Arduino Uno will be used to process the reading of 4 pieces of LM35 temperature sensor. The results of these readings will be displayed on the LCD. When there is an incoming SMS message saying "GET" then automatically Arduino will send the result from reading to four sensors to a certain number. But if the incoming SMS does not say "GET" then the LCD will display "wrong format". Modem or GSM module used in this project with SIM900A type, can also use Wavecom Modem, coding for both modem have been provided in this blog.
Hardware Requirement
- Arduino Uno Board
- LM35 Module (4)
- SIM900A GSM Module (you can also use Wavecom)
- LCD 16*2 or 20*4 (with i2c connection is recomended)
- Power supply +5 Volt
- Jumper
SIM900A | Source
Block Diagram
Schematic (GSM Module = Wavecom)
If using SIM900A, then no RS232 circuit, just connect to Arduino.
Arduino - LCD 16x2
Arduino LCD 20x4 Wiring
If using 20x4 LCD and I2C connection (I Square C) then the wiring table is as follows
Learn more about I2C connections --> Project V - 14
Arduino - LM35 Wiring
Arduino - Wavecom GSM Module
If using SIM900A then its wiring is as follows
Coding --> Wavecom
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
LiquidCrystal lcd(2,3, 4, 5, 6, 7);
const int rxpin = 8;
const int txpin = 9;
SoftwareSerial gsm(rxpin, txpin);
String inString="";
String inString2="";
String Stemp="";
String inbox="";
String noPengirim="";
unsigned int suhu1, suhu2, suhu3,suhu4;
char str,f;
int i,j;
void setup(){
gsm.begin(9600);
lcd.begin(16, 2);
lcd.print("Tes Koneksi...");
delay(1000);
gsm.println("AT");
getmodem();
getmodem();
lcd.setCursor(0, 1);
lcd.print(inString);
lcd.clear();
lcd.print(" Koneksi OK ");
delay(2000);
}
//===================program utama
void loop(){
lcd.begin(16,2);
lcd.clear();
lcd.print(" Telemetri 4 ch");
lcd.setCursor(0,1);
lcd.print(" by request SMS");
getmodem();
lcd.clear();
lcd.print("SMS Masuk...");
getmodem2();
i=inString2.indexOf(':');
if(i>0){
Stemp=inString2.substring(0,i);
if(Stemp=="+CMTI"){
i=inString2.indexOf(',');
j=inString2.length ();
i=i+1;
inbox=inString2.substring(i,j);
gsm.print("AT+CMGR=");
gsm.println(inbox);
getmodem();
getmodem();
getmodem2();
i=inString.indexOf(',');
i=i+2;
j=inString.indexOf(',',i);
j=j-1;
noPengirim=inString.substring(i,j);
//---------------------------------------------------SMS Get
if(inString2=="GET" || inString2=="Get" || inString2=="get"){
baca_sensor();
kirim_sms();
}
//--------------------------------------------------other sms
else {
gsm.print("AT+CMGS=");
gsm.println(noPengirim);
delay(1000);
gsm.print("Format Salah!");
gsm.write((byte)26);
gsm.println();
lcd.clear();
lcd.print("Format Salah!");
}
delay(3000);
lcd.clear();
lcd.print("Hapus SMS:");
//-------------------------hapus inbox
getmodem();
getmodem();
gsm.print("AT+CMGD=");
gsm.println(inbox);
do{
getmodem();
}
while(inString != "OK");
lcd.print(inbox);
lcd.setCursor(0,1);
lcd.print(inString);
delay(3000);
}
}
}
//====================baca data serial
void getmodem(){
f=1;
inString="";
while(f){
if(gsm.available()){
str=gsm.read();
switch (str){
case '\r': break;
case '\n':f=0; break;
default:inString+=(char)str;
}
}
}
}
//====================================
void getmodem2(){
f=1;
inString2="";
while(f){
if(gsm.available()>0){
str=gsm.read();
switch (str){
case '\r': break;
case '\n':f=0; break;
default:inString2+=(char)str;
}
}
}
}
//===================================baca sensor 1
void baca_sensor(){
suhu1 = (analogRead(0)*5)/10;
suhu2 = (analogRead(1)*5)/10;
suhu3 = (analogRead(2)*5)/10;
suhu4 = (analogRead(3)*5)/10;
lcd.clear();
lcd.print("T1:");
lcd.print(suhu1);
lcd.print("C ");
lcd.print("T2:");
lcd.print(suhu2);
lcd.print("C ");
lcd.setCursor(0,1);
lcd.print("T3:");
lcd.print(suhu3);
lcd.print("C ");
lcd.print("T4:");
lcd.print(suhu4);
lcd.print("C ");
delay(3000);
}
//====================================kirim SMS
void kirim_sms(){
gsm.print("AT+CMGS=");
gsm.println(noPengirim);
delay(1000);
gsm.print("T1:");
gsm.print(suhu1);
gsm.print("C, T2:");
gsm.print(suhu2);
gsm.print("C, T3:");
gsm.print(suhu3);
gsm.print("C, T4:");
gsm.print(suhu4);
gsm.print("C.");
gsm.write((byte)26);
gsm.println();
lcd.clear();
lcd.print("Kirim SMS....");
delay(2000);
}
#include <SoftwareSerial.h>
LiquidCrystal lcd(2,3, 4, 5, 6, 7);
const int rxpin = 8;
const int txpin = 9;
SoftwareSerial gsm(rxpin, txpin);
String inString="";
String inString2="";
String Stemp="";
String inbox="";
String noPengirim="";
unsigned int suhu1, suhu2, suhu3,suhu4;
char str,f;
int i,j;
void setup(){
gsm.begin(9600);
lcd.begin(16, 2);
lcd.print("Tes Koneksi...");
delay(1000);
gsm.println("AT");
getmodem();
getmodem();
lcd.setCursor(0, 1);
lcd.print(inString);
lcd.clear();
lcd.print(" Koneksi OK ");
delay(2000);
}
//===================program utama
void loop(){
lcd.begin(16,2);
lcd.clear();
lcd.print(" Telemetri 4 ch");
lcd.setCursor(0,1);
lcd.print(" by request SMS");
getmodem();
lcd.clear();
lcd.print("SMS Masuk...");
getmodem2();
i=inString2.indexOf(':');
if(i>0){
Stemp=inString2.substring(0,i);
if(Stemp=="+CMTI"){
i=inString2.indexOf(',');
j=inString2.length ();
i=i+1;
inbox=inString2.substring(i,j);
gsm.print("AT+CMGR=");
gsm.println(inbox);
getmodem();
getmodem();
getmodem2();
i=inString.indexOf(',');
i=i+2;
j=inString.indexOf(',',i);
j=j-1;
noPengirim=inString.substring(i,j);
//---------------------------------------------------SMS Get
if(inString2=="GET" || inString2=="Get" || inString2=="get"){
baca_sensor();
kirim_sms();
}
//--------------------------------------------------other sms
else {
gsm.print("AT+CMGS=");
gsm.println(noPengirim);
delay(1000);
gsm.print("Format Salah!");
gsm.write((byte)26);
gsm.println();
lcd.clear();
lcd.print("Format Salah!");
}
delay(3000);
lcd.clear();
lcd.print("Hapus SMS:");
//-------------------------hapus inbox
getmodem();
getmodem();
gsm.print("AT+CMGD=");
gsm.println(inbox);
do{
getmodem();
}
while(inString != "OK");
lcd.print(inbox);
lcd.setCursor(0,1);
lcd.print(inString);
delay(3000);
}
}
}
//====================baca data serial
void getmodem(){
f=1;
inString="";
while(f){
if(gsm.available()){
str=gsm.read();
switch (str){
case '\r': break;
case '\n':f=0; break;
default:inString+=(char)str;
}
}
}
}
//====================================
void getmodem2(){
f=1;
inString2="";
while(f){
if(gsm.available()>0){
str=gsm.read();
switch (str){
case '\r': break;
case '\n':f=0; break;
default:inString2+=(char)str;
}
}
}
}
//===================================baca sensor 1
void baca_sensor(){
suhu1 = (analogRead(0)*5)/10;
suhu2 = (analogRead(1)*5)/10;
suhu3 = (analogRead(2)*5)/10;
suhu4 = (analogRead(3)*5)/10;
lcd.clear();
lcd.print("T1:");
lcd.print(suhu1);
lcd.print("C ");
lcd.print("T2:");
lcd.print(suhu2);
lcd.print("C ");
lcd.setCursor(0,1);
lcd.print("T3:");
lcd.print(suhu3);
lcd.print("C ");
lcd.print("T4:");
lcd.print(suhu4);
lcd.print("C ");
delay(3000);
}
//====================================kirim SMS
void kirim_sms(){
gsm.print("AT+CMGS=");
gsm.println(noPengirim);
delay(1000);
gsm.print("T1:");
gsm.print(suhu1);
gsm.print("C, T2:");
gsm.print(suhu2);
gsm.print("C, T3:");
gsm.print(suhu3);
gsm.print("C, T4:");
gsm.print(suhu4);
gsm.print("C.");
gsm.write((byte)26);
gsm.println();
lcd.clear();
lcd.print("Kirim SMS....");
delay(2000);
}
Coding --> Sim900A (Recomended) and use Serial Monitor as a replacement of LCD
#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#define PIN_TX 9
#define PIN_RX 8
#define BAUDRATE 9600
#define PHONE_NUMBER "085640207374"// sesuaikan
#define MESSAGE_TRUE "Format salah"
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char data[50];
char phone[16];
char datetime[24];
int suhu1, suhu2, suhu3, suhu4;
String suhu_all;
GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate
void setup() {
Serial.begin(9600);
while (!gprsTest.init()) {
delay(1000);
Serial.print("init error\r\n");
}
Serial.println("gprs init success");
//define phone number and text
}
void loop() {
//nothing to do
messageIndex = gprsTest.isSMSunread();
if (messageIndex > 0) { //At least, there is one UNREAD SMS
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
//In order not to full SIM Memory, is better to delete it
gprsTest.deleteSMS(messageIndex);
if (String(message) == "GET")
{
Serial.print("From number: ");
Serial.println(phone);
Serial.print("Datetime: ");
Serial.println(datetime);
Serial.print("Recieved Message: ");
Serial.println(message);
suhu1 = (analogRead(0) * 5) / 150;
suhu2 = (analogRead(1) * 5) / 150;
suhu3 = (analogRead(2) * 5) / 150;
suhu4 = (analogRead(3) * 5) / 150;
suhu_all = String(suhu1)+ "C " + String(suhu2) +"C " + String(suhu3) + "C " + String(suhu4)+"C ";
Serial.println(suhu_all);
delay(3000);
suhu_all.toCharArray(data, 50);
gprsTest.sendSMS(PHONE_NUMBER, data);
Serial.println("Sending Message . . .");
}
else
{
Serial.print("Format Salah");
gprsTest.sendSMS(PHONE_NUMBER, MESSAGE_TRUE);
}
}
}
#include <SoftwareSerial.h>
#include <Wire.h>
#define PIN_TX 9
#define PIN_RX 8
#define BAUDRATE 9600
#define PHONE_NUMBER "085640207374"// sesuaikan
#define MESSAGE_TRUE "Format salah"
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char data[50];
char phone[16];
char datetime[24];
int suhu1, suhu2, suhu3, suhu4;
String suhu_all;
GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate
void setup() {
Serial.begin(9600);
while (!gprsTest.init()) {
delay(1000);
Serial.print("init error\r\n");
}
Serial.println("gprs init success");
//define phone number and text
}
void loop() {
//nothing to do
messageIndex = gprsTest.isSMSunread();
if (messageIndex > 0) { //At least, there is one UNREAD SMS
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
//In order not to full SIM Memory, is better to delete it
gprsTest.deleteSMS(messageIndex);
if (String(message) == "GET")
{
Serial.print("From number: ");
Serial.println(phone);
Serial.print("Datetime: ");
Serial.println(datetime);
Serial.print("Recieved Message: ");
Serial.println(message);
suhu1 = (analogRead(0) * 5) / 150;
suhu2 = (analogRead(1) * 5) / 150;
suhu3 = (analogRead(2) * 5) / 150;
suhu4 = (analogRead(3) * 5) / 150;
suhu_all = String(suhu1)+ "C " + String(suhu2) +"C " + String(suhu3) + "C " + String(suhu4)+"C ";
Serial.println(suhu_all);
delay(3000);
suhu_all.toCharArray(data, 50);
gprsTest.sendSMS(PHONE_NUMBER, data);
Serial.println("Sending Message . . .");
}
else
{
Serial.print("Format Salah");
gprsTest.sendSMS(PHONE_NUMBER, MESSAGE_TRUE);
}
}
}
How it Works
1. Connect the Arduino with Peripherals needed.
2. Plug in the Power Source on the device.
3. Add some library if needed
4. Compile and upload the script program5. First, Modem will initialize and it takes about 3 seconds
6. When there is an incoming SMS and it says "GET" then arduino will send data in the form of
reading result
sensor LM35 to the specified number that has been set in the program.
7. When there is an incoming SMS other than it says "GET" then the arduino will send a form of text
"wrong format" to the number.
8. On the monitor series is also displayed part of the process of sending and reading data.
Video for Project II - 6. Temperature 4 Channel Monitoring with SMS Method Based on Arduino
Required file
No comments:
Post a Comment