Internet of Things Application with MATLAB – Fall Detection

We are going to create an Android app which detects and sends to you a warning that your mobile/device has fallen.

We require at least three nodes to design any kind of IoT applications as given below.

  • Edge node where sensors are installed, in this case we will use Android mobile sensors;
  • Data Aggregator where we log sensor data, in this case we are going to use ThingSpeak;
  • Exploratory node where we do analysis on sensor data and also deploy our model on the edge node.

About ThingSpeak

ThingSpeak is an internet cloud where we log sensor data. It is a MathWorks product and it is free for students. You can log 3 million messages per year on ThingSpeak and 8,200 messages daily in a free version. If any student is working on a larger project then they can buy in a cheap price.

About MATLAB you can click here for recorded Webinars.

Support package

Our first step is to install the Simulink support package for Android mobile to create Android apps directly from Simulink. You can follow the steps below.

Step 1. From MATLAB window click on Add-Ons then Get Hardware Support Packages as given in the figure below.

Step 2. A new window will be opened as shown below. Search for Android

Step 3.

Click on link Simulink Support Package for Android Devices and install it.

Step 4. You will be asked to login with MathWorks account, provide your details and install it.

Step 5. After installation of support package we require to setup our Android mobile with MATLAB. Click Setup Now and follow all the steps during the configuration.

After Configuration you will get a message Hardware Setup Complete.

Note: If you are not able to install the support package from MATLAB Environment then you can download it from here.

After installation you will get Android libraries in Simulink as given below. We will use these libraries to design a fall detection model.

Fall detection model

Create a channel to log data on ThingSpeak

Step 1. Login on ThinsSpeak using MathWorks Account.

Step 2. Click on my Channel to create a channel where we will log data.

Step 3. Click on create channel and fill up the channel information as given below and click to Save Channel. I’ve selected Field 1 only because I want to log one sensor data only.

Step 4. Next click on API Key, note Channel ID and Write API Key.

Step 5. In Private View click on Add Widgets

Step 6. Select Lamp Indicator and click next.

Step 7. Provide information as given below and click create. So whenever a threshold value crosses 12, an indicator will indicate the red colour which will signify that mobile has fallen.

The ThingSpeak part is done now we will create a model in Simulink.

Create a model in Simulink to deploy in the Android mobile.

We will log accelerometer sensor data on ThingSpeak, if your mobile falls then x-axis acceleration value will cross 12m/sec^2 and the indicator will become red.

To design a model you require to know basics of Simulink. If you want to learn you can watch a recorded webinar here.

Step 1. Open a blank Simulink model and click on Library.

Step 2. Add an accelerometer sensor block and a ThingSpeak write block from Simulink Support Package for Android library.

Accelerometer Block
ThingSpeak Write block

Form Sink add 2 Terminator blocks.

Terminator block

Step 3. Add everything as given below.

Step 4. In this step we will modify parameter values that are channel ID and write API key of the channel. You have to provide your channel ID and write API key which you noted.

Double click on ThingSpeak write block and provide parameter values, and click apply.

Step 5. Select hardware to deploy the model. Follow the figure below.

Step 6. Connect your mobile with the laptop through usb cable in the same Wi-Fi.

Note:- Don’t forget to follow steps to configure Android mobile with MATLAB as mentioned above.

Step 7. Deploy the model by clicking Build Deploy & Start as given in figure below.

It will take time to deploy so be patient. When it is deployed in your mobile, an app will be created in your mobile. You can further disconnect usb cable. This app will send data on ThingSpeak. Whenever your mobile is fallen down you will see a red indicator on the ThingSpeak channel which you’ve created.

You can see your channel , x-axis accelerometer data started logging.

Indicator is off because it didn’t reach threshold value.
Red indicator is On , when your mobile will fall X-Axis acceleration will cross 12

Further if you want to read data in MATLAB you can use thingSpeakRead command.

In my case it is given below.

Further if you want to trace the location of your fallen device, you can use a GPS sensor block with accelerometer.

For any query you can comment below.


2 thoughts on “Internet of Things Application with MATLAB – Fall Detection”

Leave a Reply

Your email address will not be published.