About GSM Module
The GSM module that we are going to use here is SIM800L. It is compact and highly efficient as compared to other GSM modules. This type of module is used when you want to work on a cellular network using an Arduino. The SIM800L supports quadband frequencies of 850/900/1800/1900MH. By using this module you can easily transmit voice, send SMS, and access the Internet.
When you power up this module with a power supply of 3.8-4.2 Volts the LED present on the board will starts blinking. If it is blinking very fast that means SIM is not registered to any network. If it is blinking slowly then SIM has successfully logged in to the network. Make sure your power supply is of at least 2A as this module consumes lots of power.
Pin diagram of the SIM800L
Features of the SIM800L
- Input voltage: 3.8-4.2V
- Operating current: 2A
- Operating temperature: -40 to 85 degree Celsius
- Quad-band 850/900/1800/1900MHz
- GPRS class 12: max. 85.6 kbps (downlink/uplink)
- Interface: UART using AT commands
- SIM Type: MicroSIM
Components needed for this Project
- Arduino UNO
- SIM800L module
- 4.2V Li-Ion Cell
- 5V relay module
- Appliance
Working of Project
We will be using our mobile phone for sending a message to the GSM module. That message will contain a single alphabet. Suppose you have one appliance, then we will have one alphabet to turn ON the appliance and one alphabet to turn OFF the appliance. Let us suppose we are sending an alphabet”a” to turn ON the appliance and an alphabet “b” to turn OFF the appliance. Your appliance is connected to the Arduino board via a relay. Arduino will be continuously monitoring the data coming from the GSM module. If the GSM module receives a message that contains the alphabet “a” then Arduino will turn ON the Appliance by sending a signal to the relay module. If the GSM module receives a message that contains the alphabet “b” then Arduino will turn OFF the Appliance by sending a signal to the relay module.
Block diagram
Home Automation Circuit diagram
Arduino Code for Home Automation
Important note: Before uploading the code to the Arduino UNO board, make sure you have disconnected the RX and TX wire of the GSM module. After you have uploaded the code in the Arduino UNO board connect the RX and RX wire pf the GSM module to the Arduino UNO board.
int appliance1=2;
char gsmData;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(25000);
pinMode(appliance1,OUTPUT);
Serial.print("AT+CMGF=1\r");
delay(100);
Serial.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
digitalWrite(appliance1,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0)
{
gsmData=Serial.read();
if(gsmData=='a')
{
digitalWrite(appliance1,LOW);
}
else if(gsmData=='b')
{
digitalWrite(appliance1,HIGH);
}
}
Serial.print("AT+CMGD=1,4");
}
Working of code
int appliance1=2;
char gsmData;
Create a variable named appliance1 to store the pin number where you have connected the signal pin of the relay. Also, create another variable named gsmData to store the data received by Arduino from the GSM module.
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(25000);
pinMode(appliance1,OUTPUT);
In the void setup(), first set the baud rate for GSM that is 115200. Then give a large delay, so that the GSM module successfully gets logged in to the network. Then set the signal pin of the relay as input as Arduino will be using this pin to send a signal to the relay.
Serial.print("AT+CMGF=1\r");
delay(100);
Serial.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
Using AT+CMGF=1 command, set the SMS mode in text. Then give a delay of 100 milliseconds. After that using AT+CNMI=2,2,0,0,0 command, send content of SMS to the serial port.
digitalWrite(appliance1,HIGH);
Send logic HIGH to the signal pin of the relay module to initially turned it OFF.
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0)
{
gsmData=Serial.read();
In the void loop(), first check whether the serial communication is available or not by using the available() command. After that store the data from the GSM module into the variable gsmData.
if(gsmData=='a')
{
digitalWrite(appliance1,LOW);
}
else if(gsmData=='b')
{
digitalWrite(appliance1,HIGH);
}
}
Using the if else-if statement check the GSM data. If data is equal to “a”, turn ON the relay module. If data is equal to “b”, turn OFF the relay module.
Serial.print("AT+CMGD=1,4");
Comments are closed.