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.

#include <UbidotsArduinoGPRS.h>
#include <SoftwareSerial.h>

//Serial Relay - Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART
#define APN "Put_the_APN_here" // Assign the APN
#define USER "Put_the_APN_user_herer"  // If your apn doesnt have username just put ""
#define PASS "Put_the_APN_pwd_here"  // If your apn doesnt have password just put ""
#define TOKEN "Put_your_Ubidots_token_here"  // Replace it with your Ubidots token
#define VARIABLE_LABEL "temperature" // Assign the variable label

Ubidots client(TOKEN);
SoftwareSerial gprs = SoftwareSerial(7, 8);
SoftwareSerial *GPRSSerial = &gprs;

void setup() {
  Serial.begin(115200);
  GPRSSerial->begin(19200);
  if (! client.init(*GPRSSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }
  client.setApn(APN,USER,PASS);
  //client.setDebug(false);
}

void loop() {
  float value = analogRead(A0);  // Reading analog pin A0
  client.add(VARIABLE_LABEL, value);  
  client.sendAll();
}

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
  • Ubidots TOKEN
  • Device Label of the device which contain the variable desired to be obtained
  • Variable Label of the variable desired to be obtained
#include <UbidotsArduinoGPRS.h>
#include <SoftwareSerial.h>

//Serial Relay - Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART
#define APN "Put_the_APN_here" // Assign the APN
#define USER "Put_the_APN_user_here"  // If your apn doesnt have username just put ""
#define PASS "Put_the_APN_pwd_here"  // If your apn doesnt have password just put ""
#define TOKEN "Put_your_Ubidots_token_here"  // Replace it with your Ubidots token
#define DEVICE_LABEL "Put_your_device_API_label" // Assign your device api label
#define VARIABLE_LABEL "Put_your_variable_API_label" // Assign your device api label

Ubidots client(TOKEN);
SoftwareSerial gprs = SoftwareSerial(7, 8);
SoftwareSerial *GPRSSerial = &gprs;

void setup() {
  Serial.begin(115200);
  GPRSSerial->begin(19200);
  if (! client.init(*GPRSSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }
  client.setApn(APN,USER,PASS);
  //client.setDebug(false);
}

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

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?