close
KnowledgeBase

Wireless Lamp Control using SIM800C GSM Module, Arduino Uno and DC Relay Module

31381156_2052107128136008_8604490030007713792_n

Overview

GSM, or Global System for Mobile Communications, is the most popular cell phone standard in the world. This system operates in almost 200 countries. It is considered as the default global standard. In this project, the SIM800C is used to control the state of the lamp. The SIM800L is a cheap and compact GSM module. This module can perform the processes of larger GSM modules, with minimal space and requirements. On the other hand, a relay module is a type of switch that operates both electrically and mechanically. A relay module can switch the mains voltage.

Hardware Used

Software Used

  • Arduino IDE
  • Mobile Phone Messaging Application

Libraries Used

  • SoftwareSerial.h

Application Description

The SIM800C module uses GSM and GPRS (General Packet Radio Service) to send and receive data from mobile devices. In this project, the SIM800C uses GSM to transmit data through texting or SMS. The data is then used by the Arduino to control the switch of the relay, which turns the lamp on or off.

Set-up the Hardware

Figure 1 – Schematic Diagram

 

Figure 2 – SIM800C front view

Figure 3 – SIM800C back view

This project follows the schematic diagram shown in Figure 1. The Arduino pins 9 and 10 both represent the RX and TX pins needed for data transmission to the SIM800C module. Note that the connections of the RX and TX pins of the Arduino Uno and the SIM800C module are interconnected. The RX pin of the Arduino and the TX pin of the SIM800C module are connected, and the TX pin of the Arduino and the RX pin of the SIM800C module are also connected.

Also, this project uses a 5V DC relay module. Connecting the relay to the lamp is achieved by soldering the wires. Soldering the connections is a must since the breadboard cannot handle the mains voltage of 220V AC. However, jumper wires may be used to connect the pins of the relay module (VCC, GND, IN) to the Arduino Uno.

Set-up the Software

The code used in this project is shown above. To further understand the code shown above, this tutorial will explain the processes of the code per part, starting with the declaration of variables.

The code shown above is its first part, which is the declaration and initialization of variables. Also, this is where the library SoftwareSerial is included in the code. The SoftwareSerial library is used to incorporate serial communication onto the different pins of the Arduino Uno rather than using pins 0 and 1 for serial communication. Serial communication is a type of communication wherein data is transmitted and received using a communication channel one bit at a time.

To use the different pins of the Arduino Uno as the RX and TX pins of the serial communication, the Arduino pins must be declared. The second line of the code shown above states pins 9 and 10 as the RX and TX pins.

The next portion of the code is the declaration of variables needed. Declaring variables is a vital task when programming since this is where the data type of the variables are first indicated.

Lastly, the initialization of variables was created. This is where the variables first acquired their initial values. Their values may change as the code progresses.

The second part of the code is the setup function. This is where the different Arduino pins needed are assigned as either inputs or outputs. Also, this is where the baud rate is defined in both the hardware and software serial communication. Baud rate is defined as the rate of transfer of information in a communication channel. In this project, a baud rate of 9600 is used. This means that the serial port is capable of sending and receiving a maximum of 9600 bits per second.

Also, this project uses the AT commands of the SIM800C module for it to work as it is expected to. AT commands are instructions or directions needed to control a modem or module to perform a set of operations. In this case, the module should read messages, receive messages, and set its mode to SMS text.

The third part of the code is the loop function. This is where the Arduino does its processes and repeats it continuously. The first main portion of the loop function is the if-statement which checks the availability of the connections between the SIM800C and the Arduino Uno.  Once the connection is available, the loop function uses another if-else statement to receive the message. Lastly, another if-statement and an AT command are used to delete messages to save memory.

The fourth and last part of the code is the receivedMessage() function. This is where the Arduino compares the received SMS to perform a task. In this case, the function gets the number and the message. The message is then compared using if-statements.

When the message contains the word “ON,” the Arduino gives a high signal to the relay. This, in turn, allows the relay to switch and allows current to flow through, which turns on the lamp. On the other hand, the Arduino gives a low signal to the relay module once the compared message contains the word “OFF.” This turns off the lamp.

Conclusion

The SIM800C GSM module is not only limited to turning off lamps or switching relays. This is just an introduction to the capabilities of the said module. It is always up to you to mess around. The sky is the limit!

References

Tags : arduinoautomationcellulardc relayGPRSGSMrelaySIM800Csoftwareserial

Leave a Response