You are on page 1of 24

Implementation of fall detection system

I. I-Introduction

This last chapter is devoted to the description of the hardware and software environment used to
set up the IoT infrastructure of our solution, as well as in the development part. It also includes
screenshots of the interfaces to describe the implementation of both parts.

II. II- Working environment


III. Hardware environment
To carry out the IoT part, we use the following list of materials:

a- LoRa Shield v1.4 :

The LoRa Shield v1.4 is a powerful add-on for Arduino boards, empowering you to unlock
the potential of LoRa technology. This revolutionary wireless communication protocol boasts
incredible long-range, low-power capabilities, making it ideal for diverse applications in
remote areas or harsh environments.
Feature :
 LoRaWAN and private LoRa support: The shield can be used with both LoRaWAN
and private LoRa networks.
 SX1278 LoRa chip: The shield uses the SX1278 LoRa chip, which is a high
performance LoRa transceiver.
 Arduino shield compatibility: The shield is compatible with all Arduino boards
that have an SPI interface.

b- Gateway:
The Dragino Gateway LoRa is a gateway device that allows LoRa devices to be connected
to a Lora WAN network. The Dragino Gateway LoRa supports ISM (industrial, scientific and
medical) band frequencies 433 MHz, 868 MHz and 915 MHz, and uses the Lora WAN 1.0.2
protocol for communication with LoRa devices.

Features :
• Long-range communication: The LG O1 P can communicate with LoRa devices over
a range of up to 15 kilometers (9 miles).
• Low power: The LG O1 P is very power-efficient, making it ideal for battery-powered
applications.
• Reliable performance: The LG O1 P is designed to be reliable and can withstand
harsh environmental conditions.
c- MPU6050 accelerometer sensor:
The MPU-6050 is a module with a 3-axis accelerometer and a 3-axis gyroscope. The
accelerometer measures acceleration (rate of change of the object’s velocity). It senses static
forces like gravity (9.8m/s2) or dynamic forces like vibrations or movement. The MPU-6050
measures acceleration over the X, Y, and Z-axis. Ideally, in a static object, the acceleration
over the Z-axis is equal to the gravitational force, and it should be zero on the X and Y-axis.

d- Arduino uno microcontroller :


The Arduino Uno is a versatile microcontroller development board that serves as an excellent
entry point for beginners and hobbyists in the world of electronics and programming. Powered by the
ATmega328P microcontroller, it features a user-friendly USB interface for seamless connection to a
computer, simplifying both programming and power supply.

Features :
1- Software
environment
•Versatility: The Arduino Uno is compatible with a wide range of sensors, actuators,
and shields, making it suitable for a variety of projects.

•Ease of use: The Arduino IDE (Integrated Development Environment) is a user-


friendly software that makes it easy to write code for the Arduino Uno.

•Community: There is a large and active Arduino community that can provide support
and resources for beginners and experienced users alike

e- Lora WAN antenna: suitable for EU868 and US915 frequencies

f- USB cable: the USB cable for connection to a computer

We use a variety of software to carry out the different IoT part tasks:

ARDUINO IDE: The Arduino IDE (Integrated Development Environment) is a


software application used for programming and developing code for Arduino
microcontroller boards. It provides a user-friendly interface that simplifies the process of writing,
compiling, and uploading code to Arduino boards.

Embedded C++: is a programming language commonly used for embedded


systems, such as microcontrollers, bare metal processors, and real-time systems. It
offers a combination of low overhead, low-level functionality, and precise control of hardware
resources, making it very suitable for real-time and low-power applications.

The thing network : he Thing Network provides community infrastructure


for IoT connectivity, allowing users to deploy and manage their own gateways
and devices. It operates under a shared infrastructure model, where users provide gateways and share
network coverage, creating a collaborative ecosystem. Using The Thing Network, developers and
businesses can connect a wide range of IoT devices, such as sensors, actuators and trackers, to the
internet and collect data from these devices.
1- Making an
2- III- Creation
Algorithm and development of the IoT solution
3- The Fall Detector Circuit
The circuit is built around an Arduino UNO and an MPU6050 accelerometer and gyroscope
breakout module. For collecting data, we rely on the MPU6050 module to give analog input to the
Arduino UNO. The MPU6050 module provides six values as output, three values of an accelerometer,
and three values of a gyroscope.
The interfacing is quite simple. We are using A4 and A5 pins of the Arduino UNO for data
reception. To see the other pins connection check the annexe N° 1 .

Check the annexe N°2 to see the real-life implementation


