Uno + ESP8266 + Cayenne


I am trying to create an IoT demo for use in schools, makerspaces etc. First my logic:

Arduino Uno - they are really common and “known”, and they have tons of pins so that I can add lots of sensors and actuators.

ESP8266 - the UNO “antenna” is made visible for explanation purposes, rather than a board that has built-in wifi.

Cayenne - desktop and mobile apps, public dashboards

I used the circuit from here: Add WiFi to Arduino UNO -
I am able to get the ESP to respond correctly to AT commands.

I created a project and added an UNO using esp8266 wifi.
I used the supplied sketch.
Got “‘Serial1’ was not declared in this scope”
The description in the sketch says “This example uses the Serial1 hardware serial pins available on the Mega”.

I then tried to find information on how to modify the sketch to use software serial.
I used:

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(0, 1); // RX, TX

// Set ESP8266 Serial object
#define EspSerial Serial
ESP8266 wifi(&EspSerial);

It compiles and uploads.

Serial says “ESP not responding”

Any suggestions?


try this code and connect esp8266 to RX and TX (Serial) of Uno.

This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield connected via a hardware serial to an Arduino.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

1. Install the library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library) from the Cayenne extras/libraries
   folder (e.g. My Documents\Arduino\libraries\CayenneMQTT\extras\libraries) to compile this example.
2. Connect the ESP8266 as a shield to your Arduino. This example uses the Serial hardware serial pins available on the UNO. 
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
4. Set the network name and password.
5. Compile and upload the sketch.
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.

NOTE: This code requires ESP8266 firmware version 1.0.0 (AT v0.22) or later.

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>

// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial

ESP8266 wifi(&EspSerial);

void setup()
  // Set ESP8266 baud rate
    Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);

void loop()

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
  // Some examples of other functions you can use to send data.
  //Cayenne.celsiusWrite(1, 22.0);
  //Cayenne.luxWrite(2, 700);
  //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
  CAYENNE_LOG("Channel %u, value %s",, getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");

This library is not stable with UNO and you won’t be able to use serial debugging. As a suggestion, you might want to use an Arduino mega to create this IoT demo for schools as it is can help with debugging and is stable .

Thanks for responding.

I tried your sketch. I am unable to complete the upload if the ESP8266 is connected.
The sketch compiles and starts uploading, but never completes.
If I disconnect the 3.3V from the esp, then the upload completes.

Even if the upload completes, Cayenne never sees the connected arduino, so I assume that it is not functioning.

Any ideas?


when you upload a sketch you need to keep both RX and TX pins of UNO empty/not unconnected. once your upload is complete you need to connect the ESP8266 back to UNO. Open your serial monitor with baud rate set to 115200. This will give you AT commands with which UNO and esp8266 are communicating.
i hope you are using a proper voltage divider.

1 Like

I did all the steps I opened the srial monitor and I am recieving AT commands but Cayenne page is still waiting the board

do not create multiple post on same topic.

sorry my mistake