Sensor Value Triggered SMS Alert Using LinkitOne

by KedarP1 in Circuits > Sensors

1776 Views, 38 Favorites, 0 Comments

Sensor Value Triggered SMS Alert Using LinkitOne

FTADIAZII8ZUMPP.jpeg

Another great feature of the MediaTek LinkitOne development board is the support for SIM cards!
The opportunities of developing something really cool with the Linkit are endless.
In this instructable, let us look at how read sensor values and send a SMS alert to specified phone when the sensor values cross a threshold mark.

So let us get started!

What You'll Need?

images.jpg
C360_2015-12-16-23-19-52-341.jpg
share.jpg

1. LinkitOne
2. SIM card
3. Sensor of your choice (here I will be using the Grove Kit sensors)

Assembly

C360_2015-12-16-23-08-24-904.jpg

The assembly for this project is pretty simple as you would have guessed already.
Just insert the SIM card in the slot on your Linkit One, connect your sensor and you are good to go!

Make sure you have an appropriate text messaging plan in your SIM before proceeding! :)

The Code!

Let me explain what exactly the program should be doing.

As the project title states, the Linkit will send a text message to a specific number after a certain value on the analog sensor is crossed. So basically what we need to do is to write a program which reads the sensor value after specific periods of time and checks the value with a specified threshold. If the value crosses this mark, a pre defined SMS will be sent to the number given!

Sounds easy, doesn't it?

Let's code!

Make sure to include GSM and your sensor libraries. I have connected the Grove temp sensor which is based on DHT 22.

#include "LGSM.h"
#include "DHT.h"

#define DHTPIN 2 // what pin we've connected the temp sensor to
#define DHTTYPE DHT22 // DHT 22 (AM2302)

String message = "Attention! Temperature crossed 30 degrees Celsius.";

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
Serial.begin(9600);
dht.begin();
while (!LSMS.ready()) // Wait for the sim to initialize
{
delay(1000); // Wait for a second and then try again
}
Serial.println("Sim initialized"); // When SIM is started, print "Sim initialized" in the serial port
LSMS.beginSMS("0123456789"); // Saves the number where user wants to send SMS. To be changed before uploading sketch
}

void loop()
{
float t = 0.0;
float h = 0.0;
LSMS.print(message); // Prepare message variable to be sent by LSMS
if(dht.readHT(&t, &h))

{
Serial.println("------------------------------");
Serial.print("temperature = ");
Serial.println(t);
Serial.print("humidity = ");
Serial.println(h);
}
int temp=(int)t;
if(temp>30)
{
if (LSMS.endSMS())
// If so, send the SMS
{
Serial.println("SMS sent"); // Print "SMS sent" in serial port if sending is successful
}
else
{
Serial.println("SMS is not sent");
// Else print "SMS is not sent"
}
}

else
{
Serial.println("Temperature not more than 30.");
}
delay(10000);

//make it wait for 10 seconds!
}

Epilogue - Applications

This project has many real life applications.

It can be used in a cold chain truck to monitor temperatures.. Keep it in your house to monitor dust levels, if you are allergic to dust (like me :) ), or in your car if you are lending it to someone to keep a check on the speed and acceleration!

Just like I said, the possibilities are endless! :D