We will go with the threshold-based detection system and check whether a parameter is above a
certain threshold value within a time interval. In a fall situation, there is a large change in acceleration
within a split second and then after the fall, the person lies still for some time, showing no change in
orientation. Knowing these details allows us to create our algorithm.
First, we will collect data from the accelerometer and then calculate the acceleration magnitude.
Acceleration magnitude tells us about how quickly velocity changes while acceleration tells us the rate of change
in velocity, so we need acceleration magnitude here.

This equation is of the magnitude of acceleration and the three values ax, ay, and az are the
acceleration of X-, Y-, and Z-axis respectively as per data collected.

After calculating the acceleration magnitude, we need to know if its value breaks the lower
threshold. The lower threshold is the minimum threshold in the range decided by us and the value
2- Source
Code
gradually increases up to the high threshold. Then we need to check that it breaks the high threshold in
some milliseconds — for testing let's say 170 ms.
If all of these are detected as true conditions, then we need to check whether there is a change in
orientation within 170 ms and usually, it's true if the above conditions are true. After that, we check to
see if orientation remains the same for some time.
If yes, then there was a fall. There is a loop, meaning that if a condition is false at any stage, the
process goes back to start and re-executes.

a- Fall detection
The code in the annexe N° 3 is based on the algorithm stated above and follows seven steps:

1- Collect data from the module and show it as an output


2- Calculate magnitude of acceleration.
3- Check if the value of magnitude breaks the lower threshold. If false, return to Step 1.
4- Check if the value of magnitude breaks the lower threshold . if true show as an output “fall
detected “
5- return to Step 1

Here the values of X and Y and Z based on the movement of the sensor. Those values are being
recorded by using the serial monitor in Arduino software.

Here The above graph shows the values of X and Y and Z based on the movement of

the sensor. These values are taken from Arduino with the Mpu6050 sensors when the device is
attached to the human body.
The picks of the yellow line show the fall detection:
b- Transmit Data
The dragino lora shield model support ABP method for better simplicity , speed and security
and this is how it works :

Arduino IDE “MCCI loraWAN LMIC library “ provide a code for lora antenna
transmission (annexe N°4)
This is the configuration that we need to assure the communication between the antenna
and the thing network :

 NWSKEY and APPKEY must be in bid endian


 DEVADDR must be in HEX
We get those keys from the thing network platform after creation an application and
registering a device
3- The internet of thing platform
configuration

First thing to do is to create an account on the internet of thing iot cloud platform then create
an application and register the devices “lora shield” then register the lora gateway
This is the interface when you sign up :

a- Create an application :
we need to enter the application name and ID
b- Registering a device:
The device node, composed by an Arduino Uno + Dragino LoRa Shield, once it is
correctly registered in TTN collects the LDR data and send them through LoRa.

To register the device into TTN, we have to browse the console, click on Application
and, if it is necessary
to register a device we need to enter : end device ID + frequency plan of the lora shield +
Lora wan version

“Device ID” field with a unique name for our device and ask for random generation of both
“Device EUI” and “AppKey”. And enable “ABP” as “Activation Mode” asking for random generation
of the “App Session Key” and the “Network Session Key”.

c- Lora Gateway configuration

Before the registration of the gateway on the internet of thing platform we need to make some
configuration for the gateway :
To accomplish both the connections we firstly need to link the Dragino gateway to our PC
through another Ethernet cable using the LAN port. This, as the port name suggests, creates a LAN
among the two items and gives us the opportunity to access the configuration page just typing in the
browser this IP: “10.130.1.1”.

*Configure the internet access

*Lora gateway settings


The gateway ID we used is the MAC address of the Dragino, which is indicated at the bottom of the
device, plus a suffix; the ID is a unique 8 Byte Hex. For example: as below, the mac for the device is
a8:40:41:18:ff:1c, a user then can add ffff suffix and get the gateway ID: a8404118ff1cffff.

*radio settings

Just some settings are missing now: we need to browse in LG01 Sensor → Lora WAN page to input
the correct Lora Radio settings used to receive data from the LoRa nodes.

*select IOT server

and then enabling to use Lora WAN server


d- Lora gateway registration on TTN

After the gateway configuration we move to The Thing Network registration

On the manual registration form we fill in the Frequency Plan and the Gateway ID t he other
fields are optional.

We set the location .


We create the API key to able the gateway to connect to The Things Stack
After all this all configuration the gateway still disconnected

After long research we discovered that is a common problem with the other users of
the thing network

So we end the process of the project here because we need the gateway to connect to
the thing network platform so we can process the data that was send by the lora shield , that’s
why we can’t complete the sending ‘SMS alert’ part

IV. Conclusion

In this study, a wireless sensor system is implemented to measure the acceleration and angular
velocity at center chest on the body for four different types of falls. The collected data is used to
evaluate the performance of the fall detection algorithm
Unfortunately, we were not able to complete the project due to technical problems and lake of
time.
In conclusion, a fall detection system has been validated to show high sensitivity and specificity
results, using the combination of accelerometer and gyroscope

