Interfacing GSM Module with AVR Microcontroller: Send and Receive Messages Using Atmega

Interfacing GSM Module

GSM modules are interesting to use especially when our project requires remote access. These modules could make all actions that our normal mobile phone could do, like making/receiving a call, sending/receiving a SMS, connecting to internet using GPRS etc. You can also connect a normal microphone and speaker to this module and converse on your mobile calls. This will open doors to lot of creative projects if it could be interfaced with a Microcontroller. Hence in this tutorial we will learn how we can Interface the GSM module (SIM900A) with AVR microcontroller ATmega16 and will demonstrate it by sending and receiving messages using GSM Module.

Interfacing GSM Module

Materials Required

  1. Atmega16
  2. GSM module (SIM900 or any other)
  3. LCD display
  4. Push buttons
  5. 10k resistors, Potentiometer
  6. Connecting wires
  7. 12V Adapter
  8. USBasp programmer
  9. 10 pin FRC cable

Software Used

We will use CodeVisionAVR software for writing our code and SinaProg software for uploading our code to Atmega16 using USBASP programmer.

You can download these softwares from the given links:

CodeVisionAVR : http://www.hpinfotech.ro/cvavr_download.html

SinaProg : http://www.ablab.in/sinaprog-hex-file-downloader-software-to-download-code-to-avr-microcontroller/#inline_content

Before going into the schematics and codes, we learn about GSM module and its working.

GSM Module

The GSM module can be used even without any microcontroller by using the AT command mode. As shown above the GSM module comes with a USART adapter which can be directly interfaced to the computer by using a MAX232 module or the Tx and Rx pins can be used to connect it to a Microcontroller. You can also notice the other pins like MIC+, MIC-, SP+, SP- etc where a microphone or a Speaker can be connected. The module can be powered by a 12V adapter through a normal DC barrel jack.

Insert your SIM card in the slot of the module and power it on, you should notice a power LED going ON. Now wait for a minute or so, and you should see a red (or any other colour) LED Flashing once for every 3 seconds. This means that your Module was capable to establish connection with your SIM card. Now you can proceed with connecting you module with Phone or any Microcontroller.

You can build many cool projects using GSM module like:

Also check all the GSM related projects here.

Communicating with GSM module using AT commands

As you might have guessed it, the GSM module can communicate through Serial communication and could understand only one language and that is “AT commands”. Whatever that you might want to tell or ask to the GSM module it should only be via AT commands. For example if you want to know if your module is active. You should ask (send) a command like “AT” and your module will reply “OK”.

Interfacing GSM Module schematics

These AT commands are well explained in its data sheet and can be found here in its official datasheet. Okay! Okay! It is a 271 page datasheet and you might take days to read through them. So I have given some most important AT commands below for you to get this up and running soon.

AT

Replies with OK for Acknowledgement

AT+CPIN?

Check signal Quality

AT+COPS?

Find service provider name

ATD96XXXXXXXX;

Call to the specific number, ends with semi-colon

AT+CNUM

Find the number of SIM card (might not work for some SIM)

ATA

Answer the Incoming Call

ATH

Hang off the current Incoming call

AT+COLP

Show incoming call number

AT+VTS=(number)

Send DTMF number. You can use any number on your mobile keypad for (number)

AT+CMGR

AT+CMGR=1 reads message at first position

AT+CMGD=1

Delete message at first position

AT+CMGDA=”DEL ALL”

Delete All messages from SIM

AT+CMGL=”ALL”

Read all messaged from SIM

AT+CMGF=1

Set SMS configuration. “1” is for text only mode

AT+CMGS = “+91 968837XXXX”

>CircuitDigest Text<Ctrl+z>

Sends SMS to a particular number here 968837XXXX. When you see “>” start entering the text. Press Ctrl+Z to send the text.

AT+CGATT?

To check for internet connection on SIM card

AT+CIPSHUT

To close TCP connection, meaning to disconnect form internet

AT+CSTT = “APN”,”username”,”Pass”

Connect to GPRS with your APN and Pass key. Can be obtained from Network Provider.

AT+CIICR

Check if SIM card has data pack

AT+CIFSR

Get IP of the SIM network

AT+CIPSTART = “TCP”,”SERVER IP”,”PORT”

Used to set a TCP IP connection

AT+CIPSEND

This command is used to send data to server

Here we will use AT+CMGF and AT+CMGS command to send messages.

Read more: Interfacing GSM Module with AVR Microcontroller: Send and Receive Messages

Leave a Comment

Your email address will not be published. Required fields are marked *