Control an LED from anywhere via your phone!📲

It matters a lot if your Arduino supports a phone chip. It may be used in a variety of applications, such as security systems to send alerts when anything goes wrong or to control devices from anywhere in the world via text messages.


The SIM900 GSM module enables you to provide your Arduino with a SIM card to work like a cell phone!


Overview


In this tutorial we will control a small LED by sending a text message from your phone to the Arduino via the SIM900 GSM Shield.


You will be able to turn the LED on and off, and you can replace this project with other great ideas like controlling a small pump to water the tree in your house garden while you are on vacation in another country!


Let’s find out more together!


Getting the items


For this project you will need the following components you can buy them from our store. 

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat SIM900 GSM Shield for Arduino
79 QAR
Sale Off
Voltaat Half-size Breadboard
15 QAR

Make sure you also have a breadboard and jumper wires to connect everything together

Sale Off
Voltaat Red 3mm LED (5 pack)
1 QAR
Sale Off
Voltaat 1/4 Watt Resistor (20 Pack)
2 QAR
Sale Off
Voltaat Jumper Wires - Male to Male (40 Pack)
10 QAR

Wiring it up


Before you begin wiring the shield with your Arduino, let's learn about the SIM900 GSM shield and setup it so that it works properly with you. The following image shows the most important components of the SIM900 GSM shield. Understanding the different parts of the shield will let you understand this tutorial much better.


You will also need a 5V/2A DC adapter to supply the shield with the necessary power through the DC jack. You must check the specifications of the adapter well.


Also, remember to insert the SIM card into the SIM card slot at the bottom of the shield and turn off the PIN lock before you start connecting it to the Arduino.


The shield has a power supply selection switch, which you must turn on when you use the adaptor. To startup the module, you must also push the power key in the side or 2 or 3 sec so it can connect to the network.


LED Status Indicators:

The SIM900 GSM/GPRS shield has three LEDs that show connectivity and power status. You may obtain visual feedback on what's going on with the shield by observing these LEDs.



You must make sure the jumper cap is connected as shown in the picture on the serial port select.


You will also need a 5V/2A DC adapter to supply the shield with the necessary power through the DC jack. You must check the specifications of the adapter well.


The shield has a power supply selection switch, which you must turn on when you use the adaptor. To startup the module, you must push the power key in the side.


Also, remember to insert the SIM card into the SIM card slot at the bottom of the shield and turn off the PIN lock before you start connecting it to the Arduino.


Wiring with Arduino:

Connections from the Arduino to the breadboard:

• Arduino GND pin → Breadboard ground line

• Arduino 5V pin → Breadboard 5V line


Connections from the sim900 GSM module:

• Two GND pin→ Breadboard ground line

• TXD pin → Arduino pin 7

• RXD pin → Arduino pin 8


Connections from the LED:

• Negative pin→ Breadboard ground line

• Positive pin→ Arduino pin 2


Coding


The function of this code is to control a small LED by sending messages from your phone and receiving them through the Arduino with the help of the SIM900 GSM shield. Its idea is straightforward: if the message contains "ON," the LED is turned on, and if it contains "OFF", it will be turned off.


Let's look at the code, and then you should be able to understand it once you follow the instructions and read the comments.


/*
Voltaat learn (http://learn.voltaat.com)
Link for full tutorial: https://bit.ly/3fMRpBF

Tutorial: Control an LED from anywhere via your phone!

The function of this code is to control a small LED
by sending messages from your phone and receiving them through
the Arduino with the help of the SIM900 GSM shield.

Connections from the Arduino to the breadboard:
• Arduino pin GND → Breadboard ground line
• Arduino pin 5V → Breadboard 5V line

Connections from the sim900 GSM module:
• TWO GND pin→ Breadboard ground line
• TXD pin → Arduino pin 7
• RXD pin → Arduino pin 8

Connections from the LED:
• Negative pin→ Breadboard ground line
• Positive pin→ Arduino pin 2
*/


//Allows serial communication on other digital pins of an Arduino board
#include < SoftwareSerial.h >

//Configure software serial port with digital pins 7,8
SoftwareSerialSIM900(7,8);

//Define the variable led to digital Pin 2
const int led =2;

//Define the variable mySMS with String data type
String mySMS;

//Commands inside void setup run once
void setup(){

//Arduino communicates with SIM900 GSM shield at a baud rate of 9600 (9600 bits per second)
SIM900.begin(9600);

//Start the serial monitor at 9600 baud rate (9600 bits per second)
Serial.begin(9600);

//Delay for 100 milliseconds
delay(100);

// Set module to send SMS data to serial out upon receipt
SIM900.println("AT+CNMI=2,2,0,0,0");

//Delay for one second
delay(1000);

//led is defined as an output
pinMode(led,OUTPUT);

//Turn LED off
digitalWrite(led,LOW);

}

//Commands inside void loop run forever
void loop()
{

if(SIM900.available()>0)
{
//Read string data from SIM900
mySMS = SIM900.readString();

//Print mySMS value to serial monitor
Serial.println(mySMS);
}
//Check if the SMS contains "ON"
if(mySMS.indexOf("ON")>-1)
{
//Print "LED ON" to serial monitor
Serial.println("LED ON");

//Turn LED ON
digitalWrite(led,HIGH);
}
//Check if the SMS contains "OFF"
elseif(mySMS.indexOf("OFF")>-1)
{
//Print "LED OFF" to serial monitor
Serial.println("LED OFF");

//Turn LED OFF
digitalWrite(led,LOW);
}
//Delay for 10 milliseconds
delay(10);
}

Testing it out





Now you must have correctly wired the SIM900 GSM module to the Arduino, as we explained in the wiring section, as well as uploaded the code to your Arduino board.


Try to send a message to the SIM card on your Arduino; if the message contains "ON," whether in capital or small letters, you will notice that the LED is turned on.


If the message contains "OFF," whether in capital or small letters, you will notice that the LED is turned off.

What do you think about the useful things that you can control remotely in this way?


Resources 


Arduino Code

Related Tutorials


In this tutorial, we will print data on your LCD using the Arduino. It is basic and straightforward. Let's find out more together!


In this tutorial, we will use the Arduino to control a relay on and off every three seconds. You can use the same code to control a fan to be turned on and off automatically every 10 minutes to save power!


In this tutorial, we will use the Arduino to control the servo motor shaft to sweep back and forth across 180 degrees. Let's have a look at it.