In this project, a one-dimensional lidar device has been used for human detection in the privacy zone as well as a small servo for plane scanning, which can determine whether someone is in the area according to the change of distance. The device can even determine whether he's fallen or fainted through further analysis. (No camera is being used in this project for personal privacy concerned)
1. Overview of the designWe often see on the TV that senior citizens living alone fall and get fainted but nobody knows. What's worse, if they're in privacy areas such as bathrooms or bedrooms, it is not convenient for someone like the nanny who's not a family member to check it out. Nowadays, surveillance cameras are widely used for fall/faint recognition, which is not an appropriate solution in this project for personal privacy concerned.
There is a solution using an intrusion detection system in the industrial and military field which detect intrusion in dangerous places such as laser processing, toxic gas, and robotic arm area through radar, laser fences, vibration sensors, and other equipment. This project aims to use such technology for human detection in privacy areas.
Industrial sensors are extremely expensive therefore not suitable in this project designed for households. In this case, a small and cheap distance sensor installed on a servo implements large-angle detection. Seen in the photo below:
One of the characteristics of this project is that it can be applied to private areas. Take the layout of a toilet as an example. Usually, it's not as complicated as what we can see in pictures below:
It is not difficult to find from the picture that if the equipment is placed under or on the ground the hand-washing table, almost the entire toilet can be monitored. Simultaneously, sockets are often installed near the sink which provides power supply for hairdryers, electric toothbrushes, and razors and they can be used by the detector, too.
The flowchart is shown below:
- Just after initialized, the entire room needs to be scanned once. Before that, the buzzer will play music to prompt the user to exit the scanning area.
- After first scanning, information of the room will be saved so that each time scanning the room, the system can compare the result with original information.
- Once the system finds that the distance measurement results at multiple angles are different from the original ones after scanning, the information will be recorded as it shows someone has entered the area.
- If there's a huge difference contrasted with previous information, it means the person is in motion (e.g. he's not fallen or fainted). When there is a person, but no change of movement has been detected within 3 minutes, it will alarm.
- The alarm system consists of flashing LED and a buzzer.
2.1 Grove TF mini Lidar
Laser Radar, or Lidar, is a device using the TOF (Time of flight) to measure the distance between the sensor and the object. As shown below, the device emits a laser beam and receives it after irradiating the object and reflected back. Since the speed of light is known, the distance d can be obtained by (time tspeed of light c) / 2 as long as the time t* from laser emission to reception is measured.
Compared with other distance sensors such as ultrasonic distance sensors, infrared distance sensors, the advantages of lidar as a distance sensor are very obvious. Take the Grove TF Mini LiDAR sensor used in this project as an example. The measurement range is 0.3-12 meters, and the scattering angle is 2.3 degrees. The accuracy is 1-2%, and the results are directly calculated internally at a measuring speed of 100 times per second. I2C communication is needed to get the data. These parameters are incomparable to common infrared distance sensors and ultrasonic waves.
Lidars are also used on robots and some driverless cars to obtain 3D images of the surrounding environment. These lidars often use different rotations to measure the distance of all objects around the unmanned vehicle or robot to obtain a data set called a point cloud and use this data set to calculate the surrounding environment. These lidars have higher performance and price, but they all share the same way to work.
2.2 Grove Beginner kit for Arduino
The development of this project is not difficult with the Grove Beginner kit for Arduino and its grove modules on board. This developing board cleverly combines Arduino UNO、Grove shield、Grove sensors/actuator modules to reduce the size of hardware. It's a perfect choice for both beginners and veterans with such a low price and sufficient resources. The developing board, LED, and the buzzer is used in the project.
3. Hardware- Grove TF mini lidar × 1
- Seeeduino Lotus × 1
- Grove Servo × 1
- Grove Buzzer × 1
- Grove Beginner kit for Arduino × 1
Other hardware: 3D-Printed connector for servo × 1; 3D-Printed bottom plate × 1; 3D-Printed shell × 1; 3D-Printed hat × 1; USB charging plug × 1; USB cable × 1; Module cables × several - Transparent empty bottle without wrinkle × 1; M25 screws × 4 (to install LED and buzzer modules); M210 screws × 2 (to install servo and lidar); M35 screws × 3 (for the motherboard);M310 screws × 4 (for the shell); Hot melt glue;
4. Programming and Assembling4.1 Servo testing
Find out the centerline. Program to make the servo turn to 90 degrees with the rocker arm plugged in.
//Connect the servo to the D7 port of the board.
//Servo will turn to central position if successful.
#include <Servo.h>
Servo myservo;// create servo object to control a servo
void setup() {
myservo.attach(7);
// attaches the servo on pin 7 to the servo object
}
void loop() {
// sets the servo position according to the scaled
// waits for the servo to get there
myservo.write(90);
}
```
Check out if servo works fine.
```
//To make servo swing. We choose a rotation angle range from 10 to 170 because malfunction may occur at 0 or 180 on some servos.
//In fact we never need to reach the degree of 0 or 180 in this project.
//Connect servo to D7 port of the board.
//Servo begins to swing if successful.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(7); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 10; pos <= 170; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 170; pos >= 10; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}4.2 LED testing
//To test LED.
//Connect LED module to D3 port of the board.
//LED begins to blink if successful.
void setup() {
// initialize digital pin 13 as an output.
pinMode(3, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(3, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}4.3 Buzzer (alarm) testing
//Connect the buzzer to D6 port of the board.
//Buzzer begins to alarm if successful.
void setup()
{
pinMode(6,OUTPUT);
}
void loop()
{
for(int i=300;i<=800;i++) //To make the frequency increased from 300Hz to 800Hz gradually
{
tone(6,i); //Output from D4
delay(2); //Delay for 2 ms
}
for(int i=800;i>=203;i--)
{
tone(6,i);
delay(2);
}
}4.4 Grove TF mini Lidar testing
//Download the library from Seeed Website
//Address: https://wiki.seeedstudio.com/Grove-TF_Mini_LiDAR/
//After that, we need to install the library. Move the file to the folder named libraries in your Arduino installation folder. In the toolbar of Arduino IDE: click Sketch -> Include Library -> Add.ZIP Library and select the library you downloaded before.
//In the toolbar, click File -> Examples and you will find an example named Seeed_Arduino_TFlidar. Choose getdistance and you will get the code.
//Connect TF lidar to D2 port.
#include "TFLidar.h"
#define USETFMINI
// #define USETFLUNA
#define SERIAL Serial
#if defined(SEEED_XIAO_M0)
#define uart Serial1
#elif defined(SEEED_WIO_TERMINAL)
#define uart Serial1
#else
SoftwareSerial uart(2, 3);
#endif
#ifdef USETFLUNA
TFLuna SeeedTFLuna;
TFLidar SeeedTFLidar(&SeeedTFLuna);
#endif
#ifdef USETFMINI
TFMini SeeedTFMini;
TFLidar SeeedTFLidar(&SeeedTFMini);
#endif
void setup() {
// put your setup code here, to run once:
SERIAL.begin(9600);
while(!Serial);
SeeedTFLidar.begin(&uart,115200);
}
void loop() {
while(!SeeedTFLidar.get_frame_data()){
delay(1);
}
// put your main code here, to run repeatedly:
SERIAL.print("dist = ");
SERIAL.print(SeeedTFLidar.get_distance()); //output measure distance value of LiDAR
SERIAL.print('\t');
SERIAL.print("strength = ");
SERIAL.print(SeeedTFLidar.get_strength()); //output signal strength value
#ifdef USETFLUNA
SERIAL.print("\t Chip Temprature = ");
SERIAL.print(SeeedTFLidar.get_chip_temperature());
SERIAL.print(" celcius degree"); //output chip temperature of Lidar
#endif
SERIAL.println(" ");
// delay(1000);
}You will information in Serial Monitor if successful. The "*dis*t" means distance in cm and " *strength* " means signal strength which can be influenced by angle, color, and transparency of objects.
4.5 3D model design and production
The software is *SolidWorks*. Arduino model comes from the GrabCAD website while the other files are self-made. We use a common FDM printer so the model is designed with large tolerances.
4.6 Assembling
4.7 Program and annotation
#include "TFLidar.h" //Lidar library of Seeed
#include <Servo.h> //Library of servo
//This is from libraries of Seeed
#define USETFMINI
// #define USETFLUNA
#define SERIAL Serial
#if defined(SEEED_XIAO_M0)
#define uart Serial1
#elif defined(SEEED_WIO_TERMINAL)
#define uart Serial1
#else
SoftwareSerial uart(2, 3);
#endif
#ifdef USETFLUNA
TFLuna SeeedTFLuna;
TFLidar SeeedTFLidar(&SeeedTFLuna);
#endif
#ifdef USETFMINI
TFMini SeeedTFMini;
TFLidar SeeedTFLidar(&SeeedTFMini);
#endif
//End of what we get from Seeed
int areaData[160]; //Environment information to determine if someone or object is there
int objectData[160]; //To record data when area is occupied.
bool objectFound =0; //Flag for identification.
int object =0; //Quantities of angles with intrusion conditions.
int objectThread =5; //Once distance changes are detected on 5 angles or more, intrusion occurs.
int movement =0; //Quantities of angles on which movement is detected.
int movementThread =5; //Once changes are detected on 5 angles or more, it means nobody falls or is fainted.
int alarmThread =180;//Once no movement has been detected for more than 180s, system will alarm.
long lastTime =0;
Servo myservo;
void setup() {
//Alarm port, servo port, serial and soft serial ports.
alarmSetup();
myservo.attach(9);
SERIAL.begin(9600);
while(!Serial);
SeeedTFLidar.begin(&uart,115200);
//To scan the area.
scanStartSound(); //To let user know scanning is about to start.
myservo.write(10);//Turn the servo to initial position.
delay(5000);
scanStartSound(); //To let user know scanning is about to start.
for(int angle =10; angle<170; angle ++){ //To scan from 10 to 170 degrees.
myservo.write(angle);//Servo rotation
while(!SeeedTFLidar.get_frame_data()){
delay(1);
}
areaData[angle-10]= SeeedTFLidar.get_distance(); //To save the data.
}
scanFinishSound();//To let user know scanning has ended.
//To turn the servo to 10 degrees.
for(int angle =170; angle>10; angle --){
myservo.write(angle);
}
}
void loop() {
//To scan once.
for(int angle =10; angle<170; angle ++){ //To scan from 10 to 170 degrees.
myservo.write(angle);//Servo rotation
while(!SeeedTFLidar.get_frame_data()){//To wait for the data
delay(1);
}
int distance = SeeedTFLidar.get_distance(); //To save distance information
SERIAL.print(angle); //To print angle and distance in serial monitor for debugging
SERIAL.print(",");
SERIAL.println(distance);
if(abs(distance - areaData[angle-10])>5){ //To compare with the data saved when the system booted. If distance changes for more than 5 cm on one angle, it means there're objects on this angle.
object ++;
}
delay(20);
}
//To determine whether it exceeds threshold
if(object> objectThread){
objectFound =1; //If objects are detected on several angles, it means intrusion occurs.
SERIAL.println("found object");
}
else {
objectFound =0;
SERIAL.println("NOT found object");
}
object =0;
//To turn the servo to 10 degrees.
for(int angle =170; angle>10; angle --){
myservo.write(angle);
}
//Movement detectation
if(objectFound ==1){
for(int angle =10; angle<170; angle ++){ //To scan from 10 to 170 degrees
myservo.write(angle);//To make the servo rotate
while(!SeeedTFLidar.get_frame_data()){//To wait for the data
delay(1);
}
int distance = SeeedTFLidar.get_distance(); //To save the distance information
SERIAL.print(angle); //To print angle and distance in serial monitor for debugging
SERIAL.print(",");
SERIAL.println(distance);
if(abs(distance - objectData[angle-10])>5){ //To compare with the data saved when system booted. If distance changed for more than 5 cm, it means there're objects on this angle.
movement ++;
objectData[angle-10] = distance;
}
delay(20);
}
if(movement > movementThread ){
lastTime = millis();
}
movement =0;
//To determine if someone has not moved for a long time.
if((millis()-lastTime)> alarmThread * 1000){
while(1)alarm();
}
}
} //*********************loop function end here
void alarmSetup(){
pinMode(6,OUTPUT);
pinMode(4,OUTPUT);
}
void alarm(){
for(int i=300;i<=800;i+=2) //To increase frequency from 300Hz to 800Hz gradually
{
tone(6,i); //Output on port 4.
delay(2); //Delay for 2 ms.
}
digitalWrite(4, LOW);
for(int i=800;i>=203;i-=2)
{
tone(6,i);
delay(2);
}
digitalWrite(4, HIGH);
}
void scanStartSound(){
digitalWrite(4, HIGH);
tone(6, 262, 250);delay(250);
tone(6, 294, 250);delay(250);
tone(6, 330, 250);delay(250);
}
void scanFinishSound(){
digitalWrite(4, LOW);
tone(6, 262, 250);delay(250);
tone(6, 294, 250);delay(250);
tone(6, 330, 250);delay(250);
tone(6, 349, 250);delay(250);
tone(6, 392, 250);delay(250);
}5. ConclusionAs a certified member of CHAI HUO and thanks to Project Cooperation Plan in community, no cost has been spent on electronic components except 5 yuan for buying mineral water to make a waterproof cover.
Scanning resolution is not far from common lidars that cost much more due to the high performance of the sensor. The scanning distance of the sensor used in this project is up to 12 meters and it has advantages in terms of some parameters. The disadvantage is that the scanning cycle time is long, which may cause movement not recorded when someone moves fast. However, that's not a problem since this project is designed for senior citizens.
We do not put lots of effort into appearance design due to tight production time. We have only made a simple shell for components. For someone who wants to make a project just like ours, we highly recommend optimizing the appearance and algorithm for better use in all kinds of bathrooms.
BTW, all models and programming files are open-source and all available on GitHub.












Comments