Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Arduino
100 min
Share

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!

Project Video

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.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
SIM900 GSM Shield for Arduino
Get Item
AC/DC Power Adapter – 5V 3A (Barrel Jack)
Get Item
Half-size Breadboard
Get Item
Red 3mm LED (5 pack)
Get Item
1/4 Watt Resistor (20 Pack)
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item

Steps

Wiring it Up

Connect wires between the Arduino and the SIM900 GSM module as shown in the image below.


 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

Coding


/*
 Voltaat learn (http://learn.voltaat.com)
 Link for full tutorial:

 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
SoftwareSerial SIM900(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"
 else if (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

No items found.