Skip to content

Instantly share code, notes, and snippets.

@arn-ob
Last active March 26, 2018 14:37
Show Gist options
  • Select an option

  • Save arn-ob/722f52dba78732697dd7065d073e1c2c to your computer and use it in GitHub Desktop.

Select an option

Save arn-ob/722f52dba78732697dd7065d073e1c2c to your computer and use it in GitHub Desktop.
Remote Control Relay By GSM
// include the library code:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
// SoftwareSerial SIM900(11, 10); // RX, TX
SoftwareSerial SIM900(3, 2); // RX, TX
char msg;
//const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
SIM900.begin(9600);
Serial.println("GSM SIM900A BEGIN");
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Project");
pinMode(7, OUTPUT); // Fan 1
pinMode(6, OUTPUT); // Fan 2
pinMode(5, OUTPUT); // Light 1
pinMode(4, OUTPUT); // Light 2
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
if (SIM900.available() > 0)
{
if (msg == 'F') {
msg = SIM900.read();
if (msg == 'A') {
msg = SIM900.read();
if (msg == 'N') {
msg = SIM900.read();
if (msg == '1') {
msg = SIM900.read();
if (msg == '_') {
msg = SIM900.read();
if (msg == 'O') {
msg = SIM900.read();
if (msg == 'N') {
Serial.println("Fan_1 ON");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("Demo");
lcd.setCursor(0, 1);
lcd.print("Fan_1 ON");
delay(10);
digitalWrite(7, HIGH);
delay(5);
}
if (msg == 'F') {
msg = SIM900.read();
if (msg == 'F') {
Serial.println("Fan_1 OFF");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("Demo");
lcd.setCursor(0, 1);
lcd.print("Fan_2 OFF");
delay(10);
digitalWrite(7, LOW);
delay(5);
}
}
}
}
}
if (msg == '2') {
msg = SIM900.read();
if (msg == '_') {
msg = SIM900.read();
if (msg == 'O') {
msg = SIM900.read();
if (msg == 'N') {
Serial.println("Fan_2 ON");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("Demo");
lcd.setCursor(0, 1);
lcd.print("Fan_2 ON");
delay(10);
digitalWrite(6, HIGH);
delay(5);
}
if (msg == 'F') {
msg = SIM900.read();
if (msg == 'F') {
Serial.println("Fan_2 OFF");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("Demo");
lcd.setCursor(0, 1);
lcd.print("Fan_2 OFF");
delay(10);
digitalWrite(6, LOW);
delay(5);
}
}
}
}
}
}
}
}
if (msg == 'L') {
msg = SIM900.read();
if (msg == 'I') {
msg = SIM900.read();
if (msg == 'T') {
msg = SIM900.read();
if (msg == '1') {
msg = SIM900.read();
if (msg == '_') {
msg = SIM900.read();
if (msg == 'O') {
msg = SIM900.read();
if (msg == 'N') {
Serial.println("LIT_1 ON");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("Demo");
lcd.setCursor(0, 1);
lcd.print("LIT_1 ON");
delay(10);
digitalWrite(5, HIGH);
delay(5);
}
if (msg == 'F') {
msg = SIM900.read();
if (msg == 'F') {
Serial.println("LIT_1 OFF");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("Demo");
lcd.setCursor(0, 1);
lcd.print("LIT_1 OFF");
delay(10);
digitalWrite(5, LOW);
delay(5);
}
}
}
}
}
if (msg == '2') {
msg = SIM900.read();
if (msg == '_') {
msg = SIM900.read();
if (msg == 'O') {
msg = SIM900.read();
if (msg == 'N') {
Serial.println("LIT_2 ON");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("Demo");
lcd.setCursor(0, 1);
lcd.print("LIT_2 ON");
delay(10);
digitalWrite(4, HIGH);
delay(5);
}
if (msg == 'F') {
msg = SIM900.read();
if (msg == 'F') {
Serial.println("LIT_2 OFF");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("Demo");
lcd.setCursor(0, 1);
lcd.print("LIT_2 OFF");
delay(10);
digitalWrite(4, LOW);
delay(5);
}
}
}
}
}
}
}
}
msg = SIM900.read();
//Serial.print(msg);
delay(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment