Tag Archive: GSM


GSM controlled RELAY with Arduino

In this post we ‘ll control a relay through GSM by sending message.

Parts required  :

GSM SIM900 or SIM800

Relay board  (12v board with active HIGH , i.e if you send HIGH from Arduino then Rlay will be ON)

Arduino UNO

DC connector cable & 12v adapter

We’ll make it simple   By sending SMS $a1 Relay is made ON

BY sending SMS $a0 the Relay is switched OFF

GSM SIM900 board is used in this demo , but you can use SIM800 also. A valid SIM to be inserted in to the slot on GSM board. Do not use 4G SIM like JIO , as the SIM 800 / 900 is 2G /3G enabled.

GSM2

 

A 1 channel relay board is used which is a 12v relay & needs a HIGH to enable the relay. Note that if you use a relay board with opto coupler , it needs a LOW to switch ON the relay .In this demo we use a 12v , HIGH enable relay which uses a simple NPN transistor to switch ON the relay.

 

GSM3

i.e from Arduino Digital pin you send a HIGH to switch ON the relay.

 

Connection

Digital pin 8 of Arduino is connected to Relay board INPUT

Rx of Arduino to Tx of GSM , Tx of Arduino to Rx of GSM

GND of Arduino to GND of GSM

12V Adapter is used as power source. Power socket is provided on GSM & Arduino boards . DC connectors are used to power up GSM & Arduino .As Arduino has 5v regulator on board you can safely use 12v at power socket.

The +ve pin of Relay board is looped with +12v of adapter & -ve to GND of Relay board.

Ensure that all GND pins are made common , that of GSM , Arduino & Relay boards.

 

GSM5

 

Following is the Arduino code to be uploaded. Remember to disconnect wires at Rx/Tx while uploading code to Arduino.

You can Download the Code HERE

 

——————————

char inchar; // variable to store the incoming character

int Relay = 8;

 

void setup()

{

pinMode(Relay, OUTPUT);

digitalWrite(Relay, LOW);

Serial.begin(9600);

delay(2000);

Serial.println(“AT+CMGF=1”); // set mode to text

delay(100);

Serial.println(“AT+CNMI=2,2,0,0,0”);

// just to get a notification when SMS arrives &direct out SMS upon receipt to the GSM serial out

delay(100);

}

 

void loop()

{

//If a character comes in from the GSM…

if(Serial.available() >0)

{

inchar=Serial.read();

if (inchar==’$’)

{

delay(10);

inchar=Serial.read();

if (inchar==’a’)

{

delay(10);

inchar=Serial.read();

if (inchar==’0′)

{

digitalWrite(Relay, LOW);

Serial.println(“Relay OFF”);

}

else if (inchar==’1′)

{

Serial.println(“Relay ON”);

digitalWrite(Relay, HIGH);

}

delay(100);

Serial.println(“AT+CMGD=1,4”); // delete all SMS

delay(2000);

}

}

}

}

———————————–

A char variable inchar is used to store the incoming SMS

The relay pin is defined as DIGITAL pin 8

Inside setup function , the Relay pin is declared as OUTPUT using pinMode & then initially it is made LOW

Serial.begin(9600) ; starts Serial communication at baud 9600.

AT+CMGF=1 confirms TEXT mode operation of GSM .Notice the use of SerialPrintln which provides a Carriage Return

Serial.println(“AT+CNMI=2,2,0,0,0”);

// just to get a notification when SMS arrives &direct out SMS upon receipt to the GSM serial out

The AT command +CNMI is used to specify how newly arrived SMS messages should be handled. You can tell the GSM/GPRS modem or mobile phone either to forward newly arrived SMS messages directly to the PC, or to save them in message storage and then notify the PC about their locations in message storage.

Syntax: AT+CNMI=<mode>,<mt>,<bm>,<ds>,<bfr>

Description:

This command selects the procedure for message reception from the network.

Values:

<mode>: controls the processing of unsolicited result codes

Note: Only <mode>=2 is supported.

<mt>: sets the result code indication routing for SMS-DELIVERs. Default is 0.

0: No SMS-DELIVER indications are routed.

1: SMS-DELIVERs are routed using unsolicited code: +CMTI: “SM”,<index>

2: SMS-DELIVERs (except class 2 messages) are routed using unsolicited code: +CMT:…….

AT+CNMI is used anyway just to get a notification when a SMS arrives, in order to read the content of the stored SMS you have to use AT+CMGL= or AT+CMGR=…

 

Inside Loop

If any serial data is available it is assigned to inchar variable

If the first character is $ , the inchar variable is replaced with next Serial character

If the next character is a , again the inchar is replaced with next serial character

Finally , if the character is 1 , the pin 8 is made HIGH & relay is made ON

If the final character is 0 , pin 8 is made LOW , thus making the relay OFF.

SMS $a1 makes the Relay ON

SMS $a0 makes the Relay OFF

Only basic code is explained in this post to just ON or OFF the relay. Further improvements can be done like :

1. Relay status sent back as SMS to the caller

2. Programming can be done so that SMS from particular Master number only is considered

& SMS from other number will not control the relay

3. Pump starter can be made ON / OFF by using 2 relays .One relay contact used to START the motor & other to STOP .While connected with STARTER we need to momentarily switch ON / OFF the relays. This is similar to manually pressing the START or STOP button of the motor starter.

Support video :

blog_image

GSM BASED CONTROL BOARDS

This post introduces the GSM based project boards developed by NSK ELECTRONICS  & marketed by www.alselectro.com .

GSM BASED MOTOR CONTROL BOARD

GSM BASED RELAY CONTROL

GSM BASED SECURITY SYSTEM

The boards are designed to industry standards . Students can watch the videos to understand the functioning of the boards & can implement in their projects using Arduino , PIC , ARM  or 8051 controllers.

cooltext753793315_thumb.png      cooltext753790696.png

SIM908 – GSM ,GPRS & GPS All In One

This GPS/GPRS/GSM all-in-one board  uses an embedded SIM908 chip from SIMCOM.

Featuring an industry-standard interface and GPS function, the combination of both technologies allows goods, vehicles and people to be tracked seamlessly at any location and anytime with signal coverage.

Although the module is capable of dual UART , only a single UART   is used in this board.Through AT commands the GPS Engine is switched ON to get the NMEA sentence.GSM is controlled through same UART by AT commands.

Individual Antennas are provided , a STUB Antenna for GSM & an external Magnetic PATCH Antenna for the GPS.The position of Antennas is important , the one near the LM317 regulator is for GSM & the one in middle is for GPS.

sim908_11

The board must  be powered by an external adapter of 12v 1.5amps.Do not try to power this board from your Arduino or any uC board.

The board is best suited for Microcontrollers like 89S52 or PIC16F877A which have only single UART.

With SIM908 you can avail both GSM & GPS on a single UART.

To test the board with PC , we make use of a USB-UART board built on CP2102 Silicon Labs IC .The M908 board is connected to USB-UART board with a STAIGHT type of RS232 cable.

On connecting the USB cable to PC , a COM port is allotted ( which you can note down from the Device Manager) .This port number is used to communicate from PC to SIM9908 using a Terminal Software like PUTTY or HyperTerminal or TERATERM.

In this demo we shall use PUTTY on serial Baud Rate 9600.

Following snapshot shows the setup for testing.Note that the GPS Antenna should be left outside window .GPS gets a FIX immediately only when the Antenna faces SKY directly.Otherwise it takes more time to get a FIX.

STARTUP TESTING

Insert a valid SIM to the SIMHOLDER on the  back of the board.On powering up the SIM908 , the SIGNAL LED blinks fast initially & after short time it stops & then blinks slowly.

This indicates that the NETWORK is received.

Now from your mobile , dial the number of the SIM you’ve inserted on the SIM908 board.You get the Ring Back tone & the RING LED on the board glows.

WP_20150921_002

Note the COM Port allotted under the Device Manager & then open the PUTTY.

Select Serial , feed in the COM Port ( here its COM11) & baud rate as 9600.

Type in AT , the SIM908 module will respond with OK.

AT+CPIN?     returns the SIM STATUS . +CPIN: READY indicates SIM is inserted.

AT+CSQ       returns the SIGNAL QUALITY. 31 is the maximum level.

AT+COPS?    returns the SERVICE PROVIDER of your SIM.

AT+CGSN    gives the IMEI number of the SIM908 module which is Unique to every module.

gsm1

The default BAUD RATE is 9600.

If you wish to change baud , use the command AT+IPR

gsm5

To dial a number

ATD944xxxxx;        ATD followed by the number to be called & then a semicolon ; is a must.

ATH  to terminate the call

If you call the SIM number from another mobile , you get RING , RING  display.

ATA   To attend the call   & ATH to terminate the call.

If you want the caller ID to be displayed

AT+CLIP=1     enables caller ID.

GSM2

To send a message , first enable TEXT MODE ,

AT+CMGF=1

Now assign the target number to which message has to be sent

AT+CMGS=”944xxx”

A >    symbol appears , after which you’ve type the Message to be sent.

CTRL+Z has to be pressed to send the message .  0x1A is  the Hex code used to represent CTRL+Z within your C code.

gsm3

GPS AT COMMANDS

AT+CGPSPWR=1  enables GPS engine

AT+CGPSRST=0    COLD starts GPS.

AT+CGPSINF=0    returns a single NMEA sentence

GPS1

AT+CGPSSTATUS?     indicates whether GPS has got a FIX. If ERROR is the response , then relocate the GPS Antenna , wait for some time & then retry.

gps_3

AT+CGPSINF=32    returns the GPRMC NMEA sentence , from which you can parse the latitude,longitude

Generally the CGPSINF is assigned value  2 ( 2 power 1) to get GPGGA sentence

4  ( 2 power 2 ) to get GPGLL sentence

32 ( 2 power 5) to get GPRMC sentence.

gps_cgp1

gps_cgp2

Widely used value for CGPSINF is 32 which returns the GPRMC Sentence.

In your C code , look out for the value 32 & then count the occurrence of comma .After  second comma is the FIX data ( A means FIX , V means VOID- no fix)  ,after 3rd  comma is the longitude, etc..

GPS2

Watch the Support video for this post :

For availability of this Module contact :

LOGO2

cooltext753793315  cooltext753790696