Introduction: Interfacing the GSM and Arduino Uno to Controll the AC Bulb Through SMS

{"context":{"location":{"href":"","origin":"","protocol":"https:","host":"","hostname":"","port":"","pathname":"/editInstructable/publish/E3QD0YHJIKJPZHO","search":"","hash":""},"jQuery110208897716611280887":1,"b":{"jQuery110208897716611280887":20,"sizzle-1529407068425":{"parentNode":["20722 284",200]}},"h":{}},"selector":"#editor-Object-414"}

Step 1: Components Required:

- Arduino board 1

- GSM Module (SIM900A) 1

- Few jumper wires

- Bread board 1

- 512v single channel Relay 1

You can buy these products on elegocart.

Step 2: Project Setup:

Step 3: Code:

#include SoftwareSerial SIM900(7, 8); String textMessage; String lampState = "HIGH"; // Relay connected to pin 3 const int relay = 3; void setup() { // Automatically turn on the shield digitalWrite(9, HIGH); delay(1000); digitalWrite(9, LOW); delay(5000); // Set relay as OUTPUT pinMode(relay, OUTPUT); // By default the relay is off digitalWrite(relay, LOW ); // Initializing serial commmunication Serial.begin(9600); SIM900.begin(9600); // Give time to your GSM shield log on to network delay(10000); Serial.print("SIM900 is ready to send receive sms"); // AT command to set SIM900 to SMS mode SIM900.print("AT+CMGF=1\r"); delay(100); // Set module to send SMS data to serial out upon receipt SIM900.print("AT+CNMI=2,2,0,0,0\r"); delay(100); } void loop(){ if(SIM900.available()>0){ textMessage = SIM900.readString(); Serial.print(textMessage); delay(10); } if(textMessage.indexOf("LED ON")>=0){ // Turn on relay and save current state digitalWrite(relay, HIGH); lampState = "on"; Serial.println("Relay set to ON"); textMessage = ""; } if(textMessage.indexOf("LED OFF")>=0){ // Turn off relay and save current state digitalWrite(relay, LOW); lampState = "off"; Serial.println("Relay set to OFF"); textMessage = ""; } if(textMessage.indexOf("STATE")>=0){ String message = "Lamp is " + lampState; sendSMS(message); Serial.println("Lamp state resquest"); textMessage = ""; } } // Function that sends SMS void sendSMS(String message){ // AT command to set SIM900 to SMS mode SIM900.print("AT+CMGF=1\r"); delay(100); // change to your sim900's your phone number SIM900.println("AT + CMGS = \"9901xxxxxx\""); delay(100); // Send the SMS SIM900.println(message); delay(100); // End AT command with a ^Z, ASCII code 26 SIM900.println((char)26); delay(100); SIM900.println(); // Give module time to send SMS delay(5000); }