Webography
*https://www.thethingsnetwork.org/docs/lorawan/

*https://medium.com/@marcozecchini.2594/connect-dragino-lg01-p-gateway-and-a-dragino-
lora-shield-arduino-uno-to-the-things-network-301d27184e05

*https://github.com/dragino/Lora

*https://sensorkit.arduino.cc/

* https://ieeexplore.ieee.org/

* https://maker.pro/arduino/tutorial/how-to-build-a-fall-detector-with-arduino

* https://wiki1.dragino.com/index.php/Lora_Shield

Bibliography
Fall_Detection_System_Using_Arduino_MPU.pdf

Alert_System_for_Fall_Detection.pdf

Fall_Detection_System_Using_Combination.pdf

Fall_Detection_Devices_and_Their_Use_Wit.pdf

e_Health_Monitoring_System_for_Senior_Ci%20(1).pdf

Operationalizing_a_wireless_wearable_fal.pdf

LG01N_LoRa_Gateway_User_Manual_v1.1.pdf

Livre-LoRa-LoRaWAN-et-lInternet-des-Objets.pdf
Annexe

Annexe N°1 : pins connection

Annexe N°2 : real-life connection


Annexe N°3 : fall detection code

#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>

MPU6050 mpu;
const float accelerationThreshold = 170.0;
int16_t ax, ay, az;
int16_t gx, gy, gz;

struct MyData {
byte X;
byte Y;
byte Z;
};

MyData data;

void setup()
{
Serial.begin(115200);
Wire.begin();
mpu.initialize();
Serial.println("Initializing...");

//pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
data.X = map(ax, -17000, 17000, 0, 255 ); // X axis data
data.Y = map(ay, -17000, 17000, 0, 255);
data.Z = map(az, -17000, 17000, 0, 255); // Y axis data
delay(1000);
Serial.print("Axis X = ");
Serial.print(data.X);
Serial.print(" ");
Serial.print("Axis Y = ");
Serial.print(data.Y);
Serial.print(" ");
Serial.print("Axis Z = ");
Serial.println(data.Z);

// Calculate total acceleration magnitude


float accelerationMagnitude = sqrt(data.X * data.X + data.Y * data.Y +
data.Z * data.Z);

Serial.print("Acceleration Magnitude: ");


Serial.println(accelerationMagnitude);

// Check if acceleration magnitude exceeds threshold


if (accelerationMagnitude > accelerationThreshold) {
Serial.println("Fall detected!");

}
}

Annexe N°4 : lora shield ABP code

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#ifdef COMPILE_REGRESSION_TEST
# define FILLMEIN 0
#else
# warning "You must replace the values marked FILLMEIN with real values from
the TTN control panel!"
# define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN)
#endif

// LoRaWAN NwkSKey, network session key


// This should be in big-endian (aka msb).
static const PROGMEM u1_t NWKSKEY[16] = { 0xC5, 0x1B, 0xA4, 0x53, 0xCF, 0xD9,
0xCF, 0xED, 0x38, 0x75, 0x68, 0xEC, 0xA3, 0xBF, 0x88, 0x4A };

// LoRaWAN AppSKey, application session key


// This should also be in big-endian (aka msb).
static const u1_t PROGMEM APPSKEY[16] = { 0x9A, 0xF6, 0xC4, 0x22, 0xC8, 0x7B,
0x96, 0x44, 0xBA, 0x87, 0x6B, 0x59, 0xC4, 0x23, 0x53, 0xA9 };

// LoRaWAN end-device address (DevAddr)

// The library converts the address to network byte order as needed, so this
should be in big-endian (aka msb) too.
static const u4_t DEVADDR = 0x260BDE05 ; // <-- Change this address for every
node!

// otherwise the linker will complain).


void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }

static uint8_t mydata[] = "Hello, world!";


static osjob_t sendjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;

// Pin mapping
// Adapted for Feather M0 per p.10 of [feather]
const lmic_pinmap lmic_pins = {
.nss = 10, // chip select on feather (rf95module) CS
.rxtx = LMIC_UNUSED_PIN,
.rst = 5, // reset pin
.dio = {2, 3, LMIC_UNUSED_PIN}, // assumes external jumpers
[feather_lora_jumper]
// DIO1 is on JP1-1: is io1 - we connect
to GPO6
// DIO1 is on JP5-3: is D2 - we connect to
GPO5
};

void onEvent (ev_t ev) {


Serial.print(os_getTime());
Serial.print(": ");
switch(ev) {
case EV_SCAN_TIMEOUT:
Serial.println(F("EV_SCAN_TIMEOUT"));
break;
case EV_BEACON_FOUND:
Serial.println(F("EV_BEACON_FOUND"));
break;
case EV_BEACON_MISSED:
Serial.println(F("EV_BEACON_MISSED"));
break;
case EV_BEACON_TRACKED:
Serial.println(F("EV_BEACON_TRACKED"));
break;
case EV_JOINING:
Serial.println(F("EV_JOINING"));
break;
case EV_JOINED:
Serial.println(F("EV_JOINED"));
break;
case EV_JOIN_FAILED:
Serial.println(F("EV_JOIN_FAILED"));
break;
case EV_REJOIN_FAILED:
Serial.println(F("EV_REJOIN_FAILED"));
break;
case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX
windows)"));
if (LMIC.txrxFlags & TXRX_ACK)
Serial.println(F("Received ack"));
if (LMIC.dataLen) {
Serial.println(F("Received "));
Serial.println(LMIC.dataLen);
Serial.println(F(" bytes of payload"));
}
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()
+sec2osticks(TX_INTERVAL), do_send);
break;
case EV_LOST_TSYNC:
Serial.println(F("EV_LOST_TSYNC"));
break;
case EV_RESET:
Serial.println(F("EV_RESET"));
break;
case EV_RXCOMPLETE:
// data received in ping slot
Serial.println(F("EV_RXCOMPLETE"));
break;
case EV_LINK_DEAD:
Serial.println(F("EV_LINK_DEAD"));
break;
case EV_LINK_ALIVE:
Serial.println(F("EV_LINK_ALIVE"));
break;

case EV_TXSTART:
Serial.println(F("EV_TXSTART"));
break;
case EV_TXCANCELED:
Serial.println(F("EV_TXCANCELED"));
break;
case EV_RXSTART:
/* do not print anything -- it wrecks timing */
break;
case EV_JOIN_TXCOMPLETE:
Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
break;
default:
Serial.print(F("Unknown event: "));
Serial.println((unsigned) ev);
break;
}
}

void do_send(osjob_t* j){


// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending"));
} else {
// Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
Serial.println(F("Packet queued"));
}

void setup() {
// pinMode(13, OUTPUT);
while (!Serial); // wait for Serial to be initialized
Serial.begin(115200);
delay(100); // per sample code on RF_95 test
Serial.println(F("Starting"));

#ifdef VCC_ENABLE
// For Pinoccio Scout boards
pinMode(VCC_ENABLE, OUTPUT);
digitalWrite(VCC_ENABLE, HIGH);
delay(1000);
#endif

// LMIC init
os_init();

LMIC_reset();

#ifdef PROGMEM

uint8_t appskey[sizeof(APPSKEY)];
uint8_t nwkskey[sizeof(NWKSKEY)];
memcpy_P(appskey, APPSKEY, sizeof(APPSKEY));
memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY));
LMIC_setSession (0x13, DEVADDR, nwkskey, appskey);
#else
// If not running an AVR with PROGMEM, just use the arrays directly
LMIC_setSession (0x13, DEVADDR, NWKSKEY, APPSKEY);
#endif

#if defined(CFG_eu868)
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7),
BAND_CENTI); // g-band
LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B),
BAND_CENTI); // g-band
LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7),
BAND_CENTI); // g-band
LMIC_setupChannel(3, 867100000, DR_RANGE_MAP(DR_SF12, DR_SF7),
BAND_CENTI); // g-band
LMIC_setupChannel(4, 867300000, DR_RANGE_MAP(DR_SF12, DR_SF7),
BAND_CENTI); // g-band
LMIC_setupChannel(5, 867500000, DR_RANGE_MAP(DR_SF12, DR_SF7),
BAND_CENTI); // g-band
LMIC_setupChannel(6, 867700000, DR_RANGE_MAP(DR_SF12, DR_SF7),
BAND_CENTI); // g-band
LMIC_setupChannel(7, 867900000, DR_RANGE_MAP(DR_SF12, DR_SF7),
BAND_CENTI); // g-band
LMIC_setupChannel(8, 868800000, DR_RANGE_MAP(DR_FSK, DR_FSK),
BAND_MILLI); // g2-band

#elif defined(CFG_us915) || defined(CFG_au915)

LMIC_selectSubBand(1);
#elif defined(CFG_as923)

#elif defined(CFG_kr920)

#elif defined(CFG_in866)

# error Region not supported


#endif

// Disable link check validation


LMIC_setLinkCheckMode(0);

// TTN uses SF9 for its RX2 window.


LMIC.dn2Dr = DR_SF9;

// Set data rate and transmit power for uplink


LMIC_setDrTxpow(DR_SF7,14);

// Start job
do_send(&sendjob);
}

void loop() {

os_runloop_once();

You might also like