GSM SIM900 Module Control relay

Wiring all same previous blog just add relay module

Connect 4 Relays module to Arduino Board

Wiring

4 Relays module     to       Board Arduino

Vcc                                     5 Volt

IN1                                     Pin 4

IN2                                     Pin 5

IN3                                     Pin 6

IN4                                     Pin 7

GND                                   GND

Concept

Idea

Send sms

a1  relay  IN1 on

a?  relay  IN1 off

b1  relay  IN2 on

b?  relay  IN2 off

c1  relay  IN3 on

c?  relay  IN3 off

d1  relay  IN4 on

d?  relay  IN4 off

x1  All relay  on

x?  All relay  off

Library

https://drive.google.com/open?id=1MwINDk0QBViC31dtLt47_aGRQZvwQkhq

VDO

 

Code

#include "SIM900.h"

#include <SoftwareSerial.h>

//If not used, is better to exclude the HTTP library,

//for RAM saving.

//If your sketch reboots itself proprably you have finished,

//your memory available.

//#include "inetGSM.h"

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.

#include "sms.h"

SMSGSM sms;

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino

//www.open-electronics.org

//this code is based on the example of Arduino Labs.

//Simple sketch to send and receive SMS.

int numdata;

boolean started=false;

char smsbuffer[160];

char n[20];

void setup()

{

  pinMode(4, OUTPUT);

  pinMode(5, OUTPUT);

  pinMode(6, OUTPUT);

  pinMode(7, OUTPUT);

  digitalWrite(4, HIGH);

  digitalWrite(5, HIGH);

  digitalWrite(6, HIGH);

  digitalWrite(7, HIGH);

     //Serial connection.

     Serial.begin(9600);

     Serial.println("GSM Shield testing.");

     //Start configuration of shield with baudrate.

     //For http uses is raccomanded to use 4800 or slower.

     if (gsm.begin(2400)) {

          Serial.println("\nstatus=READY");

          started=true;

     } else Serial.println("\nstatus=IDLE");

     

     if(started) {

          //Enable this two lines if you want to send an SMS.

          if (sms.SendSMS("your phone number", "GSM SmartHome"))

          Serial.println("\nSMS sent OK");

     }

};

void loop()

{

     if(started) {

      

          //Read if there are messages on SIM card and print them.

          if(gsm.readSMS(smsbuffer, 160, n, 20)) {

            

               Serial.println(n);  //Print out phone number

               Serial.println(smsbuffer); // Text 

              char* ptr = smsbuffer;

  while ( strlen(ptr) >= 2 ) {

    if ( ptr[0] == 'a' ) {

      if ( ptr[1] == '1' )

        digitalWrite(4, LOW);

      else

        digitalWrite(4, HIGH);

    }

    if ( ptr[0] == 'b' ) {

      if ( ptr[1] == '1' )

        digitalWrite(5, LOW);

      else

        digitalWrite(5, HIGH);

    }

     if ( ptr[0] == 'c' ) {

      if ( ptr[1] == '1' )

        digitalWrite(6, LOW);

      else

        digitalWrite(6, HIGH);

    }

    if ( ptr[0] == 'd' ) {

      if ( ptr[1] == '1' )

        digitalWrite(7, LOW );

      else

        digitalWrite(7, HIGH);

    }

     if ( ptr[0] == 'x') {

      if ( ptr[1] == '1'){

        digitalWrite(4,LOW);

        digitalWrite(5,LOW);

        digitalWrite(6,LOW);

        digitalWrite(7,LOW);}

         

     else

     {

        digitalWrite(4,HIGH);

        digitalWrite(5,HIGH);

        digitalWrite(6,HIGH);

        digitalWrite(7,HIGH);

      }

     }

    

  

    ptr += 2;

  }

          }

          delay(1000);

     }

};