hi guys, here is my code to automatically switch on/ off AC appliances at home,. here the code u can ttry it . things needed are : Arduino uno, arduino Gsm shield, Relay shield, Bulb AND FAN
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;
char remoteNumber[20]; // Holds the emitting number
// Pin 13 has an bulb connected on most Arduino boards.
// give it a name:
int bulb = 13;
int fan = 10;
void setup()
{
// initialize serial communications
Serial.begin(9600);
Serial.println("SMS Messages Receiver");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
// initialize the digital pin as an output.
pinMode(bulb, OUTPUT);
pinMode(fan, OUTPUT);
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
digitalWrite(bulb, HIGH); // turn the bulb off (HIGH is the voltage level)
digitalWrite(fan, HIGH); // turn the fan off (HIGH is the voltage level)
}
void loop()
{
char c;
//digitalWrite(bulb, LOW); // turn the bulb on by making the voltage LOW
// If there are any SMSs available()
if (sms.available())
{
Serial.println("Message received from:");
// Get remote number
sms.remoteNumber(remoteNumber, 20);
Serial.println(remoteNumber);
// This is just an example of message disposal
// Messages starting with # should be discarded
if(sms.peek()=='#')
{
Serial.println("Discarded SMS");
sms.flush();
}
// Read message bytes and print them
while(c=sms.read()){
Serial.print(c);
if(c == '1'){
Serial.println("\n Switch on device ONE.");
digitalWrite(bulb, HIGH); // turn the bulb off (HIGH is the voltage level)
delay(5000);
}
else if(c == '4'){
digitalWrite(bulb, LOW); // turn the bulb on (HIGH is the voltage level)
}
if(c == '2'){
Serial.println("\n Switch on device ONE.");
digitalWrite(fan, HIGH); // turn the fan off (HIGH is the voltage level)
delay(5000);
}
else if(c == '5'){
digitalWrite(fan, LOW); // turn the bulb on (HIGH is the voltage level)
}
}
Serial.println("\nEND OF MESSAGE");
// delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
}
delay(1000);
}
