Arduino Yun

Ubidots-Arduino-YUN is an Arduino library for interacting with Ubidots through its API. The Arduino Yun is a microcontroller board with the traditional Arduino chip (ATmega32u4) and an Atheros AR9331 that runs a Linux distro based on OpenWrt.

Requiremets

Ubidots puts time and resources to make this open source library work. However, we can’t be responsible for its stability since it runs on third-party products. Please contact the hardware manufacturer directly for any device-related inquiries.

Setup

  1. This guide assumes your Yun is connected to a WiFi network with Internet access. If not there yet, check Arduino’s guide to configure Yun’s WiFi.
  2. Go to the Arduino IDE and make sure you can upload Arduino sketches to the Yun. For example, go to File -> Examples -> 01.Basics –> Blink, check under Tools menu that the board is set to “Arduino Yun” and the port is pointing to your board (either through WiFi or serial), then upload the Blink sketch to your board. If it’s all working, you should see the LED13 pin blinking in your board.
  3. Download the ubidots-arduino-yun library.
  4. In your Arduino IDE, click on Sketch -> Include Library -> Add .ZIP Library.
  5. Select the downloaded .ZIP file and then click “Accept” or “Choose”.
  6. Close the Arduino IDE and open it again.

This library creates a Ubidots Device named “YUN” when you send variables. There the library will save your variables.

Send values to Ubidots

To send multiple values you can use our example in our library or copy the next code and do not forget to change set there your TOKEN

#include <UbidotsYUN.h>
#define TOKEN "YOUR_TOKEN_HERE"

Ubidots client(TOKEN);

void setup() {
  client.init();
  Serial.begin(9600);

}

void loop() {
  float value = analogRead(A0);
  float value1 = analogRead(A1);
  float value2 = analogRead(A2);
  client.add("Temperature", value);
  client.add("Humidity", value1);
  client.add("Heat Index", value2);
  client.sendAll();
}

Get one value from Ubidots

To get the last value of a variable from Ubidots, go to Sketch -> Examples -> UbidotsYUN library and select the “UbidotsGetValue” example.

#include <UbidotsYUN.h>
#define TOKEN "YOUR_TOKEN_HERE"
#define ID "YOUR_ID_HERE"

Ubidots client(TOKEN);

void setup() {
  client.init();
  Serial.begin(9600);
}

void loop() {
  float value = client.getValue(ID);
}

Send a value with latitude and longitude

The library has a feature to add extra information inside of a variable. In the next example, the code will send a Temperature value and inside of the variable will be saved an extra information: latitude and longitude.

Ubidots has a widget to show the position in a map. To show the position this widget need to receive the latitude and longitude in a specific format. The format is “lat” for latitude and “lng” for longitude.

// This example is to save multiple variables with context to the Ubidots API with TCP method

#include "Ubidots/Ubidots.h"


#define TOKEN "Your_Token_Here"  // Put here your Ubidots TOKEN

Ubidots ubidots(TOKEN);

void setup() {
    Serial.begin(115200);
}
void loop() {
    // Connect sensor at pin A0 of Arduino
    float value1 = analogRead(A0);
    char context[25];
    sprintf(context, "lat=%s$lng=%s", char(1.1232), char(4323.123));
    client.add("Temperature", value1, context);
    client.sendAll();
    delay(5000);
}
Did this answer your question?