Skip to main content
All CollectionsConnect your Devices
Send Data to Ubidots from Arduino Board Provisioned with Seeed Studio’s LoRa-E5 Module
Send Data to Ubidots from Arduino Board Provisioned with Seeed Studio’s LoRa-E5 Module

Learn how to connect and send data to Ubidots with any Arduino board and Wio-E5 LoRa module.

Sergio M avatar
Written by Sergio M
Updated over 3 months ago

<a href="https://downloads.intercomcdn.com/i/o/596978839/ad633355912e64a78d4c0c90/94951e1c-6d11-4dd4-9423-6c202b2170d1?expires=1733670000&amp;signature=a6f1d10ba2a852e4edc1628580e9046ec278fe4e3bc4548e61a6dd9ccdf00cb9&amp;req=cSkhH852lYJWFb4X1HO4gaP4XjBkQt5IPFwy2xZde1yJy2EuNCWTFCLESIew%0A" target="_blank" rel="nofollow noopener noreferrer">https://downloads.intercomcdn.com/i/o/596978839/ad633355912e64a78d4c0c90/94951e1c-6d11-4dd4-9423-6c202b2170d1</a>

Requirements

  • Access to a LoRaWAN gateway connected to Helium network

  • Any Arduino board with at least two UART interfaces. This guide uses Arduino Mega 2560, however, you can choose any that suits you better

  • A breadboard and jumper wires

  • Any of Seeed Studio’s Wio-E5 Series registered on Helium’s network. Visit this guide (steps 1 to 4) in order to learn how to register your device and how to use its built-in AT firmware

  • DS18B20 temperature sensor or any other sensor of your choice. If you don’t have sensors at hand, this guide will show how to simulate the data

  • An active Ubidots account

1. Connect the Sensor to Arduino

In this guide, a DS18B20 temperature sensor was used; however, you can pick any sensor you want or, even, not use one at all. If you chose to use the DS18B20, proceed to connect it to the Arduino Board in the following way:

  • Sensor “Vin” pin to Arduino “5V”

  • Sensor “GND” pin to Arduino “GND”

  • Sensor “Data” pin to Arduino pin “2”

image1099.png

2. Connect the LoRa Module to Arduino

In this guide, the Wio-E5 Development Kit was used, however, as stated before, any of the Wio-E5 Series Modules is compatible with this guide.

In order to use the Wio-E5 module as a LoRa transmitter, its built-in factory AT firmware will be used. For that purpose, it is only required to establish a serial communication with the module. Proceed to connect the Arduino board and the Wio-E5 module in the following way:

  • Arduino “TX01” pin to Wio-E5 “RX” pin

  • Arduino “RX01” pin to Wio-E5 “TX” pin

  • Arduino “5V” pin to Wio-E5 “Vin” pin

  • Arduino ""GND" pin to Wio-E5 "GND" pin

The following picture shows the connection instructions:

image1071.png

Pro Tip: Remember to connect the antenna to the chip you are using in order to prevent it from getting damaged.


If you chose to use the DS18B20 sensor, you might want to check out this link before moving onto the next section in order to set up the libraries for acquiring the sensor data.

3. Uploading the code to Arduino

Start your Arduino IDE and create a blank sketch, then select the board you are using from Arduino’s Board Manager. In this guide, Arduino Mega 2560 was used; however, you should select specifically the one that you are using.

image1479.png

After selecting the appropriate board, proceed to paste the following chunk of code:

//delete both of these includes in case you are not using the DS18B20 temperature sensor
#include <OneWire.h>
#include <DallasTemperature.h>

//pin number in which the DS18B20 sensor is connected
#define DS18B20DataPin 2

//delete this instances in case you are not using DS18B20
OneWire oneWire(DS18B20DataPin);
DallasTemperature ds18b20(&oneWire);

//enter here your appkey
#define APP_KEY "2B7E151628AED2A6ABF7158809CF4F3C"

bool checkBoard();
bool getDevEui(String &devEui);
bool getAppEui(String &appEui);
bool boardSetup();
bool _setAppKey(String key);
String buildPayload(String key1 = "key1", String value1 = "value1", String key2 = "key2", String value2 = "value2");


String DevEui;
String AppEui;
String AppKey = APP_KEY;
String payload;
String st;

void setup() {

Serial.begin(9600);
Serial1.begin(9600);
ds18b20.begin();

if (boardSetup())Serial.println("LoRa setup succesfull");
}

