Arduino projectsUncategorized

Arduino SIM900A Home Automation

Arduino SIM900A GSM Based Home Automation System

Hey, folks. In this tutorial, we are going to make a GSM Based Home Automation System using SIM900A module. Whenever an SMS is sent to the GSM, it forwards that to microcontroller i.e. Arduino and thereafter according to the message decoded Arduino triggers the respective relays. The project is very straightforward and takes less than 10 minutes to make.

 List of the items required for this project :

  • GSM/GPRS Module ( Here, we are using SIM900A)
  • Arduino Uno
  • 2G Sim Card
  • Jumper Wires
  • Relays ( for controlling the AC appliances )
  • Few connectors/jumper wires
Note : For demonstration, we are using LEDs instead of Relay but the whole process
 remains the same .

 

Why SIM900A?

SIM900A works on frequencies 900/ 1800 MHz and it generally comes with RS232 interface, which allows us to connect microcontroller as well as PC with RS232 Chip(MAX232). There are other modular versions that have the different set of hardware architecture but all work the same ways. Baud rate can be configurable from 9600-115200 using AT command. The GSM/GPRS Modem have internal TCP/IP stack which enables us to connect with internet via GPRS. Thus, it is suitable for SMS, Voice as well as DATA transfer application in M2M interface.

Note: You can choose other GSM modules too and also the code and connection of 
pins will  work fine for that particular module too.

Since GSM modules are manufactured by different vendors. So, they all have work on different input power supply. So, before using one blindly it is recommended to double check the GSM modules power requirements. Here, our gsm module requires a 12 volts input, so we supplying 12V,1A DC power to it. Some GSM modules require 15 volts and some other needs only 5 volts. In that cases, we can power it directly from Arduino’s 5V out.

Guide on Booting GSM module:

1. Insert the SIM card to the module and lock it properly in position.

2. Connect the power adapter to the module and turn it ON!

3. Now wait for few seconds (say around 60sec) and see the blinking rate of ‘status LED’ (GSM module will take some time to establish a connection with the mobile network)

4. Once the connection is established successfully, the status LED will blink continuously every 2sec (or 3sec).

Here, is the flow diagram of the project that shows how the whole system works-Whenever an SMS is sent to the GSM, it forwards that to microcontroller i.e. Arduino and thereafter according to the message decoded Arduino triggers the respective relays.

Connection:

Sim900A GSM module’s Tx and Rx pins to Arduino Rx and Tx respectively.

Common the Ground(GND) of both Arduino and Sim900A GSM Module

LEDs to Pin 10,11 and 12 of Arduino. ( In place of LEDs you can use Relays for Switching the AC Appliances using SMS via GSM module)

Code :

Initialising Pins for Relays/LEDs and setting their PinMode:

const int red = 12;
const int green = 11;
const int blue = 10;
void setup() {
   // Set leds as OUTPUT
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);

  // By default the leds is off i.e LOW but for RELAYs this pin needs to be in HIGH State
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
...
}

AT command to set SIM900 to SMS mode:

Serial.print("AT+CMGF=1\r");

 

Full Code :

// This Code is written by Ashish Maurya in collaboration with Roboshala (https://www.roboshala.com)
// Variable to store text message
String textMessage;

const int red = 12;
const int green = 11;
const int blue = 10;


void setup() {
   // Set leds as OUTPUT
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);

  // By default the leds is off
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  
  // Initializing serial commmunication
  Serial.begin(19200); 
  

  // Give time to your GSM shield log on to network
  delay(20000);

  // AT command to set SIM900 to SMS mode
  Serial.print("AT+CMGF=1\r"); 
  delay(100);
}

void loop(){
  if(Serial.available()>0){
    textMessage = Serial.readString();
   textMessage.toUpperCase();   
    delay(10);
  } 
  if(textMessage.indexOf("REDON")>=0){
    // Turn on red
    digitalWrite(red, HIGH);  
    textMessage = "";   
  }
  if(textMessage.indexOf("REDOFF")>=0){
    // Turn off red
    digitalWrite(red, LOW);
    textMessage = ""; 
  }
  if(textMessage.indexOf("GREENON")>=0){
    // Turn on green
    digitalWrite(green, HIGH);  
    textMessage = "";   
  }
  if(textMessage.indexOf("GREENOFF")>=0){
    // Turn off green
    digitalWrite(green, LOW);
    textMessage = ""; 
  }
  if(textMessage.indexOf("BLUEON")>=0){
    // Turn on blue 
    digitalWrite(blue, HIGH); 
    textMessage = "";   
  }
  if(textMessage.indexOf("BLUEOFF")>=0){
    // Turn off Blue 
    digitalWrite(blue, LOW);
    textMessage = ""; 
  }
   if(textMessage.indexOf("ALLON")>=0){
    // Turn on all leds
    digitalWrite(blue, HIGH);
    digitalWrite(green, HIGH); 
    digitalWrite(red, HIGH);  
    textMessage = "";   
  }
  if(textMessage.indexOf("ALLOFF")>=0){
    // Turn off all leds
    digitalWrite(blue, LOW);
    digitalWrite(red, LOW);
    digitalWrite(green, LOW);
    textMessage = ""; 
  }
}  



Download Code Directly:  Sharing is Caring!

Also, Check other GSM Projects

GSM Based Notice Board using Arduino and SIM900A

Phone Call Automation using DTMF Decoder

Tags
Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close