GSM Home automation using GSM900A with Arduino

GSM Home automation using GSM900A with Arduino

C++
//Programmed by KAVIKUMARAN G 
//Electrical and Electronics Engineering 

// Visit : Pickupmyskills.com

#include <SoftwareSerial.h>

SoftwareSerial SIM900(2, 3); // RX, TX pins

const int relay1 = 11; 
const int relay2 = 12;

String message = "";

void setup() {

  Serial.begin(9600);

  SIM900.begin(9600);
  delay(500);
  
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);

  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);

  SIM900.println("AT");
  delay(500);

  
  SIM900.println("AT+CMGF=1");
  delay(500);
    Serial.print("GSM Ready");

sendSMS("GSM Ready");
}

void loop() {

  if (SIM900.available()) {
    message = SIM900.readString(); 

    Serial.println("Received Message: ");
    Serial.println(message);

    
    if (message.indexOf("ON1") >= 0) {
      digitalWrite(relay1, HIGH);
      sendSMS(" turned ON");
    } else if (message.indexOf("OFF1") >= 0) {
      digitalWrite(relay1, LOW); 
      sendSMS(" turned OFF");
    }

    if (message.indexOf("ON2") >= 0) {
      digitalWrite(relay2, HIGH); 
      sendSMS(" turned ON");
    } else if (message.indexOf("OFF2") >= 0) {
      digitalWrite(relay2, LOW); 
      sendSMS(" turned OFF");
    }
    message = "";
  }
}


void sendSMS(String text) {
  SIM900.println("AT+CMGF=1");  
  delay(500);
  SIM900.println("AT+CMGS=\"+91xxxxxxxxxx\""); // Replace XX with receiver  mobile number.
  delay(500);
  SIM900.print(text); 
  delay(500);
  SIM900.write(26); 
  delay(500);
}

Leave a Comment

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

Scroll to Top