How to Send Data to Web Server using Arduino and SIM900A GPRSGSM Module - Internet of Things

How to Send Data to Web Server using Arduino and SIM900A GPRSGSM Module

How to Send Data to Web Server using Arduino and SIM900A GPRS/GSM Module
Today we are here with an interesting project in which we will Send Data to the SparkFun server using Arduino and GPRS. This is an IoT based project in which we will use GPRS, present on the GSM Module SIM900A board, to send some data to the web service on the internet.
In this project, we will simply enter some text using 4x4 Alphanumeric keypad and send it to SparkFun website using Arduino and GPRS, from where you can see that data from anywhere in the word through internet. Here we have also attached a 16x2 LCD to see the data locally. This data sending technique is very useful in IoT projects where you want to monitor things from anywhere in the world like Monitoring Temperature & HumidityMonitor Vehicle LocationMonitor Heart BeatMonitor Air pollution level etc.

Components Required:
  1. Arduino
  2. GSM Module SIM900A
  3. 16x2 LCD
  4. 4x4 Matrix Keypad
  5. Breadboard or PCB
  6. Connecting jumper wire
  7. Power supply 12v
  8. SIM Card

Using GPRS in GSM Module:
Here we have used a normal GSM Module with a SIM card for GPRS connection. In this project, GPRS is responsible for sending data to the Sparkfun server. Previously we have done many projects where we have used Wi-Fi module ESP8266 to send data to different servers over internet. But this time we have used GPRS. Check the detailed Video at the end of this tutorial.

GPRS stands for General Packet Radio Services which is a packet based wireless communication service that works with data rate of 56-114kbps and provides a connection to the internet.
For GPRS, we do not need to buy any special module or hardware because GSM already has GPRS facilities inbuilt. We only need to access it by using the same method or AT commands that we used for GSM interfacing in our previous projects. There are many AT commands already mentioned in the datasheet of SIMCOM SIM900A GSM module.
Now for sending data to server by using GPRS, first we need to initialize GSM module.
Commands for initializing GSM:
AT :- this command is used to check whether GSM module is responding or not.

AT+CPIN? :- this command is used to check whether SIM card is inserted in GSM Module or not.
ATE0 :- is used for disabling echo

ATE1 :- is used for enabling echo

Commands for initializing GPRS internet connection:
AT+CIPSHUT :- to close TCP Port Explicitly means disconnect connection if any

AT+CGATT? :- Checking SIM card has internet connection or not

AT+CSTT = "APN","userName","Pass" :- connect to internet

(ex; AT+CSTT="airtelgprs.com","","")

AT+CIICR :- bring up with the wireless network. Checking SIM card has data pack or balance

AT+CIFSR :- get IP (sometimes without this command GSM do not work so use this command)

AT+CIPSTART = ”TCP,SERVER IP,PORT” :- is used for creating TCP connection with the server that we provide in place of SERVER IP

AT+CIPSEND :- this command is used for sending data to the server. After input, this command server asks for data.

After inputting the data we send 26 to the server. If everything will be fine then data will be posted successfully to the server and SparkFun server responds with a pass or fail string.

Working Explanation:
Process of Sending Data from GPRS of GSM Module is easy. Here in this project, we are sending some string or words to the server by typing using keypad. Same string or word will appear over the LCD, then press D/OK to send the input string to the server. Here we have created an Alphanumeric Keypad for inputting the characters or numeric values to Arduino or LCD. C/clear is programmed for backspace.

Alphanumeric is a method to enter numbers and alphabets both by using the same 4x4 matrix Kepad keypad. Here we have coded the same 4x4 keypad for Arduino to accept alphabets also. Check the full code at the end of the article.

Circuit Explanation:
 For Sending Data to SparkFun Server, we need to interface Keypad and GSM module to Arduino. In this project we have used Arduino to taking input string from the keypad and sending commands to GSM/GPRS module. GSM/GPRS is used to communicate with the Internet for sending data to the Sparkfun server. GSM Modules Rx and Tx pin is directly connected with Arduino's pin D3 and D2 respectively (Ground of Arduino and GSM must be connected with each other). 16x2 LCD is used for displaying input strings and showing welcome message and data sending status as well.  Pins of this 16x2 LCD namely Rs, en, d4, d5, d6, and d7 are connected with pin number 14, 15, 16, 17, 18 and 19 of Arduino respectively. 4x4 keypad is used for input string to Arduino and its  Row pins R1, R2, R3, R4 are directly linked to pin number 11,10, 9, 8 of Arduino and Colum pin of keypad C1, C2, C3 are linked with pin number 7, 6, 5,4 of Arduino.
Here we have also connected GSM Tx pin to Tx of Arduino to get response data over the serial monitor.

Programming Explanation:
Programming part of this project is a little complex for beginners but by doing a little bit practice and paying attention you can understand it. In this code, we have used keypad library for interfacing simple keypad for entering numbers. And for entering alphabets we have used the same library and keypad but used one more function to make it alphanumeric keypad. Means we have made every key multi-functioning and can enter all the characters and integers by using only 10 keys.
If we press key 2 (ABC2), it will show Aand if we press it again then it will replace Awith Band if again we press it then it will show Cat the same place in LCD. If we wait for some time after pressing a key, the cursor will automatically move to next position in LCD. Now we can enter next char or number. And same procedure is applied to other keys. It works same as keypad in old mobile phones.

Below we have included Keypad.h library and define array matrix for the keys:
#include <Keypad.h>               // keypad library for interfacing keypad
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
int x=0;
int y=0;
int n=0;
int minValue=0;
int maxValue=0;
char keyPress=0;
int keyPressTime=100;
String msg="";

char hexaKeys[ROWS][COLS] =
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = {11, 10, 9, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad

And given void getkey function is used for input alphabets
void getkey(int minValue, int maxValue, char keyPress)
{
   int ch=minValue;
   int pressed=1;
   char key=keyPress;
   lcd.noBlink();
   for(int i=0;i<keyPressTime;i++)
   {    
      if(key==keyPress)
      {
         lcd.setCursor(x,y);
         lcd.print(alpha[ch]);
         ch++;
         if(ch>maxValue)
         ch=minValue;
         i=0;  
      }
      ....
      .....

Below void initGSM() and void initGPRS() functions are used for initializing GSM module and GPRS
void initGSM()
{
  connectGSM("AT","OK");
  connectGSM("ATE1","OK");
  connectGSM("AT+CPIN?","READY");
}
void initGPRS()
{
  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);
}

Below part of the code is used to create URL and send the data to server via URL.
else if(key == 'D')
    {
      lcd.clear();
      lcd.noBlink();
      lcd.print("Sending Data");
      lcd.setCursor(0,1);
      lcd.print("To Server");
      url="GET /input/";
      url+=publicKey;
      url+="?private_key=";
      url+=pvtKey;
      url+="&log=";
      url+=msg;
      url+=" HTTP/1.0\r\n\r\n";
      String svr=Start+","+ip+","+port;
      delay(1000);
      connectGSM(svr,"CONNECT");
      delay(1000);
      int len = url.length();
      String str="";
      str=SendCmd+len;
      sendToServer(str);

 Demo & Code


How to Send Data to Web Server using Arduino and SIM900A GPRSGSM Module How to Send Data to Web Server using Arduino and SIM900A GPRSGSM Module Reviewed by XXX on สิงหาคม 27, 2560 Rating: 5

ไม่มีความคิดเห็น