All Collections
Connect your Devices
Connect an Arduino UNO + GPRS Shield to Ubidots over TCP/UDP
Connect an Arduino UNO + GPRS Shield to Ubidots over TCP/UDP

Learn to setup and connect the Arduino Uno board + GPRS Shield to POST and GET data over TCP/UDP to/from Ubidots.

Isabel Lopez avatar
Written by Isabel Lopez
Updated over a week ago

Arduino is an open-source electronics platform based on easy-to-use hardware and software. The primary board for Arduino is the Arduino UNO which connects to a series of different shields to expand it’s possibilities.  

The Arduino UNO is a microcontroller board based on the ATmega328P, which contains everything needed to support the microcontroller including simple power supplies via a USB cable, an AC-to-DC adapter, or by battery. For official overviews of the Arduino UNO please refer to its documentation here.

The GPRS Shield is based on the SIM900 module from SIMCOM. It is compatible with all boards that have the same form factor (and pinout) as a standard Arduino Board. 

The GPRS Shield is configured and controlled via its UART using simple AT commands, is based on the SIM900 module from SIMCOM, and is about the size of a credit card.

By following this guide you will be able to POST and GET data to/from Ubidots using an Arduino UNO Board with a GPRS Shield in just a couple of minutes!

Requirements

Step-By-Step

 1. Hardware Setup
2. Setting up the Arduino IDE
3. Sending (POST) Data to Ubidots  
4. Receiving (GET) Data from Ubidots
5. Summary

1. Hardware Setup  

 1. Insert the SIM card with an activated data plan into the GPRS Shield.

2. Place the GPRS Shield atop of the Arduino UNO and apply gentle pressure until the shield's pins and the board's headers at tightly connected.  

3. The library which is going to be used to send handle the data with Ubidots uses the digital PIN "JP" of the SIM900 (PIN 9 in the Arduino) to power on/off the GPRS shield. Make sure the JP pad is soldered. The pad of the JP pin can be found next to the ISP port of the GPRS board. For additional information in soldering the JP pad, click here.

2. Setting up the Arduino IDE

  1. Download the Ubidots GPRS library and install it. For a detailed explanation of how to install libraries using the Arduino IDE, refer to this guide.  

3. Sending (POST) Data to Ubidots  

With the following sample code you will be able to post the ANALOG readings taken from Arduino UNO analog port.

NOTE: Before running the examples, make sure you have an active data plan. You will also need your mobile operator’s APN settings (APN, USERNAME, PASSWORD). You should be able to easily find these settings in Google or on your operator’s website.

1. To post your first value in Ubidots, open the Arduino IDE and paste the sample code below. Once you have pasted the code, you will need to assign your unique Ubidots TOKEN and the APN (Access Point Name) of your cellular provider with username and password.

// This example retrieves last value of a variable from the Ubidots API  
// using TCP protocol.        

/****************************************                      
* Include Libraries
****************************************/
#include <Ubidots.h>      

/****************************************                      
* Define Constants
****************************************/    
                 
// Your GPRS credentials, if any    
const char *APN = "Put_the_APN_here";
const char *USER = "Put_the_APN_user_here";
const char *PASS = "Put_the_APN_pwd_here";
const char *TOKEN = "Put_your_Ubidots_token_here";
const char *DEVICE_LABEL = "Put_your_device_API_label";
const char *VARIABLE_LABEL = "Put_your_variable_API_label";          

Ubidots client(TOKEN,APN,USER,PASS);

/****************************************                      
* Auxiliar Functions
****************************************/                          

// Put here your auxiliar functions
/****************************************                      
* Main Functions
****************************************/

void setup() {                      
  Serial.begin(115200);                      
  client.setDebug(true); // Set true to make available debug messages }    
                                     
void loop() {
  float value = analogRead(A0);  // Reading analog pin A0
  client.add(VARIABLE_LABEL, value);
  if(client.send()){
    Serial.println("Data sent to Ubidots sucessfully!")
  }                                      
  delay(5000);                    
}

2. Verify your code within the Arduino IDE. To do this, in the top left corner of our Arduino IDE you will see the "Check Mark" icon; press it to verify your code. 

3. Upload the code into your Arduino UNO + GPRS Shield. To do this, choose the "right-arrow" icon beside the "check mark" icon. 

4. To verify the connectivity of the device and the data sent, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of the Arduino IDE to see the connectivity logs. 

5. Confirm your data in Ubidots. Now you should see the posted data in your Ubidots account, located the device called "GPRS".

4. Receiving (GET) Data from Ubidots

With the following sample code you will be able to get a value from Ubidots to start controlling any asset you desire. 

1. To start getting values from Ubidots, open the Arduino IDE and paste the sample code below. Once you have pasted the code, be sure to assign the following parameters:

  • APN (Access Point Name) of your cellular provider with username and password

  • Device Label of the device which contain the variable desired to be obtained

  • Variable Label of the variable desired to be obtained

// This example retrieves last value of a variable from the Ubidots API                     
// using TCP protocol.

/****************************************
* Include Libraries
****************************************/
#include <Ubidots.h>  

/****************************************
* Define Constants
****************************************/

// Your GPRS credentials, if any
const char *APN = "Put_the_APN_here";
const char *USER = "Put_the_APN_user_here";
const char *PASS = "Put_the_APN_pwd_here";
const char *TOKEN = "Put_your_Ubidots_token_here";
const char *DEVICE_LABEL = "Put_your_device_API_label";
const char *VARIABLE_LABEL = "Put_your_variable_API_label";

Ubidots client(TOKEN,APN,USER,PASS);

/****************************************
* Auxiliar Functions
****************************************/
                         
// Put here your auxiliar functions    

/****************************************
* Main Functions
****************************************/  

void setup() {
  Serial.begin(115200);
  client.setDebug(true);// Set true to make available debug messages
}

void loop() {
  float value = client.get(DEVICE_LABEL, VARIABLE_LABEL);
  if(value!=ERROR_VALUE){
    Serial.print("Getting variable value: ");
    Serial.println(value);
  }
  delay(5000);
}                
                   

2. Verify & Upload the code into the board following the same steps provided in the POST step above.

3. To verify the connectivity of the device and the data which is being received, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of the Arduino IDE to see the connectivity logs. 

4. At this point, in the serial monitor, you should be able to see the last value of variable specified in the firmware that was received in Ubidots.

5. Summary  

With this simple tutorial we are able to POST & GET data to/from Ubidots with the ease of the Arduino IDE and a Arduino UNO + GPRS Shield. If your wish to find more examples to handle context or timestamp values in your request checkout Ubidots documentation with the GPRS Shield by clicking here

Now its time to create Ubidots Dashboards to visualize your data and deploy your IoT solution!  Happy Hacking! :) 

Other readers have also found useful...

Did this answer your question?