>

ESP8266 as stand-alone Module

The ESP8266 is a low-cost WiFi module built by Espressif Systems. Its popularity has been growing among the hardware community thanks to it’s nice features and stability, to the point that it can be easily programmed using your Arduino IDE.

In this post, we’ll learn how to program your ESP8266 using an UARTbee or Arduino UNO, and the Arduino IDE.

Requirements

Wire up

  • First we’ll need to identify the pinout of ESP8266.

ESP8266 UARTbee Arduino UNO
RXD TXD RX
GPIO0 GND GND
GPIO2
GND GND GND
VCC 3.3V 3.3V
RST
CH_PD 3.3V 3.3V
TXD RXD TX

Note: If you are using an Arduino UNO you will need to set Arduino RST to GND. Please be careful with the VCC of the ESP8266, it works only with a 3.3V supply.

Setup

  1. Download Arduino IDE.
  2. Open you IDE and click on File -> Preferences.
  3. In Aditional Boards Manager URLs add this line and click on “OK”: “http://arduino.esp8266.com/stable/package_esp8266com_index.json”
  4. Go to Tools -> Board -> Boards Manager, type “ESP8266” and install it.
  5. Go againt to Tools -> Board and select “Generic ESP8266 Module”.
  6. Download the UbidotsMicroESP8266 library here
  7. Go to the Arduino IDE, click on Sketch -> Include Library -> Add .ZIP Library
  8. Select the .ZIP file of the ESP8266 library and then “Accept” or “Choose”
  9. Close the Arduino IDE and open it again.

Send one value to Ubidots

The next code is an example that send a Temperature value to the Ubidots variable. The device read a sensor via Analog Pin A0. If you want to use this example don’t forget to change TOKEN, WIFISSID and PASSWORD.

#include "UbidotsMicroESP8266.h"
#define TOKEN  "Your_token_here"  // Put here your Ubidots TOKEN
#define WIFISSID "Your_WiFi_SSID"
#define PASSWORD "Your_WiFi_Password"

Ubidots client(TOKEN);

void setup(){
    Serial.begin(115200);
    delay(10);
    client.wifiConnection(WIFISSID, PASSWORD);
}
void loop(){
    float value = analogRead(A0);
    client.add("Temperature", value);
    client.sendAll(true);
}

Get one value from Ubidots

The next code explain how to get the last value of a Ubidots value, the code will save the value inside “value” variable. If you want to use this example don’t forget to change TOKEN, WIFISSID and PASSWORD.

#include "UbidotsMicroESP8266.h"
#define TOKEN  "Your_token_here"  // Put here your Ubidots TOKEN
#define ID "xxaaaaaxxxxx"  // Variable ID of Ubidots
#define WIFISSID "Your_WiFi_SSID"
#define PASSWORD "Your_WiFi_Password"

Ubidots client(TOKEN);


void setup() {
    Serial.begin(115200);
    delay(10);
    client.wifiConnection(WIFISSID, PASSWORD);
}

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

Send multiple values to Ubidots

In the next code, we will send three values of diferents sensors. If you want to use this example don’t forget to change TOKEN, WIFISSID and PASSWORD.

#include "UbidotsMicroESP8266.h"
#define TOKEN  "Your_token_here"  // Put here your Ubidots TOKEN
#define WIFISSID "Your_WiFi_SSID"
#define PASSWORD "Your_WiFi_Password"

Ubidots client(TOKEN);

void setup(){
    Serial.begin(115200);
    delay(10);
    client.wifiConnection(WIFISSID, PASSWORD);
}
void loop(){
    float value = analogRead(A0);
    float value2 = analogRead(A1);
    float value3 = analogRead(A2);
    client.add("Temperature", value);
    client.add("Humidity", value2);
    client.add("Heat Index", value3);
    client.sendAll(true);
}

GET STARTED
Join thousands of fellow IoT developers using Ubidots to build production-ready IoT solutions.

Sign up for free