The aging population of the world presents enormous financial challenges. There are not enough retirement facilities to cater the needs of the elderly and costs are high. The tendency is that elderly people prefer staying in their own homes for longer. That makes the elderly more independent and happier, but risks are higher when they fall or experience health or security problems. Sometimes that is only discovered hours or days after the incident.
With this non-invasive system daily events can be monitored and recorded and a set of rules can be applied to generate an alarm condition. This includes:
- opening and closing doors
- switching lights on or off
- using electrical appliances
- movement in various locations in the house
- temperature measurement
- panic button
- fall detection (monitor worn by elderly)
A summary of this information will be sent to the cloud. With the monitor app users with access to the service will be able to monitor various statuses and will be alerted of emergency situations. These users may include family, friends, emergency services and health services.
- one or more wifi sensor nodes to collect relevant data
- wifi network infrastructure
- data cloud storage and service infrastructure
- client app to display cloud collected data and control sensor nodes via the cloud
A number of different sensors are used to accumulate data for a rules based system, which will send alerts when events do not follow a normal pattern. These include, but are not restricted to:
- a) accelerometer - vibration (eg. fridge running), orientation or fall detection (where the device is worn by the person), objects being moved (sensor device attached to the object)
- b) light sensor - to determine whether lights are on and/or sun is shining (curtains drawn of not)
- c) temperature - to measure room temperature (too hot or too cold)
- d) magnetic switch OR motion monitor contact - to determine when a door is opened or closed (when not supposed to) OR lack thereof (which may be an abnormal condition) OR lack of motion (for a period of time in a specific time slot)
All these events are time stamped, so that rules can include time of day, time slots and time span.
A bi-color LED and buzzer is used to communicate remote messages and as local alarm when the internet is not available. Messages may include reminders like medication, time to feed the cat, time for a meal, etc.
The assumption is that a wifi router, which is connected to the internet, will be available. The wifi sensor node makes use of DHCP to obtain an IP address.
Cloud EnvironmentThe wifi sensor node currently makes use of a free subscription to the Microsoft Azure IoT Hub to store data. Setup and tools will be described in the software section.
As a proof of concept I used the Azure Device Monitor software to analyze data and to send commands to my MKR1000 sensor node via Azure IoT Hub.
I also installed the Azure IoT Suite and had a look at their example application (more under software).
In future a Windows 10 app will be used to display data (light level, temperature) and alerts (fall, door open) from Azure IoT Hub and to send signal commands to wifi sensor nodes via the hub.
Hardware SetupInitially I did my prototype on a breadboard, as shown in the first picture. The second picture shows the schematic. Towards the end I decided to do a more permanent setup for testing and I built the circuit on prototype board, as seen in the project picture. The Fritzing file is available under uploaded files.
If you are not currently running Arduino IDE version 1.6.7, download it from here
https://www.arduino.cc/en/Main/OldSoftwareReleases
and install. The MKR1000 forum will help to set up the board
http://forum.arduino.cc/index.php?topic=380369.msg2622600#msg2622600
Upgrade to MKR1000 core version 1.6.4-mkr02, which contains a crucial fix for a condition that destroys the bootloader. Install the latest Arduino Wifi101 library.
Setup the Arduino IDE for MKR1000, plug the module into a usb port and ensure that the correct serial port is selected. There are good example sketches in Wifi101 to turn the module into a webclient or webserver. Try these out to ensure that your board is working properly. Change ssid and pass to connect to your own wifi router.
Refer to the hardware schematics and component list to prepare the wifi sensor node. The pinouts are well documented in the Arduino sketch.
Initially I planned on using Windows Remote Arduino, which is a Windows 10 environment that uses firmata protocol to "take over" the Arduino. This would poll remote sensors from a Windows app. Due to the unpredictable nature of accelerometer data I decided against this method, in favor of pushing sensor data to the cloud. The obvious choice was Microsoft Azure IoT Hub.
MKR1000 Sensor Node SketchI am thrilled to be in the group of 1000 to familiarize myself with the MKR1000. Initially I worked through example sketches in the Wifi101 library. After I defined the goal of my project I made a decision on the sensors and other components I would use, preferably in stock items. I collected libraries and examples for LDR light dependent resistor, DS18B20 temperature sensor, ADXL345 accelerometer, switch, bi-color LED, buzzer and tested them individually on a breadboard. I had to quickly learn Fritzing to do the schematic and breadboard layout (see hardware setup).
I received lots of help from members on the MKR1000 forum, as well as other hobbyists (see references). At this stage I had only heard about Azure, but I decided to use it for cloud data storage anyway. The vast capabilities of the Azure cloud platform was quite confusing. Fortunately Mohan Palanisami (mohanp) did a good article on connecting to Azure IoT Hub. A "simple C" sample on azure-iot-sdks looked promising, but it was not that simple after all and I did not like the 100k+ size of my sketch. I noticed that mohanp only used around 30k, so I decided to use his sketch as basis. Initially I used the JSON structure in the connect the dots library examples, but now I am using a very neat JSON library for generating strings.
In the main loop there are basic local rules for determining an event condition (temperature changing x degrees, light level changing y lumens, accelerometer events, battery voltage falling under 3.3V). When an event occurs the data gets sent to Azure IoT Hub, where a secondary set of rules is applied on the data to decide on an alarm condition (abnormal events in specific time slots or time spans). Currently this is not implemented, but the Azure IoT Suite example shows how it can be done.
Further work needs to be done to decode combinations of accelerometer "words" (INACTIVITY, ACTIVITY, TAP, DOUBLE TAP, FALL DETECT) into real life events (like fall, object moved, vibration stopped).
With the extension of the deadline I managed to add more functionality:
- JSON generation is simplified by using JSON library calls. The JSON string is also simplified.
- Commands received from Azure IoT Hub via the Device Explorer "messages to device" tab are executed on the MKR1000. Examples are beepon/beepoff to turn the buzzer on of off. Similarly this could in future be used to turn a relay on/off to control electrical devices.
- I moved from the Arduino IDE environment to Visual Studio with Visual Micro, Azure IoT Hub and Github extensions. I posted my local library to Github from here.
If you are not already using Azure you can subscribe to a free account. Use the Azure portal to create you own IoT Hub (mine is called MKR1000hub)
https://azure.microsoft.com/en-in/documentation/articles/iot-hub-csharp-csharp-getstarted/.
To enable you to create and explore devices on Azure install Device Explorer for IoT Hub devices
Configure the Device Explorer by using the IoT Hub Connection String and Protocol Gateway Hostname from Azure portal. Go to the Management tab to create a device. Use this connection string in the MKR1000 sensor node sketch. The Data tab enables you to display the JSON messages sent to Azure. The Messages to Device tab enable you to send messages to the MKR1000 sensor node (as described in the sketch section).
An excellent example application monitors and displays temperature and humidity. That together with the ease of registering new devices and the rules engine makes it ideal for my project. I adapted my sketch to send data to the sample Azure IoT Hub, which according to Device Explorer worked. The device showed up in the IoT Device Portal, but the status stayed "pending". More people complained about getting the same results sending from Arduino, but could not get any clarity on solving the problem. I could also not find documentation on the JSON schema they use. I tried to reverse engineer it by looking at the sample data in Device Explorer, but I may still be missing something.
1. MKR1000 Azure IoT Hub Interface Using HTTP
http://mohanp.com/mkr1000-azure-iot-hub-how-to/
2. Connect the Dots libraries examples of JSON structures
https://github.com/Azure/connectthedots/tree/master/Devices/GatewayConnectedDevices/Arduino%20UNO
3. Detecting Human Falls with a 3-Axis Digital Accelerometer
http://www.analog.com/library/analogdialogue/archives/43-07/fall_detector.html
4. ADXL345 accelerometer plus Arduino - tap, double tap, fall, activity, inactivity
http://bildr.org/2011/03/adxl345-arduino/
5. Run a simple C sample on Arduino WiFi Shield 101 and MKR1000 device
https://github.com/Azure/azure-iot-sdks/blob/master/doc/get_started/arduinoide-arduino-wifi101-c.md
6. IoT device management using Azure IoT Suite and Azure IoT Hub
https://github.com/Azure/azure-content/blob/master/articles/iot-hub/iot-hub-device-management.md
7. Arduino JSON library
Comments