<<<<Previous Blog Next Blog>>>>
Audio & Visual Cue System for Anosmia (Smell Disorder) and Smart WheelChair - Ft. Amazon's Alexa
Week 6: Aug 7 - 13
The Smart Wheelchair has the following three sections: temperature monitoring, fall & collision detection, and home appliance control. These will be covered in a four-part blog series, the last part being the integration part. This blog is about the 'Fall and Collision Detection' section of the Smart Wheelchair. For the collection of this project's blogs published so far, visit this link and for the detailed plan of the 'Smart WheelChair' visit this link.
Smart WheelChair [Part 2 of 4]
Temperature Monitoring | Fall & Collision Detection | Home Appliance Control | Integration
Introduction
The 'Fall and Collision Detection' section of the smart wheelchair will be able to identify whether a person in a wheelchair has fallen to the ground along with the with the wheelchair or not. When such an incident occurs, an SMS will be sent to a pre-configured number through IFTTT. The SMS will contain a message saying, that person needs help/attention and also detail such as the time when the incident occurred. This will not be able to identify whether the person alone has fallen down to the ground. I will take this up as a stretch goal and try to implement after I complete the previously committed things in this project.
Also, this will be able to detect the collision and alert the person in the wheelchair beforehand. There will be two ultrasonic sensors in the back and front of the wheelchair, measuring the distance at a finite time interval. If the distance obtained is very less then that implies the wheelchair is about to hit an obstacle, it will alert the person through LED signals (probably a RED LED). I will try to make Alexa alert the person in the wheelchair when that person is about to collide. This will be again another stretch goal.
List of Hardware and Software involved
Below is the list of hardware and software involved in making a 'Fall and Collision Detection' system. Click on the names in order to be directed to the site where you can buy or access the resource.
Hardware
All the hardware circuit components used for this project are available in the Sponsored kit.
- HC-SR04 Ultrasonic sensor - x2
- ADXL335Z Evaluation Board
- Arduino MKR1000 Dev Board
- Proto Shield / Breadboard & few jumper wires
Software
Circuit Connection
The Fall Detection Circuit requires the ADXL335Z Evaluation Board connected to the Arduino MKR1000 Dev Board. This will assess the position of the wheelchair and trigger IFTTT in case of a fall. The X and Y axes are used to maintain simplicity and hence the Z axis is omitted. The X and Y axes are connected to A3 and A2 respectively. The ground pin of the accelerometer to Arduino MKR1000 ground and the VSS to the VCC (3.3V) of the Arduino. After testing the accelerometer on various positions, the condition for a fall from a determined stable position is as in the if clause below. The determined stable position is assessed to be around 520 for both X and Y axes.
if ( X < 430 or X > 600 ){ XFlag = 1; } else { XFlag = 2; } if ( Y < 430 or Y > 600 ){ YFlag = 1; } else { YFlag = 2; }
The Collision Detection Circuit requires two HC-SR04 Ultrasonic sensors to detect a collision. One for the front and another for the back of the wheelchair. The trig and echo pins are connected to the digital pins. The ground pin of the ultrasonic sensor to the ground pin of the Arduino MKR1000 and the Vcc to the 5V of the Arduino.
The Green LED will help us know whether the SMS send was successful or not. If SMS is sent then it will be blinked, else it will be in OFF state. Also, it will serve the purpose of the status LED for the connection to the URL configured (IFTTT Webhooks). The Red LED will be used to alert the person in the wheelchair when there is a possible chance of collision.
Below is the 'fall and collision detection' part of the smart wheel chair's circuit connection. If needed, you can download the Arduino MKR1000 part for Frtizig from here.
IFTTT
According to Wikipedia, IFTTT is defined as below,
If This Then That, also known as IFTTT (/ɪft/),[4] is a free web-based service to create chains of simple conditional statements, called applets.
An applet is triggered by changes that occur within other web services such as Gmail, Facebook, Telegram, Instagram, or Pinterest.[5]
For example, an applet may send an e-mail message if the user tweets using a hashtag, or copy a photo on Facebook to a user's archive if someone tags a user in a photo.[6]
In simple terms, IFTTT is used when you need an event to happen if the condition is met. IF This condition is met Then execute that event. This as a whole is termed as an Applet. So an applet will comprise of two things: the event which triggers and the event which needs to be triggered. In my project, when the person along with the wheelchair encounters a fatal fall, an SMS needs to sent to a pre-configured number. So in the event of fall or collision, Arudino MKR1000 will post a request to an IFTTT Webhooks service URL (an event which triggers). This will trigger an SMS event to happen next (an event which needs to be triggered), which will send SMS saying:
'XXXX has fallen down and needs your help! Time of incident: August 14, 2018 at 09:25 AM'
For detailed steps on how to create a new applet in IFTTT, check out the below video. In this video, the applet to be created will be the one containing Webhooks and SMS services required for this part of the project.
Obtaining the Webhook URL to trigger an event from Arduino MKR1000
- Go to https://ifttt.com/services/maker_webhooks and then click Settings.
- Copy paste the URL in that page to a new tab and click enter to load that page. When the page loads you will have a link generated like this under 'Make a POST or GET web request to:' - https://maker.ifttt.com/trigger/{event}/with/key/XXXXXXXXXX-XXXXXXX-XXX where X is a secret key and {event} should be replaced with your event name.
- Use the parts of the above URL in the Arduino code in the places as shown below:
- maker.ifttt.com - char server[] = "maker.ifttt.com";
client.println("Host: maker.ifttt.com");
- /trigger/{event}/with/key/XXXXXXXXXX-XXXXXXX-XXX - client.println("GET /trigger/FallDetection/with/key/XXXXXXXXXX-XXXXXXX-XXX HTTP/1.1");
Code
The code for the 'fall and collision detection' section of the smart wheelchair is provided below. For GitHub page for the same code, Click here. I have added comments for a better understanding of the code. You will need to add the 'WiFi101' using the library manager in your Arduino IDE (Preferably the latest version, I used V1.8.5).
/* This is the code for the Fall and Collision Detection section of the Smart WheelChair deisgned for the Element14 Community's 'Design for a Cause' * design challenge, sponsored by Arduino. * * This code contains extracts from the WiFi101 WebClient example code, 'created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 by Tom Igoe' * * Author : Dixon Selvan * Date : August 14, 2018 * Project: Cue system for Anosmia and Smart WheelChair * Website: * * Hardware components Required * ---------------------------- * 1. Arduino MKR1000 board * 2. HC-SR04 Ultrasonic Sensors - x2 * 3. Accelerometer ADXL335Z Evaluation Board (any ADXL XXX should work) * 4. ProtoShield/ Breadboard and Few Jumper wires * * Connections * ----------- * Arduino MKR1000 | Ultrasonic Sensor * --------------------------------------------- * 5V | Vcc * Gnd | Gnd * D2/3 | Echo * D5/4 | Trig * * Arduino MKR1000 | ADXL335Z Evaluation Board * --------------------------------------------- * VCC(3.3V) | VSS * Gnd | Gnd * A2 | Y * A3 | X * * Arduino MKR1000 | LED (Green/ Red) * --------------------------------------------- * D1 | Positive of Green LED * D2 | Positive of Red LED * Gnd | Negative of both the LEDs * * Blog Link - https://www.element14.com/community/community/design-challenges/designforacause/blog/2018/08/03/cue-system-for-anosmia-and-smart-wheelchair-5-fall-and-collision-detection * * Design Challenge Page - * https://www.element14.com/community/community/design-challenges/designforacause/blog * * Create a new applet using IFTTT - https://ifttt.com/create */ /*Adding Required Libraries*/ #include <SPI.h> #include <WiFi101.h> #include "arduino_secrets.h" /*Please enter your sensitive data and credential in the Secret tab/arduino_secrets.h*/ char ssid[] = SECRET_SSID; // Your network SSID (name) char pass[] = SECRET_PASS; // Your network password (use for WPA, or use as key for WEP) int keyIndex = 0; // Your network key Index number (needed only for WEP) int status = WL_IDLE_STATUS; /*Find instructions to obtain the below value here - https://www.element14.com/community/community/design-challenges/designforacause/blog/2018/08/03/cue-system-for-anosmia-and-smart-wheelchair-5-fall-and-collision-detection#jive_content_id_Obtaining_the_Webhook_URL_to_trigger_an_event"*/ char server[] = "maker.ifttt.com"; /* Initialize the Ethernet client library with the IP address and port of the server that you want to connect to (port 80 is default for HTTP):*/ WiFiClient client; /*Declaring and initializing variables*/ int trigPinF = 5, trigPinR = 4; int echoPinF = 2, echoPinR = 3; int collisionLED = 1; //Red LED to Alert user in case of collision int statusLED = 0; //Green LED for status int XAxis = A3, YAxis = A2; int XValue = 0, YValue = 0; int XFlag = 0, YFlag = 0; int fallCount = 0; long duration; int distance; int measDistanceF; int measDistanceR; void setup() { /*Declaring GPIO pins connection mode I/O*/ pinMode(trigPinF, OUTPUT); pinMode(echoPinF, OUTPUT); pinMode(trigPinR, OUTPUT); pinMode(echoPinR, OUTPUT); pinMode(collisionLED, OUTPUT); pinMode(statusLED, OUTPUT); pinMode (XAxis, INPUT); pinMode (YAxis, INPUT); /*Serial initialisation for debugging*/ Serial.begin(9600); while (!Serial) { ; /*Wait for serial port to connect. Needed for native USB port only*/ } /*Check for the presence of the WiFi shield:*/ if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi shield not present"); /*Don't continue, to inidcate code is stuck here, turn on both the LEDs*/ digitalWrite(collisionLED, HIGH); digitalWrite(statusLED, HIGH); while (true); } /*Attempt to connect to WiFi network:*/ while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); digitalWrite(statusLED, HIGH); Serial.println(ssid); /*Connect to WPA/WPA2 network. Change this line if using open or WEP network:*/ status = WiFi.begin(ssid, pass); /*wait 10 seconds for connection:*/ delay(10000); } Serial.println("Connected to wifi"); printWiFiStatus(); delay(5); digitalWrite(statusLED, LOW); digitalWrite(collisionLED, LOW); } void loop() { XValue = analogRead(XAxis); YValue = analogRead (YAxis); detectFall (XValue, YValue); measDistanceF = calculateDistance(trigPinF, echoPinF); /*For Debugging purpose*/ Serial.print(measDistanceF); Serial.print('\t'); measDistanceR = calculateDistance(trigPinR, echoPinR); Serial.println(measDistanceR); if ((measDistanceF <= 10) || (measDistanceR <= 10)){ Serial.println("Collision Alert!"); digitalWrite(collisionLED, HIGH); delay(1); } else { digitalWrite(collisionLED, LOW); delay(1); } } /* User-Defined Functions: * void detectFall (int X, int Y) - To detect a fall * int calculateDistance(int trigPin, int echoPin) - To calculate distance * void printWiFiStatus() - To print WiFi Status * void sendSMS() - To send SMS */ void detectFall (int X, int Y){ /*Code to detect fall, The values below are assessed keeping the center position around the value 530 from X & Y axes*/ if ( X < 430 or X > 600 ){ XFlag = 1; } else { XFlag = 2; } if ( Y < 430 or Y > 600 ){ YFlag = 1; } else { YFlag = 2; } /* For Debugging purpose Serial.print(XFlag);Serial.print('\t'); Serial.print(YFlag);Serial.print('\t'); Serial.print(X);Serial.print('\t'); Serial.print(Y);Serial.print('\t');*/ delay(10); if (XFlag == 1 or YFlag == 1) { fallCount = fallCount + 1; Serial.print("Fall Detected! C: "); Serial.println(fallCount); delay(1000); if(fallCount >= 10){ sendSMS(); fallCount = 0; while(true); } } } int calculateDistance(int trigPin, int echoPin) { /*Code to calculate Distance from Duration*/ digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); delayMicroseconds(2); duration = pulseIn(echoPin, HIGH); distance= duration*0.034/2; return distance; } void printWiFiStatus() { /*Print the SSID of the network you're attached to:*/ Serial.print("SSID: "); Serial.println(WiFi.SSID()); /*pPrint your WiFi shield's IP address:*/ IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); /*Print the received signal strength:*/ long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); } void sendSMS(){ Serial.println("\nStarting connection to server..."); /*If you get a connection, report back via serial:*/ if (client.connect(server, 80)) { Serial.println("connected to server"); /*Make a HTTP request: Find instructions to obtain the below value here - https://www.element14.com/community/community/design-challenges/designforacause/blog/2018/08/03/cue-system-for-anosmia-and-smart-wheelchair-5-fall-and-collision-detection#jive_content_id_Obtaining_the_Webhook_URL_to_trigger_an_event"*/ client.println("GET /trigger/{YOUR_IFTTT_EVENT_NAME}/with/key/{YOUR_IFTTT_KEY} HTTP/1.1"); client.println("Host: maker.ifttt.com"); client.println("Connection: close"); client.println(); digitalWrite(statusLED, HIGH); } int reqReceived = 1; while(reqReceived){ while (client.available()) { char c = client.read(); Serial.write(c); reqReceived = 0; } /*If the server's disconnected, stop the client:*/ if (!client.connected()) { Serial.println(); Serial.println("disconnecting from server."); client.stop(); digitalWrite(statusLED, LOW); } } }
Outcome
Now that we have built our own 'Fall and Collision Detection' system, it is time to enjoy our fruits of labor. Below is the video showing a demo of the final outcome.
Related Products in the market
- Philips Lifeline Auto Alert -https://www.lifeline.philips.com/medical-alert-systems/fall-detection.html
- Bay Alarm Medical - https://www.bayalarmmedical.com/medical-alert-blog/the-truth-behind-automatic-fall-detection-systems/
- YuniDetect - https://www.indiegogo.com/projects/yunidetect-collision-detection-avoidance-system#/backers
Reference
- IFTTT -
Have you got any suggestion or comment? Let me know in the comments section below.
Progress made so far,
|||||||||||||||||||||||||||||||||||||||||||||||||||| 40%
Top Comments