Turn ON OFF LEDs using Arduino uno and GSM 900A Module with acknowledgment

Turn ON OFF LEDs using Arduino uno and GSM 900A Module with acknowledgment 


This article will explain about how to turn ON/OFF LEDs suing Arduino and Board GSM Module and Working SIM to receive messages; LED Light ... Instead of LEDs (5V), we can control AC appliances using relay connecting with ARDUINO
+

You can also use breadboard
+

Connections

GSM900A + Arduino uno
GND to GND
TXD to 8
RXD to 9

RelayModule + Arduino uno 

GND to GND
IN1 to 2 
VCC to 5V 

Code

#include <SoftwareSerial.h> //software serial library for serial communication b/w arduino & GSM
SoftwareSerial mySerial(8, 9);//connect Tx pin of GSM to pin 8 of arduino && Rx pin of GSM to pin no 9 of arduino

int led = 2;
String message;
String number;

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);

  mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
  
  pinMode(led,OUTPUT);
  digitalWrite(led,LOW);
  
}

void loop()
{
  if (mySerial.available()>0){ 
  message = mySerial.readString();
  }

  if(message.indexOf("ON") > -1){
     Serial.println("LED ON");
     digitalWrite(led,HIGH);
     SendMessage("ON");
     }
    else if(message.indexOf("OFF") > -1){
     Serial.println("LED OFF");
     digitalWrite(led,LOW);
     SendMessage("OFF");
  }

  delay(10);
}

void SendMessage(String status)
{
  Serial.println("SendMessage:"+status);
  mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
  delay(1000); // Delay of 1000 milli seconds or 1 second
  Serial.println("message: "+message);
  number = message.substring(12, 22); // If (12, 22) not work you can try to use (9, 22) 
  mySerial.println("AT+CMGS=\"+number+\"\r"); 
  delay(1000);
  mySerial.println("GSM Module Status:"+status);// The SMS text you want to send
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}

Note

You don't change the code and you can send sms your mobile phone to gsm sim card number and led switch on or off. The command on or off is send sms in a capital letter ON or OFF. And your mobile phone receive the acknowledgment of led on or off.

No comments

Powered by Blogger.