Wireless Fall Detection Device
As more and more people work hard in their careers, the national economy is beginning to take off. However, the aging of society will also deepen. Without the care of young people, life for the elderly is always difficult and dangerous.
Each year, one-third to one-half of all people age 65 and older experience a fall. Falls are the leading cause of injury in older adults and the leading cause of accidental death in those 75 and older. For a person to experience a fall unnoticed can be doubly dangerous. The distinct possibility of an initial injury may further exacerbate the possible consequences if not treated in a short period of time. Statistics show that the most serious consequences are not the direct result of a fall, but rather the result of a delay in assistance and treatment. The consequences of a fall can be greatly reduced if rescuers are alerted in a timely manner.
Many seniors live alone in apartments or smaller homes after their children have grown up and left home. After a fall, it is not uncommon for the elderly to be unable to get up on their own or summon help. Therefore, there is a need for an automatic fall detection system that can summon help even if the patient loses consciousness or is unable to get up after a fall.
- Grove - 3-Axis Digital Accelerometer (LIS3DHTR)
- Wio RP2040 mini Dev Board to complete this project.
Grove - 3-Axis Digital Accelerometer (LIS3DHTR) can be used as a sensor to detect falls, and Wio RP2040 mini Dev Board can be used to process data and send distress information wirelessly. In addition, you need a computer and WiFi.
1. Install Thonny
Easy to get started. Thonny comes with Python 3.7 built-in, so just one simple installer is needed and you're ready to learn to program. First, click Thonny.org to enter the download page. In the upper right corner of the page, select the Thonny installation package according to your operating system to download. Double-click the installation package you downloaded to open it, and install it according to the steps.
Now that you have Thonny installed, open the application. You should see the main interface of Thonny:
The main interface of Thonny is very simple, divided into the following four parts:
Toolbar: basic common tools, such as new, open, save, run the current script, stop, etc.
Code editor: Thonny's core area, where we will write Python/MicroPython code.
Shell: We can run commands here, and the results of the commands will be displayed in the Shell immediately. We also can see outputs of our code in the Shell window.
Interpreter: Here you can select the type of interpreter to compile the program. Click Python 3.7.9, find MicroPython (Raspberry pi Pico) in the pop-up menu, and click OK to switch the interpreter to Pico interpreter. You can also click "Tools>>>Options>>>Interpreter" to select.
2.Connect Wio RP2040 mini Dev Board
Use the data cable to connect the development board to the computer, and then click the "Restart backend" button on the toolbar. If Wio RP2040 is successfully connected to the computer, you will see the MicroPython version information and device name in the Shell.
In order to use 3-Axis Digital Accelerometer, we need to import the library file of the sensor into the memory of Wio RP2040. This is done as follows: Copy the following code, paste it into a new thorny editor window, then save it to the development board and rename it to "ACC_ Adxl345.py "
from machine import I2C
ADXL345_DEVICE = (0x53)
""" ------- Register names ------- """
ADXL345_BW_1600 =0xF # 1111
ADXL345_BW_800 =0xE # 1110
ADXL345_BW_400 =0xD # 1101
ADXL345_BW_200 =0xC # 1100
ADXL345_BW_100 =0xB # 1011
ADXL345_BW_50 =0xA # 1010
ADXL345_BW_25 =0x9 # 1001
ADXL345_BW_12 =0x8 # 1000
ADXL345_BW_6 =0x7 # 0111
ADXL345_BW_3 =0x6 # 0110
"""Interrupt bit position"""
ADXL345_OK =1 # no error
ADXL345_ERROR =0 # indicates error is predent
ADXL345_NO_ERROR =0 # initial state
ADXL345_READ_ERROR =1 # problem reading accel
ADXL345_BAD_ARG =2 # bad method argument
def __init__(self, i2c, addr=ADXL345_DEVICE, drdy=None):
self.i2c_device = i2c
#self.rgbMatrixData = [0xFF]*64
def read(self, reg_base, reg, buf):
def write(self, buf=None):
if buf is not None:
# i2c_device.writeto(0x58, bytearray([3,100,100,16,39]))
def writeTo(self,address, val):
dta_send = bytearray([address, val])
def readFrom(self, address, num):
data_0 = address & 0xff
dta_send = bytearray([data_0])
def setRegisterBit(self, regAdress, bitPos, state):
for _b in bytes:
value = int(_b)
value |= (1 << bitPos)
value &= ~(1 << bitPos)
#Turning on the ADXL345
#look of activity movement on this axes - 1 == on; 0 == off
self.setRegisterBit(ADXL345_ACT_INACT_CTL, 6, 1)
self.setRegisterBit(ADXL345_ACT_INACT_CTL, 5, 1)
self.setRegisterBit(ADXL345_ACT_INACT_CTL, 4, 1)
#look of inactivity movement on this axes - 1 == on; 0 == off
self.setRegisterBit(ADXL345_ACT_INACT_CTL, 2, 1)
self.setRegisterBit(ADXL345_ACT_INACT_CTL, 1, 1)
self.setRegisterBit(ADXL345_ACT_INACT_CTL, 0, 1)
self.setRegisterBit(ADXL345_TAP_AXES, 2, 0)
self.setRegisterBit(ADXL345_TAP_AXES, 1, 0)
self.setRegisterBit(ADXL345_TAP_AXES, 0, 0)
#set values for what is a tap, and what is a double tap (0-255)
#setTapThreshold(50); # 62.5mg per increment
#setDoubleTapWindow(200); # 1.25ms per increment
#set values for what is considered freefall (0-255)
#setting all interrupts to take place on int pin 1
#I had issues with int pin 2, was unable to reset it
self.setRegisterBit(ADXL345_INT_MAP, ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN)
self.setRegisterBit(ADXL345_INT_MAP, ADXL345_INT_DOUBLE_TAP_BIT, ADXL345_INT1_PIN)
self.setRegisterBit(ADXL345_INT_MAP, ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN)
self.setRegisterBit(ADXL345_INT_MAP, ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN)
self.setRegisterBit(ADXL345_INT_MAP, ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN)
#register interrupt actions - 1 == on; 0 == off
self.setRegisterBit(ADXL345_INT_ENABLE, ADXL345_INT_SINGLE_TAP_BIT, 1)
self.setRegisterBit(ADXL345_INT_ENABLE, ADXL345_INT_DOUBLE_TAP_BIT, 1)
self.setRegisterBit(ADXL345_INT_ENABLE, ADXL345_INT_FREE_FALL_BIT, 1)
self.setRegisterBit(ADXL345_INT_ENABLE, ADXL345_INT_ACTIVITY_BIT, 1)
self.setRegisterBit(ADXL345_INT_ENABLE, ADXL345_INT_INACTIVITY_BIT, 1)
ADXL345_TO_READ = (6)
_buff = self.readFrom(ADXL345_DATAX0, ADXL345_TO_READ) #read the acceleration data from the ADXL345
if _buff <= 0:
if _buff <= 0:
if _buff <= 0:
#x = int(((_buff) << 8) | _buff)
#y = int(((_buff) << 8) | _buff)
#z = int(((_buff) << 8) | _buff)
#print("%d, %d, %d\r\n", x, y, z)
__Gains = [0.00376390, 0.00376009, 0.00389265]
ax = xyz * __Gains
ay = xyz * __Gains
az = xyz * __Gains
if(xyz == 0):
if(xyz == 1):
if(xyz == 2):
acceleration = AccelerationAdxl345()
Then create a new program window to write the following code.
from Acc_Adxl345 import AccelerationAdxl345
from machine import Pin,I2C
from time import sleep
i2c = I2C(0,sda = Pin(4),scl= Pin(5))
ax = AccelerationAdxl345(i2c)
N1 = network.WLAN_SPI(network.STA_IF)
print('network information:', N1.ifconfig())
led = Pin(13, Pin.OUT)
button = Pin(12,Pin.IN,Pin.PULL_UP)
SERVER = 'mqtt.p2hp.com'
CLIENT_ID = 'Wio_RP2040'
TOPIC = 'Security_status'
cl = mqtt.MQTTClient(CLIENT_ID, SERVER, mqtt_port = 1883)
val_last = 1
a = ax.acc_adxl345_read_acc()
b = ax.acc_adxl345_read_acc()
for i in range(0,3):
a = a[i] * a[i]
b = b[i] * b[i]
if a - b > 0.4 or b - a > 0.4:
Note that on line 12 of the program, change your correct WiFi name and password.
4.Setting up MQTT client
MQTT is a Client Server publish/subscribe messaging transport protocol. The client can work as a publisher or subscriber or both.
The publisher can create a topic with messages attached to the topic. For example, I can create a new topic "Today's Weather" and the message content is "25 degrees Celsius", and then sent the message to the Server. After receiving the topic message, the publisher distributes the information to any clients that have subscribed to that topic. That is, the subscriber will receive the message of "25 degrees Celsius" only if it subscribes to the topic "Today's Weather". If the subscriber does not subscribe to the topic of "Today's Weather", no matter what message the publisher sends, the subscriber will not receive the message.
Download the MQTTX server software and install it on the computer, and then configure the MQTT server.
We will use the free server of "mqtt.p2hp.com" in this project. Online server
- Address: mqtt.p2hp.com
- Ports: 1883 (TCP), 8083 (WebSocket)
- Type: EMQ
- MQTT V3.1.1/V5.0 compatible
Enter the MQTTX software to create a new connection, fill in the name, server, port, subject, and then click "Connect" to connect to the server.
After the connection is successful, there will be a pop-up in the upper right corner of the software.
Then set the topic and message below.
When data is received, the number of messages is displayed at the top. If you don't see the message, click on the subscription topic.
Here, the deployment of the MQTT client is completed. Let's go back to the Thorny editor to run the code, and then drop the 3-axis digital accelerator from a high place to observe whether the mqtt client has received the message.
Installation and testing
If you get the message successfully, congratulations you have done most of the work. Next, you just need to connect the battery to the development board and fix the device on a 5cm * 5cm cardboard.
Finally, put it into a cloth pocket. This simple fall detection device is complete! So far, this project is just a simple experimental prototype. There may be some mistouch in practical application. You can also give me feedback and we will optimize this project together.
Tech Support & Product Discussion
if you have any technical issue. submit the issue into our forum. Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.