How to use Arduino GSM shield to switch on appliances

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);

}

Are you asking for help with this ?

Can you also please edit it to use code blocks.

Cheers Pete.

Moderator:

  • moved this to exhibition as it is no Gig Question
  • added code tags
  • replaced capitals in title

(please follow the submission guidelines as that helps to get more feedback)

Fellow Arduinians,
I've been trying to find a way to actuate a code(or UNO) reset via sending a text to a GSM shield.

This is the ONLY info I can find; both online and in the forum.

Some details...

Built a water level alarm that texts me in the event of a high-water situation. It works great and saved my tush a couple of times.
HOWEVER, once it trips, I cannot reset it until I get home.
We have cats, and I know they explore the sump pump area and have caused some false alarms (buggers!)
The ability to text "reset" back to the GSM would allow me to know if it was indeed a false alarm. (would not repeat right away).

Using an UNO with GSM (SIM900) running on this code for now. And it works -shy of reset.

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
 
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
 
char sms_position;
char phone_number[20];
char sms_text[100];
int i;
int sumpPin = 7;
int auxPin = 9;
int LED1 = 5;       
int LED2 = 6;
int val = 0;     // variable for reading the pin status
 
void setup(){      //upon initialization do…
  
pinMode(sumpPin, INPUT);     // declare sump sensor as input
pinMode(auxPin, INPUT);     // declare aux sensor as input
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
    Serial.begin(9600);
        if (gsm.begin(9600)) 
    {
       (sms.SendSMS("17055072474", "Sump Alarm READY")); 
        Serial.println("Sump Alarm READY");
        started=true;       //this part works fine
    } 
    else 
        Serial.println("\nstatus=IDLE");
 
}
 void loop(){        
        val = digitalRead(sumpPin);
        if (val == HIGH){  // check if the input is HIGH
        delay(20);
        Serial.println("Sum Pin HIGH");
      }
          delay(1500);
        //Serial.println("Waited");
          
        if (val == LOW){ // if LOW, do nothing
        //Serial.println("Sump Pin LOW");
        }
        
        else if (val == HIGH) { // check if the input is still HIGH
        //Serial.println("Sump High Again");
        
        (sms.SendSMS("1705507xxxx", "***FLOOD ALARM***!!"));
        Serial.println("Flood Alarm!!");
        delay(1000);
        }

        while (val == HIGH){

  digitalWrite(LED1,HIGH); //L1 on
  digitalWrite(LED2,LOW); //L2 off
  delay(80); //Wait .08 second
 digitalWrite(LED1,LOW); //L1 off
  digitalWrite(LED2,HIGH); //L2 on
  delay(80); //Wait .08 second
}
 }

Any help on this would be greatly appreciated!
Once we have this going, I will share the full design, code and diagrams.

Thanks in advance!
Mike