Arduino UNO mengontrol nyala dan mati 4 lampu dengan SMS. Apabila ingin menghidupkan lampu no.1 saja cukup SMS “1 on” kemudian lampu no.1 menyala selanjutnya mikrokontroler membaca sensor cahaya, jika lampu menyala maka mikrokontroler membalas SMS tersebut dengan “Lampu 1 ON” jika tidak menyala maka isi balasannya “Lampu 1 OFF”. Sedangkan untuk mematikan lampu 1 cukup dengan SMS “1 off” nantinya juga ada SMS balasan. Begitupula untuk kontrol lampu yang lain tinggal diganti lampu mana yang akan di kontrol.
Kebutuhan Hardware
- Relay 4 Channel
- Modem SMS Getway (SIM900A / Wavecom)
- Modul Serial RS232
- Modul LCD 2x16 atau 20x4 (dengan koneksi i2c)
- Modul Arduino UNO
- Power supply +5Volt
Relay 4 Channel | Source
SIM900A | Source
Diagram Blok A (menggunakanSIM900A)
Schematic A (menggunakan wavecom)
Jika menggunakan SIM900A, maka tidak perlu rangkaian RS232, langsung saja koneksikan ke Arduino.
(Alternatif) Diagram Blok B (menggunakan Wavecom dan LDR)
(Alternatif) Schematic B (menggunakan Wavecom dan LDR)
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 - Relay
(Alternatif) Arduino - LDR
Arduino - Wavecom GSM Module
Arduino - SIM900A
Source Code --> 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="";
String Sensor="";
String Sensor1="";
String Sensor2="";
String Sensor3="";
String Sensor4="";
char str,f;
int i,j;
void setup() {
gsm.begin(9600);
lcd.begin(16,2);
lcd.print("Kontrol 4 Lampu");
lcd.setCursor(0,1);
lcd.print(" Via SMS");
delay(2000);
lcd.clear();
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);
//--------------------------dig output Relay
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
digitalWrite(A0, 0);
digitalWrite(A1, 0);
digitalWrite(A2, 0);
digitalWrite(A3, 0);
//--------------------------dig input baca LDR
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
//--------------------------pull up
digitalWrite(10, 1);
digitalWrite(11, 1);
digitalWrite(12, 1);
digitalWrite(13, 1);
}
//=============================program utama
void loop() {
lcd.begin(16,2);
lcd.print("SMS Control 4Rly");
lcd.setCursor(0,1);
lcd.print("Tunggu SMS masuk");
//----------------------data ENTER
getmodem();
lcd.begin(16,2);
lcd.print("SMS Masuk...");
//----------------------data CMTI:
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);
//----------------------------------------------------Relay ON
if(inString2=="1 on"){
digitalWrite(A0,1);
delay(200);
baca_sensor1();
kirim_sms();
}
else if(inString2=="2 on"){
digitalWrite(A1,1);
delay(200);
baca_sensor2();
kirim_sms();
}
else if(inString2=="3 on"){
digitalWrite(A2,1);
delay(200);
baca_sensor3();
kirim_sms();
}
else if(inString2=="4 on"){
digitalWrite(A3,1);
delay(200);
baca_sensor4();
kirim_sms();
}
//---------------------------------------------isi SMS "All on"
else if(inString2=="All on"){
digitalWrite(A0,1);
digitalWrite(A1,1);
digitalWrite(A2,1);
digitalWrite(A3,1);
delay(200);
baca_all_sensor();
kirim_all_sms();
}
//----------------------------------------------------Relay OFF
else if(inString2=="1 off"){
digitalWrite(A0,0);
delay(200);
baca_sensor1();
kirim_sms();
}
else if(inString2=="2 off"){
digitalWrite(A1,0);
delay(200);
baca_sensor2();
kirim_sms();
}
else if(inString2=="3 off"){
digitalWrite(A2,0);
delay(200);
baca_sensor3();
kirim_sms();
}
else if(inString2=="4 off"){
digitalWrite(A3,0);
delay(200);
baca_sensor4();
kirim_sms();
}
//-------------------------------------------isi SMS "All off"
else if(inString2=="All off"){
digitalWrite(A0,0);
digitalWrite(A1,0);
digitalWrite(A2,0);
digitalWrite(A3,0);
delay(200);
baca_all_sensor();
kirim_all_sms();
}
//-----------------------------------------------isi SMS "Cek"
else if(inString2=="Cek"){
baca_all_sensor();
kirim_all_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.begin(16,2);
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_sensor1(){
if (digitalRead(10) == 0){
Sensor="Lampu 1= ON ";
}
else{
Sensor="Lampu 1= OFF";
}
}
//====================================baca sensor 2
void baca_sensor2(){
if (digitalRead(11) == 0){
Sensor="Lampu 2= ON ";
}
else{
Sensor="Lampu 2= OFF";
}
}
//====================================baca sensor 3
void baca_sensor3(){
if (digitalRead(12) == 0){
Sensor="Lampu 3= ON ";
}
else{
Sensor="Lampu 3= OFF";
}
}
//====================================baca sensor 4
void baca_sensor4(){
if (digitalRead(13) == 0){
Sensor="Lampu 4= ON ";
}
else{
Sensor="Lampu 4= OFF";
}
}
//====================================baca semua sensor
void baca_all_sensor(){
delay(1000);
if (digitalRead(11) == 0){
Sensor2="ON ";
}
else{
Sensor2="OFF";
}
if (digitalRead(12) == 0){
Sensor3="ON ";
}
else{
Sensor3="OFF";
}
if (digitalRead(13) == 0){
Sensor4="ON ";
}
else{
Sensor4="OFF";
}
if (digitalRead(10) == 0){
Sensor1="ON ";
}
else{
Sensor1="OFF";
}
}
//====================================kirim SMS
void kirim_sms(){
gsm.print("AT+CMGS=");
gsm.println(noPengirim);
delay(1000);
gsm.print(Sensor);
gsm.write((byte)26);
gsm.println();
lcd.begin(16,2);
lcd.print(Sensor);
lcd.setCursor(0,1);
lcd.print("Kirim SMS....");
}
//====================================kirim Semua SMS
void kirim_all_sms(){
gsm.print("AT+CMGS=");
gsm.println(noPengirim);
delay(1000);
gsm.print("Lampu1="); gsm.print(Sensor1); gsm.print(", ");
gsm.print("Lampu2="); gsm.print(Sensor2); gsm.print(", ");
gsm.print("Lampu3="); gsm.print(Sensor3); gsm.print(", ");
gsm.print("Lampu4="); gsm.print(Sensor4); gsm.print(".");
gsm.write((byte)26);
gsm.println();
lcd.begin(16,2);
lcd.print("Kirim SMS....");
delay(1000);
lcd.begin(16,2);
lcd.print("L1:"); lcd.print(Sensor1);
lcd.print(" L2:"); lcd.print(Sensor2);
lcd.setCursor(0, 1);
lcd.print("L3:"); lcd.print(Sensor3);
lcd.print(" L4:"); lcd.print(Sensor4);
lcd.setCursor(0,1);
}
#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="";
String Sensor="";
String Sensor1="";
String Sensor2="";
String Sensor3="";
String Sensor4="";
char str,f;
int i,j;
void setup() {
gsm.begin(9600);
lcd.begin(16,2);
lcd.print("Kontrol 4 Lampu");
lcd.setCursor(0,1);
lcd.print(" Via SMS");
delay(2000);
lcd.clear();
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);
//--------------------------dig output Relay
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
digitalWrite(A0, 0);
digitalWrite(A1, 0);
digitalWrite(A2, 0);
digitalWrite(A3, 0);
//--------------------------dig input baca LDR
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
//--------------------------pull up
digitalWrite(10, 1);
digitalWrite(11, 1);
digitalWrite(12, 1);
digitalWrite(13, 1);
}
//=============================program utama
void loop() {
lcd.begin(16,2);
lcd.print("SMS Control 4Rly");
lcd.setCursor(0,1);
lcd.print("Tunggu SMS masuk");
//----------------------data ENTER
getmodem();
lcd.begin(16,2);
lcd.print("SMS Masuk...");
//----------------------data CMTI:
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);
//----------------------------------------------------Relay ON
if(inString2=="1 on"){
digitalWrite(A0,1);
delay(200);
baca_sensor1();
kirim_sms();
}
else if(inString2=="2 on"){
digitalWrite(A1,1);
delay(200);
baca_sensor2();
kirim_sms();
}
else if(inString2=="3 on"){
digitalWrite(A2,1);
delay(200);
baca_sensor3();
kirim_sms();
}
else if(inString2=="4 on"){
digitalWrite(A3,1);
delay(200);
baca_sensor4();
kirim_sms();
}
//---------------------------------------------isi SMS "All on"
else if(inString2=="All on"){
digitalWrite(A0,1);
digitalWrite(A1,1);
digitalWrite(A2,1);
digitalWrite(A3,1);
delay(200);
baca_all_sensor();
kirim_all_sms();
}
//----------------------------------------------------Relay OFF
else if(inString2=="1 off"){
digitalWrite(A0,0);
delay(200);
baca_sensor1();
kirim_sms();
}
else if(inString2=="2 off"){
digitalWrite(A1,0);
delay(200);
baca_sensor2();
kirim_sms();
}
else if(inString2=="3 off"){
digitalWrite(A2,0);
delay(200);
baca_sensor3();
kirim_sms();
}
else if(inString2=="4 off"){
digitalWrite(A3,0);
delay(200);
baca_sensor4();
kirim_sms();
}
//-------------------------------------------isi SMS "All off"
else if(inString2=="All off"){
digitalWrite(A0,0);
digitalWrite(A1,0);
digitalWrite(A2,0);
digitalWrite(A3,0);
delay(200);
baca_all_sensor();
kirim_all_sms();
}
//-----------------------------------------------isi SMS "Cek"
else if(inString2=="Cek"){
baca_all_sensor();
kirim_all_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.begin(16,2);
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_sensor1(){
if (digitalRead(10) == 0){
Sensor="Lampu 1= ON ";
}
else{
Sensor="Lampu 1= OFF";
}
}
//====================================baca sensor 2
void baca_sensor2(){
if (digitalRead(11) == 0){
Sensor="Lampu 2= ON ";
}
else{
Sensor="Lampu 2= OFF";
}
}
//====================================baca sensor 3
void baca_sensor3(){
if (digitalRead(12) == 0){
Sensor="Lampu 3= ON ";
}
else{
Sensor="Lampu 3= OFF";
}
}
//====================================baca sensor 4
void baca_sensor4(){
if (digitalRead(13) == 0){
Sensor="Lampu 4= ON ";
}
else{
Sensor="Lampu 4= OFF";
}
}
//====================================baca semua sensor
void baca_all_sensor(){
delay(1000);
if (digitalRead(11) == 0){
Sensor2="ON ";
}
else{
Sensor2="OFF";
}
if (digitalRead(12) == 0){
Sensor3="ON ";
}
else{
Sensor3="OFF";
}
if (digitalRead(13) == 0){
Sensor4="ON ";
}
else{
Sensor4="OFF";
}
if (digitalRead(10) == 0){
Sensor1="ON ";
}
else{
Sensor1="OFF";
}
}
//====================================kirim SMS
void kirim_sms(){
gsm.print("AT+CMGS=");
gsm.println(noPengirim);
delay(1000);
gsm.print(Sensor);
gsm.write((byte)26);
gsm.println();
lcd.begin(16,2);
lcd.print(Sensor);
lcd.setCursor(0,1);
lcd.print("Kirim SMS....");
}
//====================================kirim Semua SMS
void kirim_all_sms(){
gsm.print("AT+CMGS=");
gsm.println(noPengirim);
delay(1000);
gsm.print("Lampu1="); gsm.print(Sensor1); gsm.print(", ");
gsm.print("Lampu2="); gsm.print(Sensor2); gsm.print(", ");
gsm.print("Lampu3="); gsm.print(Sensor3); gsm.print(", ");
gsm.print("Lampu4="); gsm.print(Sensor4); gsm.print(".");
gsm.write((byte)26);
gsm.println();
lcd.begin(16,2);
lcd.print("Kirim SMS....");
delay(1000);
lcd.begin(16,2);
lcd.print("L1:"); lcd.print(Sensor1);
lcd.print(" L2:"); lcd.print(Sensor2);
lcd.setCursor(0, 1);
lcd.print("L3:"); lcd.print(Sensor3);
lcd.print(" L4:"); lcd.print(Sensor4);
lcd.setCursor(0,1);
}
Coding --> Sim900A (Recomended)
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <GPRS_Shield_Arduino.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
#define PIN_TX 9
#define PIN_RX 8
#define BAUDRATE 9600
#define PHONE_NUMBER "085714112026"// sesuaikan
#define relay_1on "Relay 1 On"
#define relay_2on "Relay 2 On"
#define relay_3on "Relay 3 On"
#define relay_4on "Relay 4 On"
#define relay_1off "Relay 1 Off"
#define relay_2off "Relay 2 Off"
#define relay_3off "Relay 3 Off"
#define relay_4off "Relay 4 Off"
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char data[50];
char phone[16];
char datetime[24];
GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate
void setup() {
lcd.begin();
lcd.setCursor(0, 0);
lcd.print("Initialization...");
delay(1000);
Serial.begin(9600);
while (!gprsTest.init()) {
delay(1000);
lcd.setCursor(0, 1);
lcd.print("init error\r\n");
}
lcd.setCursor(0, 2);
lcd.println("gprs init success");
delay(2000);
lcd.clear();
//--------------------------dig output Relay
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
digitalWrite(A0, 1);
digitalWrite(A1, 1);
digitalWrite(A2, 1);
digitalWrite(A3, 1);
}
//============================================program utama
void loop() {
lcd.setCursor(0, 0);
lcd.print(" Remote 4 Relay");
lcd.setCursor(0, 1);
lcd.print(" System is Ready");
lcd.setCursor(0, 2);
lcd.print(" Waiting ");
//----------------------data CMTI:
messageIndex = gprsTest.isSMSunread();
if (messageIndex > 0) { //At least, there is one UNREAD SMS
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
//----------------------data ENTER
lcd.setCursor(0, 2);
lcd.print(" 1 New Message ");
//In order not to full SIM Memory, is better to delete it
gprsTest.deleteSMS(messageIndex);
if (String(message) == "1 on")
{
lcd.setCursor(0, 3);
lcd.print(" Relay 1 On");
digitalWrite(A0, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_1on);
}
else if (String(message) == "2 on") {
lcd.setCursor(0, 3);
lcd.print(" Relay 2 On");
digitalWrite(A1, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_2on);
}
else if (String(message) == "3 on") {
lcd.setCursor(0, 3);
lcd.print(" Relay 3 On");
digitalWrite(A2, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_3on);
}
else if (String(message) == "4 on") {
lcd.setCursor(0, 3);
lcd.print(" Relay 4 On");
digitalWrite(A3, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_4on);
}
//-------------------------isi SMS "1 off"
else if (String(message) == "1 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 1 Off");
digitalWrite(A0, 1);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_1off);
}
//-------------------------isi SMS "2 off"
else if (String(message) == "2 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 2 Off");
digitalWrite(A1, 1);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_2off);
}
else if (String(message) == "3 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 3 Off");
digitalWrite(A2, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_3off);
}
else if (String(message) == "4 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 4 Off");
digitalWrite(A3, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_4off);
}
lcd.setCursor(0, 2);
lcd.print(" Sending a Message");
delay(3000);
lcd.clear();
}
}
#include <SoftwareSerial.h>
#include <GPRS_Shield_Arduino.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
#define PIN_TX 9
#define PIN_RX 8
#define BAUDRATE 9600
#define PHONE_NUMBER "085714112026"// sesuaikan
#define relay_1on "Relay 1 On"
#define relay_2on "Relay 2 On"
#define relay_3on "Relay 3 On"
#define relay_4on "Relay 4 On"
#define relay_1off "Relay 1 Off"
#define relay_2off "Relay 2 Off"
#define relay_3off "Relay 3 Off"
#define relay_4off "Relay 4 Off"
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char data[50];
char phone[16];
char datetime[24];
GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate
void setup() {
lcd.begin();
lcd.setCursor(0, 0);
lcd.print("Initialization...");
delay(1000);
Serial.begin(9600);
while (!gprsTest.init()) {
delay(1000);
lcd.setCursor(0, 1);
lcd.print("init error\r\n");
}
lcd.setCursor(0, 2);
lcd.println("gprs init success");
delay(2000);
lcd.clear();
//--------------------------dig output Relay
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
digitalWrite(A0, 1);
digitalWrite(A1, 1);
digitalWrite(A2, 1);
digitalWrite(A3, 1);
}
//============================================program utama
void loop() {
lcd.setCursor(0, 0);
lcd.print(" Remote 4 Relay");
lcd.setCursor(0, 1);
lcd.print(" System is Ready");
lcd.setCursor(0, 2);
lcd.print(" Waiting ");
//----------------------data CMTI:
messageIndex = gprsTest.isSMSunread();
if (messageIndex > 0) { //At least, there is one UNREAD SMS
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
//----------------------data ENTER
lcd.setCursor(0, 2);
lcd.print(" 1 New Message ");
//In order not to full SIM Memory, is better to delete it
gprsTest.deleteSMS(messageIndex);
if (String(message) == "1 on")
{
lcd.setCursor(0, 3);
lcd.print(" Relay 1 On");
digitalWrite(A0, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_1on);
}
else if (String(message) == "2 on") {
lcd.setCursor(0, 3);
lcd.print(" Relay 2 On");
digitalWrite(A1, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_2on);
}
else if (String(message) == "3 on") {
lcd.setCursor(0, 3);
lcd.print(" Relay 3 On");
digitalWrite(A2, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_3on);
}
else if (String(message) == "4 on") {
lcd.setCursor(0, 3);
lcd.print(" Relay 4 On");
digitalWrite(A3, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_4on);
}
//-------------------------isi SMS "1 off"
else if (String(message) == "1 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 1 Off");
digitalWrite(A0, 1);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_1off);
}
//-------------------------isi SMS "2 off"
else if (String(message) == "2 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 2 Off");
digitalWrite(A1, 1);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_2off);
}
else if (String(message) == "3 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 3 Off");
digitalWrite(A2, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_3off);
}
else if (String(message) == "4 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 4 Off");
digitalWrite(A3, 0);
delay(2000);
gprsTest.sendSMS(PHONE_NUMBER, relay_4off);
}
lcd.setCursor(0, 2);
lcd.print(" Sending a Message");
delay(3000);
lcd.clear();
}
}
Cara Kerja Alat (Menggunakan SIM900A)
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. Ketika pertama kali dihidupkan.
4. Ketika menerima SMS dengan format tertentu maka LCD akan menampilkan
5. Kemudian akan mengeksekusi perintah tersbut dan langsung mengirimkan SMS feed back
6. LCD akan kembali ke tampilan normal
Video untuk Project III - 4. Kontrol 4 Channel Relay menggunakan SMS dengan Feedback berbasis Arduino
Project V - 9. Sistem Keamanan Rumah dengan 3 Sensor berbasis SMS menggunakan Arduino
|| AT-Command ||
Merupakan sebuah sistem keamanan yang menggunakan SMS sebagai kontrol
dan feedback dari sistem. Dengan menggunakan 3 buah sensor, Sensor Api
yang akan mendeteksi adanya api atau kebakaran, Sensor Gas yang akan
mendeteksi adanya gas bocor atau lebih tepatnya LPG pada kompor, dan
Sensor PIR yang berfungsi untuk mendeteksi adanya gerakan manusia.
Ketika salah satu dari ketiga sensor mendeteksia adanya hal-hal tadi,
maka secara otomatis Arduino diprogram untuk menyalakan buzzer dan
mengirimkan pesan teks ke nomor tertentu yang berisikan bahwa ada
sesuatu terdeteksi tergantung dari sensor apa yang mendeteksi. Selain
untuk menerima feed back berupa pesan tersebut, sistem ini juga
dikontrol menggunakan SMS untuk : menyalakan sistem, mematikan sistem,
dan mematikan alarm ketika. Mematikan alarm digunakan untuk mematikan
buzzer ketika sensor mendeksi adanya sesuatu. Sebuah LED digunakan
sebagai indikator apakah sistem kemanan telah aktif atau tidak. Selain
itu, sistem juga dilengkapi dengan sebuah LCD 20x4 yang terhubung
menggunakan modul I2C pada arduino, setiap jalannya proses dan beberapa
informasi akan ditampilkan pada LCD tersebut.
Schematic
Arduino - Output Component Wiring
Arduino - SIM900A Wiring
Kebutuhan Hardware
- Modem SMS Getway (SIM900A)
- Sensor Api (Flame Sensor)
- Sensor Gas (MQ2)
- Sensor PIR
- LED
- Buzzer
- PC / Laptop dengan Arduino IDE
- Modul LCD 20x4 (dengan koneksi i2c)
- Modul I2C
- Modul Arduino UNO
- Power supply +5Volt
Diagram Blok
Schematic
Wiring untuk SIM900A
Arduino - Sensors Wiring
Arduino - Output Component Wiring
Arduino - I2C Wiring
Selengkapnya tentang koneksi I2C --> Project V - 14
Source Code
LiquidCrystal_I2C lcd(0x3F, 20, 4);
boolean stringComplete = false;
String inputString = "";
String fromGSM = "";
String my_number = "082322514735";
int pir = 10; //sensor gerak/orang
int mq = 11; //sensor gas
int api = 12; //sensor api
int buzzer = 13; //alarm
int led = 7; //led
unsigned long millisAwal, timeBuzz;
char str, f;
int i, j;
byte keluar = 1;
boolean sensorON = false;
void setup()
{
lcd.begin();
lcd.setCursor(0, 0);
lcd.print("Initialization Modem");
delay(1000);
pinMode(pir, INPUT);
pinMode(mq, INPUT);
pinMode(api, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("Serial Connected");
mySerial.begin(9600);
inputString.reserve(200);
fromGSM.reserve(200);
mySerial.print("ATE0");
mySerial.print("\r");
delay(300);
lcd.setCursor(0, 2);
lcd.print(" DONE ");
delay(1000);
lcd.clear();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Initial Sensor ");
delay(2000);
while (!digitalRead(mq));
lcd.setCursor(0, 2);
lcd.print(" DONE ");
delay(2000);
lcd.clear();
}
void sendSMS(String& phone_number, char message[] )
{
mySerial.print("AT+CMGF=1");
mySerial.print("\r");
delay(500);
mySerial.print("AT+CMGS=\"" + phone_number + "\"\r");
delay(700);
mySerial.print(message);
mySerial.write(0x1A);
delay(500);
}
void recSMS()
{
if (mySerial.available()) {
char inChar = mySerial.read();
if (inChar == '\n') {
//check the state
if (fromGSM == "OK\r") {
Serial.println("AT Command, Done !");
}
else if (fromGSM == "ON\r") {
Serial.println("sensorOn = true");
sensorON = true;
digitalWrite(led, HIGH);
}
else if (fromGSM == "OFF\r") {
Serial.println("sensorOff = false");
sensorON = false;
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
}
else if (fromGSM == "ALARMOFF\r") {
Serial.println("sensorOff = false");
keluar = 0;
digitalWrite(buzzer, LOW);
}
else if (fromGSM == "ERROR\r") {
Serial.println("GSM Error");
}
// Serial.println(fromGSM);
fromGSM = "";
} else {
fromGSM += inChar;
}
delay(20);
}
if (stringComplete) {
mySerial.print(inputString);
inputString = "";
stringComplete = false;
}
}
void loop ()
{
lcd.setCursor(0, 0);
lcd.print("Home Security System");
lcd.setCursor(0, 1);
lcd.print(" SMS Based");
lcd.setCursor(0, 3);
bacaSensor();
recSMS();
if (sensorON == false) {
lcd.setCursor(0, 2);
lcd.print(" Sensor OFF ");
lcd.setCursor(0, 3);
lcd.print(" nonactive ");
}
else {
lcd.setCursor(0, 2);
lcd.print(" Sensor ON ")
lcd.setCursor(0, 3);
lcdprint(" Secure ");
}
}
void bacaSensor() {
//----------------------------------baca sensor gerak
if (digitalRead(pir) == HIGH && sensorON == true) {
digitalWrite(buzzer, HIGH);
lcd.setCursor(0, 2);
lcd.print(" There is Movement");
lcd.setCursor(0, 3);
lcd.print("Conditions of Danger");
char myMessage[] = "There is Movement";
sendSMS(my_number, myMessage);
millisAwal = millis();
do {
timeBuzz = millis() - millisAwal;
recSMS();
//-------waktu lama buzzer ON 5 menit / 300000 mili detik
if (timeBuzz > 300000) {
keluar = 0;
}
}
while (keluar);
keluar = 1;
digitalWrite(buzzer, LOW);
lcd.clear();
}
else if (sensorON == true) {
lcd.setCursor(0, 3);
lcd.print(" Secure ");
}
//----------------------------------baca sensor asap
if (digitalRead(mq) == LOW && sensorON == true) {
digitalWrite(buzzer, HIGH);
lcd.setCursor(0, 2);
lcd.print(" There is Gas");
lcd.setCursor(0, 3);
lcd.print("Conditions of Danger");
char myMessage[] = "There is Gas";
sendSMS(my_number, myMessage);
millisAwal = millis();
do {
timeBuzz = millis() - millisAwal;
recSMS();
//-------waktu lama buzzer ON 5 menit / 300000 mili detik
if (timeBuzz > 300000) {
keluar = 0;
}
}
while (keluar);
keluar = 1;
digitalWrite(buzzer, LOW);
lcd.clear();
}
else if (sensorON == true) {
lcd.setCursor(0, 3);
lcd.print(" Secure ");
}
//----------------------------------baca sensor api
if (digitalRead(api) == LOW && sensorON == true) {
digitalWrite(buzzer, HIGH);
lcd.setCursor(0, 2);
lcd.print(" There is Fire");
lcd.setCursor(0, 3);
lcd.print("Conditions of Danger");
char myMessage[] = "There is Fire";
sendSMS(my_number, myMessage);
millisAwal = millis();
do {
timeBuzz = millis() - millisAwal;
recSMS();
//-------waktu lama buzzer ON 5 menit / 300000 mili detik
if (timeBuzz > 300000) {
keluar = 0;
}
}
while (keluar);
keluar = 1;
digitalWrite(buzzer, LOW);
lcd.clear();
}
else if (sensorON == true) {
lcd.setCursor(0, 3);
lcd.print(" Secure ");
}
}
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
stringComplete = 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. Ketika pertama kali dihidupkan.
4. LCD akan menunjukkan apakah sistem keamanan telah On atau Off.
5. Kirim SMS dengan format "ON" untuk menyalakan sistem keamanan, LED Indikator akan
menyala dan LCD akan menunjukkan informasi bahwa sistem keamanan telah ON.
6. Ketika salah satu sensor mendeteksi adanya sesuatu, misalkan sensor gas mendeteksi adanya gas,
maka LCD akan menunjukkan terdeteksi gas, buzzer akan berbunyi dan secara otomatis akan mengirimkan pesan ke nomor tertentu yang berisi bahwa telah terdeteksi gas.
7. Kirim SMS dengan format "ALARMOFF" untuk mematikan alarm yang selanjutnya akan mematikan
buzzer.
8. Kirim SMS dengan format "OFF" untuk mematikan sistem keamanan yang selanjutnya juga akan
mematikan LED Indikator.
Video untuk Project V - 9. Sistem Keamanan Rumah dengan 3 Sensor berbasis SMS menggunakan Arduino
KAMI MELAYANI JASA PEMBUATAN HARDWARE ATAU SOFTWARE BERBASIS ARDUINO
KONTAK KAMI 085743320570 (adi sanjaya)
No comments:
Post a Comment