Hi,
I would like to find out how do I send the state of an LED in arduino via an SMS. So if the LED is ON I want to send and SMS saying the LED is ON and when Its OFF I want to send an SMS saying the LED is OFF. This is my code I have:
Any type of help will be appreciated.
[code][code]#include <SoftwareSerial.h>
SoftwareSerial SIM900(2, 3); // RX, TX
char incoming_char=0; //Will hold the incoming character from the Serial Port.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
int led_status = 0; // variable to store the led status
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
Serial.begin(19200); // set the baud rate
SIM900.begin(19200); // for GSM shield
delay(20000); // give time to log on to network.
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
SIM900.println("AT+CNMI=2,2,0,0,0\r");
SIM900.print("AT+CLIP=1\r"); // turn on caller ID notification
// blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
digitalWrite(led, LOW); // Set led to LOW
// Serial.println("AT+CMGD=1,4"); //Delete all SMS in box
}
void sendSMS(char led_status){ //SEND SMS
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(1000);
SIM900.println("AT + CMGS = \"+2772XXXXXXX\""); // recipient's mobile number, in international format
delay(1000);
SIM900.println( " LED STATUS: ON "); // message to send
delay(1000);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(1000);
SIM900.println();
delay(5000); // give module time to send SMS
}
// the loop routine runs over and over again forever:
void loop() {
//If #a1b1c1d1 comes as sms, all led's should light up.
if(SIM900.available() >0)
{
incoming_char=SIM900.read();
if (incoming_char=='#')
{
delay(10);
incoming_char=SIM900.read();
//first led
if (incoming_char=='a')
{
delay(10);
incoming_char=SIM900.read();
if (incoming_char=='0')
{
digitalWrite(led, LOW);
}
else if (incoming_char=='1')
{
digitalWrite(led, HIGH);
}
else if (incoming_char=='S')
{
digitalRead(led);
led_status=digitalRead(led);
Serial.print(led_status); // prints status on serial terminal
sendSMS(led_status);
}
delay(10);
}
}
}
}
[/code][/code]