SMS Controlled Relay with PIC Microcontroller- MikroC

SMS Controlled Relay with PIC Microcontroller- MikroC

Figure 1: SMS Controlled Security Access Control Boom Gate

Remotely controlled and monitored systems are becoming increasingly popular these days. Smart controlled devices, such as SMS vending machines, parking ticket payment stations, home automation, security access controls are becoming part of our everyday lives.

In this project we are going to learn how  to control a relay with an SMS. This relay could be used in many applications to Switch ON or OFF devices such as an electric bulb, or opening a security boom gate like in this example. A security access control can be implemented at apartments or housing complexes, when a visitor arrives at the gate, he/she can phone the visited person who can send an SMS: “OPEN” to the gate cellphone number, upon receiving this message from the GSM module, the PIC will trigger the relay to open the gate and then close automatically the gate after a short delay or after the car has entered the into the housing complex (Infrared beam detectors could be used to detect if a car has passed the gate).

In this project we are going to use a GSM modem, a PIC microcontroller and a relay.

A GSM modem is a wireless modem that works with a GSM wireless network. GSM stands for Global System for Mobile communications, this architecture is used for mobile communication in most of the countries in the world. 

A wireless modem acts basically like the traditional dial-up modem, the main difference is that a dial-up modem sends and receives data through a fixed telephone line while a wireless modem sends and receives data through radio waves. Besides the dial-up connection, GSM modem can also be used for sending and receiving SMS which is also one of the key features of GSM modem.

To learn more about interfacing GSM modem with PIC microcontrollers, please read more the article:

Interfacing GSM/GPRS Modem with PIC Microcontroller

To learn more about interfacing a Relay with PIC microcontrollers, please read more the article:

Interfacing a Relay with PIC Microcontroller

Circuit Diagram

Figure 2: SMS Controlled Relay with PIC Microcontroller

Buy GSM Modem, PIC, Development board, Relay, Accessories from our Online Store


If you would like to build this project as a prototype for your soon to be improved project, we would advise to create a PCB for this project as you won’t be able to work well with relays on a breadboard, you don’t have to worry about the cost even if you are a student or with limited budget, these days it’s really cheaper to get quality professional PCB or PCB SMD component assembly relatively cheap.

There are many PCB companies in the world that can make you good quality PCBs, One of those companies we can recommend is PCBWay a china based PCB manufacturer specializing in PCB prototyping, small volume production and PCB assembly service all under one roof with more than a decade of experience.

They are now running an unbelievable SMD component assembly for only $30 USD this is for 1-20pcs plus free shipping worldwide!!!

You won’t get this offer anywhere with great SMT quality, so try them and verify their SMT services quality, maybe they could become your future partner with your prototyping. They produce also PCBs of great quality from only $5 USD for 10 pcs 1-2 layers.

To find out more about this great offer or to learn more about their services, please click on the image below:

MikroC Code

In this project, we are going to receive an SMS by using the Polled Response. In this mode, an AT command is sent t the modem to list any new Unread messages instead of getting a notification from the modem:

If we assume that there is only one unread message, the modem may respond:

1 is the index number. After receiving, we could delete all messages from the memory to be ready to receive new messages.

We are going to enable to UART interrupts so that when a character is received from the modem the program jumps straight to the interrupt service routine.

This code just demonstrate the basics of receiving an SMS then control a relay, there are many ways we could improve this code:

  • We could improve this by instead of sending a new SMS to close the gate, we could simply use a short delay like 10 seconds to close the gate automatically or even use infrared beam detectors to detect the presence of a car and only close the gate automatically once the car enters the area.
  • Add a send function to send to the user the status of the gate. gate open or closed to make sure the command was executed
  • Check the telephone number of the sender to make sure only numbers from authorized users can open the gate.

Share this post

has been added to your cart:
Select your currency