ESP32 / ESP8266

Learn how to set up ESP32/ESP8266 based boards in the Arduino Cloud.

Arduino Cloud supports a wide range of ESP32 / ESP8266 based development boards. The ESP chips are great for any IoT project, and they can be programmed using the Arduino language (C++).

Setting up ESP based boards in the Arduino Cloud is quick and simple. It is done by generating a Device ID and Secret Key, which together with your Wi-Fi® credentials is enough to connect to the Arduino Cloud.

This guide will show you how to set up a generic ESP32/ESP8266 board to communicate with the Arduino Cloud.

The official guide for connecting to Arduino Cloud using the C++ environment is found here. This article is specifically for connecting ESP32/ESP8266 development boards.

Requirements

For this guide, you will need to have a registered account at Arduino. Register through the link below:

You will also need a ESP32 or ESP8266 development board.

ESP32 and ESP8266 boards are third-party boards. Arduino Cloud supports the both variations but cannot guarantee that certain boards based on these SoCs work. A list of tested and officially supported development boards can be found at here.

Setup

In this section, we will go through the steps necessary to connect your ESP32 board to the Arduino Cloud. To follow these steps, please make sure you have a registered Arduino account, and that you have access to the Arduino Cloud.

Configure Device

First navigate to Arduino Cloud - Devices. Here you can see all your devices, and configure a new one.

  1. Click on "Add Device"
  2. Select "Third Party Device"
  3. Choose your board from the list (if not there, choose e.g.
    ESP32S3 Dev Board
    ).
  4. Name your board, e.g.
    Device_ESP32_LivingRoom
    .
  5. Save your Device ID and Secret Key. This will be used to connect to the Arduino Cloud.

More details on this step is available in the Setup ESP32/ESP8266 devices.

Configure Thing

Next, navigate to the Things tab. Here you will see a list of your Things, and a button to create a new one. When you create a new Thing, you will open up a new configuration space.

Arduino Cloud Thing Interface
Arduino Cloud Thing Interface

A "Thing" is a virtual twin of your hardware, and it is here that we create variables that we want to synchronize between the Cloud and board. Any changes we make here will be reflected in an automatically generated sketch.

  1. First, let's attach the device we want to use, by clicking the "Select Device" button in the "Associated Devices" section to the right.
  2. let's create a new variable, call it
    test
    , and select it to be a
    boolean
    type and with a read/write permission.
  3. finally, configure your network in the Network section. Here you will enter your Wi-Fi® credentials, and your Secret Key, obtained when configuring your device.
Enter network credentials.
Enter network credentials.

All the above configurations have now been generated into a set of files that can be accessed in the Sketch tab.

For more details, see the documentation for Things.

The automatically generated sketch is now available to be edited. This sketch includes all necessities to connect to the Cloud, and has a callback function generated for each read/write variable.

Below is a sketch generated for a single

boolean
variable called
test
. We modified it to turn on/off the built-in LED of the board anytime the
test
bool is
true
.

1#include "thingProperties.h"
2
3void setup() {
4 pinMode(LED_BUILTIN, OUTPUT);
5
6 Serial.begin(9600);
7 delay(1500);
8
9 initProperties();
10
11 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
12
13 setDebugMessageLevel(2);
14 ArduinoCloud.printDebugInfo();
15}
16
17void loop() {
18 ArduinoCloud.update();
19}
20
21void onTestChange() {
22 if(test){
23 digitalWrite(LED_BUILTIN, HIGH);
24 }
25 else{
26 digitalWrite(LED_BUILTIN, LOW);
27 }
28}
  • The sketch is automatically updated whenever you change your Thing (e.g. adding a variable, changing device),
  • Read/Write permission variables adds a callback function to the bottom of your code. This function executes whenever the variable changes,
  • the
    ArduinoCloud.update()
    function synchronises data between the board and Cloud.
  • if we update the
    test
    variable in the sketch, if it is connected to the Cloud, we will see the change there as well.

Compile & Upload

When our sketch is ready, we can compile & upload our sketch to our board. This process can take some time, depending on how large your sketch is.

  1. First make sure that you have the Create Agent installed. This allows Arduino Cloud to communicate with your board in the web interface.
  2. Check that your board is connected and visible in the board selection menu.
  3. Click the verify/upload button.
  4. Wait until the code has successfully been uploaded.
  5. Open the serial monitor tool to check for debug messages. If your board is failing to connect, it will print the errors here.

Verify Connection

After a complete upload, you can verify the connection by checking the Thing interface. Here you can see the latest value & time stamp, as well as your device status (online/offline).

In this case, we have just a single boolean variable named

test
, which is used to switch the state of the built-in LED.

To control the state of the

test
variable, we can setup a dashboard and a switch widget. This will allow us to control the LED remotely.

  1. Go to Dashboards, and create a new dashboard.
  2. Click on the edit button at the top left, then on the "Add" button. Select the Thing you want to associate it with, and then click on "Create Widgets".
  3. A switch widget will have generated, which is now linked to your board. Flicking it should control the state of the LED (on/off).
Dashboard in the Arduino Cloud.
Dashboard in the Arduino Cloud.

You can find more details in the dashboards documentation.

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.

ON THIS PAGE