Arduino Uno akan digunakan untuk memproses hasil pembacaan 4 buah sensor suhu LM35. Hasil dari pembacaan tersebut akan ditampilkan pada LCD. Ketika ada SMS masuk berupa pesan bertuliskan "GET" maka secara otomatis Arduino akan mengirimkan hasil dari pembacaan ke empat sensor ke nomer tertentu. Tetapi jika SMS yang masuk tidak bertuliskan "GET" maka pada LCD akan menampilkan "format salah". Modem atau modul GSM yang digunakan pada project ini dengan tipe SIM900A, dapat juga menggunakan Modem Wavecom, coding untuk kedua modem tersebut telah disediakan di blog ini.
Kebutuhan Hardware
- 4 Sensor LM35
- Modem SMS Getway (SIM900A)
- Modul Serial RS232
- Modul LCD 2x16 atau 20x4 (dengan koneksi i2c)
- Modul Arduino UNO
- Power supply +5Volt
LM35 Temperature Sensor | Source
SIM900A | Source
Diagram Blok
Schematic (Modul GSM = Wavecom)
Arduino - LCD 16x2
Arduino LCD 20x4
Jika menggunakan LCD 20x4 dan koneksi I2C (I Square C) maka wiringya adalah sebagai berikut
Selengkapnya tentang koneksi I2C --> Project V - 14
Arduino - LM35 Wiring
Arduino - Wavecom GSM Module
Jika menggunakan SIM900A maka wiring nya adalah sebagai berikut
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) dengan Serial Monitor
#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);
}
}
}
Cara Kerja Alat
1. Koneksikan antara sistem Arduino dengan peripheral lain seperti pada rangkaian (skematik).
2. Pasang power supply (adaptor 5 V) dan hidupkan (colokkan ke sumber PLN 220V) sehingga
lampu LED indikator nyala, LCD juga nyala.
3. Pertama, Modum akan melakukan inisialisasi membutuhkan waktu kira-kira 3 detik
4. Ketika ada SMS masuk berupa "GET" maka arduino akan mengirimkan data berupa hasil pembacaan
sensor LM35 ke nomer tertentu yang telah di set pada program.
5. Ketika ada SMS masuk selain bertuliskan"GET" maka arduino akan mengirimkan tulisan berupa
"format salah" ke nomer tersebut.
6. Pada serial monitor juga ditampilkan sebagian proses pengiriman dan pembacaan data.
Video untuk Project II - 6. Monitoring 4 Channel of Temperature with SMS Method Based on Arduino
KONTAK KAMI 085743320570 (adi sanjaya)
hello, i have tried this coding using arduino and sim900 a but there's an error. It saya that GPRS does not have a name type in the coding GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE);
ReplyDeletedo you know what is the error?
Bonjour,je ne vois pas l’intérêt de partager des poste qui ne fonctionne pas?
ReplyDelete