Turn the lights on and off via SMS. Working system of this tool if you want to turn the lights no.1 just enough SMS "1 on" then light no.1 turns on if you want to turn off enough SMS "1 off". Because SMS-based devices can be controlled remotely, as long as there are signals and bandwidth data. Arduino UNO as its data processor.
Hardware Requirement
- Arduino Uno Board
- 2 Channel of Relay
- SIM900A GSM Module (you can also use Wavecom)
- LCD 16*2 or 20*4 (with i2c connection is recomended)
- Power supply +5 Volt
- Jumper
Block Diagram
Schematic (Wavecom)
If using SIM900A, then no RS232 circuit, just connect to Arduino.
Arduino - LCD 16x2
Arduino LCD 20x4
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 - Relay
Arduino - Wavecom GSM Module
If using SIM900A then its wiring is as follows
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="";
char str,f;
int i,j;
void setup(){
gsm.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.print("Tes Koneksi...");
delay(1000);
gsm.println("AT");
getmodem();
getmodem();
lcd.setCursor(0, 1);
lcd.print(inString);
delay(2000);
//--------------------------dig output Relay
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
digitalWrite(A0, 0);
digitalWrite(A1, 0);
}
//============================================program utama
void loop() {
lcd.begin(16,2);
lcd.print("Kontrol 2 Relay");
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();
lcd.setCursor(0,1);
lcd.print(inString2);
//-------------------------isi SMS "1 on"
if(inString2=="1 on"){
digitalWrite(A0,1);
delay(2000);
}
//-------------------------isi SMS "2 on"
else if(inString2=="2 on"){
digitalWrite(A1,1);
delay(2000);
}
//-------------------------isi SMS "1 off"
else if(inString2=="1 off"){
digitalWrite(A0,0);
delay(2000);
}
//-------------------------isi SMS "2 off"
else if(inString2=="2 off"){
digitalWrite(A1,0);
delay(2000);
}
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;
}
}
}
}
#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="";
char str,f;
int i,j;
void setup(){
gsm.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.print("Tes Koneksi...");
delay(1000);
gsm.println("AT");
getmodem();
getmodem();
lcd.setCursor(0, 1);
lcd.print(inString);
delay(2000);
//--------------------------dig output Relay
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
digitalWrite(A0, 0);
digitalWrite(A1, 0);
}
//============================================program utama
void loop() {
lcd.begin(16,2);
lcd.print("Kontrol 2 Relay");
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();
lcd.setCursor(0,1);
lcd.print(inString2);
//-------------------------isi SMS "1 on"
if(inString2=="1 on"){
digitalWrite(A0,1);
delay(2000);
}
//-------------------------isi SMS "2 on"
else if(inString2=="2 on"){
digitalWrite(A1,1);
delay(2000);
}
//-------------------------isi SMS "1 off"
else if(inString2=="1 off"){
digitalWrite(A0,0);
delay(2000);
}
//-------------------------isi SMS "2 off"
else if(inString2=="2 off"){
digitalWrite(A1,0);
delay(2000);
}
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;
}
}
}
}
Source Code --> SIM900A
#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 "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];
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);
digitalWrite(A0, 0);
digitalWrite(A1, 0);
}
//============================================program utama
void loop() {
lcd.setCursor(0, 0);
lcd.print(" Remote 2 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);
}
else if (String(message) == "2 on") {
lcd.setCursor(0, 3);
lcd.print(" Relay 2 On");
digitalWrite(A1, 0);
delay(2000);
}
//-------------------------isi SMS "1 off"
else if (String(message) == "1 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 1 Off");
digitalWrite(A0, 1);
delay(2000);
}
//-------------------------isi SMS "2 off"
else if (String(message) == "2 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 2 Off");
digitalWrite(A1, 1);
delay(2000);
}
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 "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];
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);
digitalWrite(A0, 0);
digitalWrite(A1, 0);
}
//============================================program utama
void loop() {
lcd.setCursor(0, 0);
lcd.print(" Remote 2 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);
}
else if (String(message) == "2 on") {
lcd.setCursor(0, 3);
lcd.print(" Relay 2 On");
digitalWrite(A1, 0);
delay(2000);
}
//-------------------------isi SMS "1 off"
else if (String(message) == "1 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 1 Off");
digitalWrite(A0, 1);
delay(2000);
}
//-------------------------isi SMS "2 off"
else if (String(message) == "2 off") {
lcd.setCursor(0, 3);
lcd.print(" Relay 2 Off");
digitalWrite(A1, 1);
delay(2000);
}
delay(3000);
lcd.clear();
}
}
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 with the correct format, then LCD will display it.
7. After sending SMS message, lcd will return to normal view.
Video for Project III - 3. Controlling 2 Channel Relay using SMS Method based on Arduino
Required file
No comments:
Post a Comment