Sending Data from GSM module to a Web Server using Arduino
Sending Data from GSM module to a Web Server using Arduino
Required Components:
1. Arduino Uno: We will use Arduino due to its easy use. It also provides
several digital pins to interface with the LCD, GSM module, and keypad
at the same time. It is very friendly when you prototyping any project.
2. GSM SIM900A: SIM900A GSM Module is the smallest and cheapest
module for GPRS/GSM communication. The module offers GPRS/GSM
technology for communication with the uses of a mobile sim. It uses a
900 and 1800MHz frequency band and allows users to receive/send
mobile calls and SMS. We can send SMS, data, Voice, and Fax using
this module. Its operating voltages range is 3.2 to 4.8V. It draws only
1.0mA in sleep mode. Its Operating temperature range is -40°C to +85
°C. Note use a power supply which can supply up to 1 amp. You can
check this article to know, how to interface a GSM module
with Arduino.
3. External 5 volt supply: 5 volt dc supply is required to power the GSM
module.
4. 16×2 LCD: 16×2 LCD is used to display 16 characters in two lines. It is
easy to interface with Arduino due to its available library. It also operates
on the same voltages of Arduino Uno. In this project, this LCD is used to
display different messages. A 10k potentiometer is used to control the
contrast of the display.
5. 4×4 Keypad: It consists of 4 rows and 4 columns. It contains 16 buttons
which we can define as our requirement in the code. The following
keypad is used in this project:
Working
In this project, Arduino Uno is used as the brain of our circuit.
You can view the operations constituting this project in the block diagram
below.
First of all, we will enter text using the 4×4 keypad. The text will be displayed
on 16×2 LCD in real time.
We will program our project in such a way that we will be able to enter both
numerical and alphabets/characters using the 4×4 keypad. The figure above
shows the keypad configuration we will use in this project. For example if we
press the key 3 once then it will enter D. If we press it again, then it will enter
E. If we press it again, then it will enter F.
After writing the text, we will press D button on the keypad to send the data to
the Spark Fun web server. The GSM module will connect to the web server by
using the information defined in the code such as public and private keys. It
will send the data on the web server which we can check by opening the web
server. The data can be of any type such as numeric, alphabetic or special
character. The only disadvantage is that spark fun only provides 50MB of data
which is not enough if you want to use it regularly.
D0 – D7: Pin number 7-14 are data bus lines that are used to send data
from Arduino which you want to display on LCD. With these 8 data lines,
data can be transferred either in an 8-bit format or in a 4-bit format. In a
4-bit format, only upper four bits (D4-D7) are used to send data from
Arduino to LCD. The full byte is transmitted in two successive
transmissions. A 4-bit format is used to save GPIO pins of Arduino.
Because fewer GPIO pins of Arduino will be required to transfer data.
Contrast Select (VEE): It will help to control the contrast of PIXELS
according to the 16X2 LCD light.
RS: This pin is known as a register select pin. It helps to toggle the
command/data register.
R/W: The signal on this pin will decide whether it is going to read from
LCD or write on it.
EN: Enable pin will help to transfer the instruction from the data pins and
another command pin to the LCD. It act as permission to internal
registers.
VSS: It’s a ground pin for common grounds.
VCC: The power pin will use for voltage input to the 16X2 LCD.
Arduino connections with 16×2 LCD
We are using the following connections as described below. Refer to the
schematic diagram to have a clearer idea of the connections.
Enable Pin A1
RS Pin A0
RW GND
VSS GND
VCC +5V
LED+ +5V
LED- GND
We have an Arduino library for easy communication between LCDs called
the LiquidCrystal library. It is an inbuilt library by Arduino Adafruit version.
Arduino with 4×4 Keypad
Keypads consist of push buttons arranged in row and column pattern. That
means if we take an example of a 4×4 keypad, it will internally consist of 16
push buttons. To save microcontroller pins, keypads are arranged in the form
matrix of rows and columns. For instance, a 4×4 keypad is arranged into a
matrix of four rows and four columns. By using this pattern, we will need only 8
GPIO pins of Arduino.
The status of each key/switch is determined by Scanning the rows or columns.
The column pins (Col 1–Col4) are connected to the microcontroller as the
inputs pins and the rows pins (Row 1–Row 4) are connected to the output pins
of the microcontroller. Normally, all the column pins are pulled high by internal
or external pull up resistors. Now we can read the status of each switch
through scanning.
The output connector provides output pins for rows and columns. The first four
pins from the left are rows and the last four pins from the right are the
columns. To sense the state of each pushbutton from a specific location of a
row and a column, we will use digital pins of Arduino.
Arduino Sketch
Open your Arduino IDE and go to File > New to open a new file. Copy the
code given below in that file and save it.
#include <SoftwareSerial.h> // serial software library
for interfacing gsm module
#include<LiquidCrystal.h> // LCD library for interfacing
LCD
#include <Keypad.h> // keypad library for interfacing
keypad
void setup()
{
Serial1.begin(9600); // init serial for GSM
lcd.begin(16, 2); // init LCD
lcd.print("MICROCONTROLLERS");
lcd.setCursor(0, 1);
lcd.print(" LAB ");
delay(2000);
lcd.clear();
lcd.print("Sending Data ");
lcd.setCursor(0, 1);
lcd.print("to Server");
delay(2000);
lcd.clear();
lcd.print("Initializing GSM");
initGSM(); // init GSM module
lcd.clear();
lcd.print("Initializing GPRS");
initGPRS(); // init GPRS in GSM Module
lcd.clear();
lcd.print("System Ready");
delay(2000);
}
void loop()
{
int n = 0;
lcd.clear();
lcd.noCursor();
while (1)
{
lcd.cursor();
char key = customKeypad.getKey();
if (key == '1')
getkey(0, 6, key);
if (key == '2')
getkey(7, 10, key);
else if (key == '3')
getkey(11, 14, key);
else if (key == '4')
getkey(15, 18, key);
else if (key == '5')
getkey(19, 22, key);
else if (key == '6')
getkey(23, 26, key);
else if (key == '7')
getkey(27, 31, key);
else if (key == '8')
getkey(32, 35, key);
else if (key == '9')
getkey(36, 40, key);
else if (key == '*')
getkey(41, 41, key);
else if (key == '0')
getkey(42, 43, key);
else if (key == '#')
getkey(44, 44, key);
connectGSM("AT+CIPSHUT", "OK");
connectGSM("AT+CGATT=1", "OK");
connectGSM("AT+CSTT=\"airtelgprs.com\",\"\",\"\"",
"OK");
connectGSM("AT+CIICR", "OK");
delay(1000);
Serial1.println("AT+CIFSR");
delay(1000);
}
connectGSM()
The connectGSM() function will be used to initialize the GPRS and the GSM
module.
void setup()
{
Serial1.begin(9600); // init serial for GSM
lcd.begin(16, 2); // init LCD
lcd.print("MICROCONTROLLERS");
lcd.setCursor(0, 1);
lcd.print(" LAB ");
delay(2000);
lcd.clear();
lcd.print("Sending Data ");
lcd.setCursor(0, 1);
lcd.print("to Server");
delay(2000);
lcd.clear();
lcd.print("Initializing GSM");
initGSM(); // init GSM module
lcd.clear();
lcd.print("Initializing GPRS");
initGPRS(); // init GPRS in GSM Module
lcd.clear();
lcd.print("System Ready");
delay(2000);
}
loop()
Inside the loop() function we will send alphanumerical data through the GSM
module to SparkFun server. We will use a series of if-else if statements to
check which key was entered and thus, we will accordingly input the
characters using the getkey() function.
void loop()
{
int n = 0;
lcd.clear();
lcd.noCursor();
while (1)
{
lcd.cursor();
char key = customKeypad.getKey();
if (key == '1')
getkey(0, 6, key);
if (key == '2')
getkey(7, 10, key);
else if (key == '3')
getkey(11, 14, key);
else if (key == '4')
getkey(15, 18, key);
else if (key == '5')
getkey(19, 22, key);
else if (key == '6')
getkey(23, 26, key);
else if (key == '7')
getkey(27, 31, key);
else if (key == '8')
getkey(32, 35, key);
else if (key == '9')
getkey(36, 40, key);
else if (key == '*')
getkey(41, 41, key);
else if (key == '0')
getkey(42, 43, key);
else if (key == '#')
getkey(44, 44, key);