void loop() {

ds18b20.requestTemperatures();
float temperature = ds18b20.getTempCByIndex(0);
float humidity = random(1, 100);

Serial.println("Sending payload: ");
Serial.println(buildPayload("temperature", String(temperature),"humidity", String(humidity)));
Serial1.println(buildPayload("temperature", String(temperature),"humidity", String(humidity)));
while(Serial1.available() == 0);
while(Serial1.available() > 0)
{
String val = Serial1.readString();
val.trim();
Serial.println(val);
}
delay(5000);
}

String buildPayload(String key1 = "key1", String value1 = "value1", String key2 = "key2", String value2 = "value2")
{
String var1;
var1 = "AT+MSG="+ String("\"{'") + key1 + String("':") + value1 + String(",") + String("'") + key2 + String("':") + value2 + String("}\"") ;
return (var1);
}

bool boardSetup()
{
bool retVal = false;
bool init = false;
if (checkBoard())
{
Serial.println("Getting device credentials");
if (getDevEui(DevEui) && getAppEui(AppEui) && _setAppKey(AppKey)) init = true;
Serial.println("setup will now start");
}
if (init)
{

Serial1.println("AT+DR=AU915");
while(Serial1.available() == 0);
if (Serial1.available() > 0)
{
String val = Serial1.readString();
Serial.println(val);
}

Serial1.println("AT+CH=NUM,8-15");
while(Serial1.available() == 0);
if (Serial1.available() > 0)
{
String val = Serial1.readString();
Serial.println(val);
}

Serial1.println("AT+MODE=LWOTAA");
while(Serial1.available() == 0);
if (Serial1.available() > 0)
{
String val = Serial1.readString();
Serial.println(val);
}

Serial1.println("AT+JOIN");
while(Serial1.available() == 0);
if(Serial1.available() > 0)
{
String val = Serial1.readString();
Serial.println(val);
Serial.println("Waiting for joining");
while(Serial1.available() == 0);
val = Serial1.readString();
Serial.println(val);

retVal = true;
}


}
return retVal;
}

bool _setAppKey(String key)
{
bool retVal = false;
String Key = "AT+KEY=APPKEY,""\"" + key + "\"";
Serial.println("Setting AppKey");
Serial1.println(Key);
while(Serial1.available() == 0);
if (Serial1.available() > 0)
{
String val = Serial1.readString();
Serial.println(val);
retVal = true;
}
return retVal;
}

bool getDevEui(String &devEui)
{
String DevEui;
bool retVal = false;
Serial.println("getting device DevEui");
Serial1.println("AT+ID=DevEui");
while(Serial1.available() == 0);
if (Serial1.available() > 0)
{
DevEui = Serial1.readString();
DevEui.trim();
DevEui.remove(0, 13);
devEui = DevEui;
retVal = true;
Serial.print("your device's DevEui is: ");
Serial.println(DevEui);

}
return retVal;
}

bool getAppEui(String &appEui)
{
String AppEui;
bool retVal = false;
Serial.println("getting device AppEui");
Serial1.println("AT+ID=AppEui");
while(Serial1.available() == 0);
if (Serial1.available() > 0)
{
AppEui = Serial1.readString();
AppEui.trim();
AppEui.remove(0, 13);
appEui = AppEui;
retVal = true;
Serial.print("your device's AppEui is: ");
Serial.println(appEui);
}
return retVal;
}

bool checkBoard()
{
bool checkStatus = false;
String received_data; //variable to store read data

while (!checkStatus)
{
//send at command to check if there is connection with the lora module
Serial1.println("AT");
while(Serial1.available() == 0);
//case where message was received
if (Serial1.available() > 0) //check for any data received
{
received_data = Serial1.readString(); //read received data
received_data.trim();
if (received_data == "+AT: OK")
{
Serial.println(received_data); //display received data
checkStatus = true;
}
else
{
Serial.println(received_data); //display received data
Serial.print("error:");
}
}
//case where no received message
else
{
Serial.print("no data received");
}
delay(80);

}//while setup
return checkStatus;
}

Some comments on the code above:

  • You should modify the “APP_KEY” defined at line 12 to match the one you set in the registration step.

  • If you are using your sensor on another pin other than “2”, you should change the 6th line in order to match the pin that you are using.

  • It is sending data from a real DS18B20 sensor, as well as simulated humidity data (no sensor used). For this reason, you actually don't need a real sensor, you could just simulate.

Upload the code to the Arduino board by hitting the “Upload” button. Then your device will be all set up and sending data to Ubidots. Head over to the “Devices” section in your Ubidots account to check it!

image1544.png
Did this answer your question?