ESP8266 ESP-01 WIFI Shield for Arduino

Just to start off and getting everyone up to speed on my suggestion: I have developed a control that controls the crockpot from a remote location using Blynk. You would think this is a simple task but it isn’t. The idea is to maintain the temperature in the crockpot below the point where the meat cells burst. If the temperature is too high, the cells burst and the result is a dry taste to the meat. You also want to bring this pot up to temperature as quickly as possible to reduce the cook time. So, I switched from a simple bang bang control to a PID control. This was not easy. There are about 5 heat transition points in this system starting from the heating element, the air, the thick ceramic crockpot, the liquid and the sheath on the thermistor. Together this results in a 5 minute lag between the turn-on of the element and the heat reaching the thermistor. The NANO was selected because I wish to use this configuration for other projects. Connecting the WIFI ESP-01 to NANO was a small challenge.

My wife loves it. She fills the pot, plugs it in, goes to work. At work, she can programme the start time and cook time, start it, gets confirmation that it has started and and view the temperature in the pot. When she’s gets home, it is perfectly cooked. I don’t like Blynk. Text is small and you have to pay for their services in a sneaky way.after you reach a limit.

Now… the ESP8266 has many configurations. The ESP-01 is the smallest and is best suited to fill the role of a WIFI shield for a controller. This is probably the reason why it has only two digital I/O pins. The ESP-01 comes with the AT Firmware preinstalled. Now this is very important to understand. You can serially connected (TTL 3.3V on ESP.01 RX) and send AT commands with the expected replies. What some people do is overwrite this programme with a control sketch to play with the two pins. Then try to use it as a WIFI shield and find that it no longer communicates with AT commands. You have to download that AT firmware once again. And it isn’t that easily available. So in a nutshell, don’t touch it. Leave it alone. At $2 a pop, it’s a great WIFI shield for a NANO.

I used Blynk’s .h library to connect ESP-01/NANO to their servers. Great. If you like I can reply with a sketch I used. There are two in fact. The first is completely automated. The second requires some coding but the advantage is you can control how the system recovers when WIFI/power is lost. The second is the best bet to connect to Cayenne if you don’t want to connect to Blynk’s servers.

What I don’t see is that option here at Cayenne. When I pull up Arduino and specifically NANO and look for the ESP-01 shield, I don’t see it. There is an ESP8266 stand alone but I’m not interested in that. Remember that the ESP-01 comes preprogrammed with the AT Firmware and I want to leave it intact so the stand alone ESP8266 - ?? is not an option. I have been searching this community for a “quick fix” and that hasn’t resulted in anything I could use. Almost all topics center on using the ESP8266 as a stand alone controller. Actually, all the topics do.

So, what I ask is this… is there a topic I missed that explains how to configure the Arduino with an ESP-01 WIFI shield to work with Cayenne? If not, does anyone wish to write one? Or am I on my own and have to come up with a fix?

Welcome to Cayenne!

It’s a bit hidden, but here it is. I agree that eventually there should be some official support, but for now this is how you do it. Let me know if that helps!

Thank you, Adam.

Good news and bad news.

The good news is that you people are doing something.

The bad news is that this is not a complete solution for my setup.

Let me explain: The solution given uses two hardware serial ports. There are a couple of Arduino’s that have that, like the Leonardo (TTL RX TX identified as Serial1). But, the NANO does not. We get around this by using software serial. SoftwareSerial.h is built into the Arduino IDE. Now… the other problem is that although they say softwareSerial will work on any pins up to 115200 baud… in truth for the NANO it does not. We have to slow down the ESP8266-01 to 9600 baud. The easiest way to do that is to simply use a TTL USB serial cable to connect to the ESP with a 3.3 power supply and voltage divider on ESP RX (I have a 3.3 RX TX version). Testing the connection with Arduino Monitor set at 115200 with AT should get a response OK. If not… you pick the next speed. Sometimes its 57600. If you do, you send a command AT+CIOBAUD 9600. Then change Monitor to 9600 and hook up again. AT > OK. To test the radio, AT+CWLAP will list all the available networks in the range of the ESP.

You now connect the ESP to NANO. I identified DO pins 10 and 11 as my communication port to work with ESP. That now allows me to use the USB port to monitor Serial.print messages.

This is the programme I use to test the setup. I don’t know who wrote it. But it’s a simple programme. This is also how Blynk works around it. Now I took a peak at a couple of header library files that Cayenne and Blynk have written… and I’m not going to reverse engineer this stuff. Unless you know what was in the programmer’s mind, it’s difficult to follow. So, what I’m asking you do to is to try to work it out using SoftwareSerial? I’d love to test out Cayenne with NANO and ESP-01. Otherwise, I notice you don’t have MKR1000 included. That would have been my other choice. I firmly believe this is important for Cayenne to have startup examples that cover either one. Preferably both.

// Basic serial communication with ESP8266
// Uses serial monitor for communication with ESP8266
// Pins
// Arduino pin 2 (RX) to ESP8266 TX
// Arduino pin 3 to voltage divider then to ESP8266 RX
// Connect GND from the Arduiono to GND on the ESP8266
// Pull ESP8266 CH_PD HIGH
// When a command is entered in to the serial monitor on the computer
// the Arduino will relay it to the ESP8266

#include <SoftwareSerial.h>
SoftwareSerial ESPserial(10, 11); // RX | TX

void setup()
Serial.begin(9600); // communication with the host computer
//while (!Serial) { ; }

// Start the software serial for communication with the ESP8266

Serial.println("Remember to to set Both NL & CR in the serial monitor.");


void loop()
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ); }

// listen for user input and send it to the ESP8266
if ( Serial.available() )       {  ESPserial.write( );  }


Hi @fred2013ies, welcome to the Cayenne Community!

We do have MKR1000 support through our MQTT API, if you add the device as “Bring Your Own Thing” rather than through the Arduino menu in the Cayenne UI. Here is the sketch in question, and the whole library itself.

That sketch has some commented example code to show how you can send and receive sensor and actuator data to our platform, and can of course be extended upon. This might be a simpler solution than tethering an ESP to an Arduino board and troubleshooting that communication.

1 Like


It is possible to setup debug on the software serial port and leave the hardware port for the Cayenne libraries to connect to the ESP. The ESP stuff is not for the faint of heart. There are multiple variants, and multiple firmwares, and that is why ESPs are only officially supported as standalone right now.


Thanks. I’ll look it up. On the issue of NANO… got it working. What I did was put the ESP on the TTL TX RX pins and use softwareSerial to set up pins for diagnostics and put my TTL cable there. It works!!

1 Like


I used software serial to setup a monitoring port and used my TTL cable to connect to the PC. The ESP-01 was connected to the NANO RX TX pins after the download. The ESP is a heavyweight and by sticking to hardware it would solve my problems. Monitoring the software serial port wasn’t a biggie so using softwareSerial.h there was a good choice. When I started it up, the MONITOR used the USB port that the TTL cable was on and displayed a message I set up. The native RXTX port connected to ESP and was able to connect to your servers. I then went ahead and designed my first dashboard… DO pin 13 to turn on and off. Hello World lives!!!

You people should write this up properly and put it in the Newbie setup pages.

In any event… the setup of one ESP-01/Chinese NANO and the tiny 3.3 V PS cost me under $10 USD.

1 Like

Graig… This just arrived in my email and I immediately thought of you. :grinning: I understand what you mean about the AT firmware that differs from one manufacturer to another… generally I find the new stuff pretty consistent. It is possible to upgrade the AT firmware on ESP but that’s another story. ESP is shooting up like a rocket and I hate to see Cayenne miss out on the excitement. Hackster ESP8266 Contest But WAIT… I see My Devices in as a sponsor. You sly devil you.



The handsome fella on the right is not @bestes. He’s the other one.



1 Like

Hi @fred2013ies, I am a newby in IOT and I am working on a class project since weeks and could not be able to get thing worked. Your solutions should help end my project in schedule. Coud you please email me your source code or post it here? Thank you in advance.


See this post

@adam @shingyfetue @kreggly @rsiegel Hey guys. We just provided support in our MQTT Arduino library for using ESP8266 as a shield :slight_smile: We’ve done basic testing and works well. Give it a try for your project and let us know how it works out for you !

Here is the updated library on our github:

and the code can be found here:



I’m terribly sorry. This is now July 2018. Obviously I’m late.

Well… it’s been some time since I’ve tackled Cayenne. Long story short, I’m writing a book for engineers who find themselves in need to build automated test jigs. I’ve been using Arduino as the muscle to actuate and listen. Used for the HMI on a PC communicating to the Arduino via BlueTooth. Now I’m interested in iOS smart phone hookups. I was going to go with BLYNK but I thought I’d give Cayenne another try. Three days I’ve been trying to get an Arduino NANO with a ESP-01 to work properly. The best I could do is turn on that pesky LED but then the Cayenne button hangs up. Yes, the LED on pin 10 turned on. But that Cayenne button had the “I’m busy circle” go round and round and round.

The first time setup docs have errors when it comes to installing libraries on Arduino IDE. “Cayenne” library no long exist. You have CayenneLPP, CayenneLPPDEC and CayenneMQTT. Obviously the problem here is just plain confusion for a novice. The sketches for a NANO shows two serial ports when there’s just one. This line must be changed to reflect the only serial port #define EspSerial Serial1. Serial1 must be changed to Serial or it won’t compile. You may think, “What’s the problem?” The problem is that I picked a NANO sketch from the provided list and I expected Serial instead of Serial1. You may notice that there are other code lines expecting a second serial port to monitor. Unless you use a software serial port with a TTL cable to feed back to the PC/Monitor, this isn’t going to happen. This is just what you need to turn people off.

So as it was three years ago you guys are still messed up. What takes 20 minutes on BLYNK takes 3 days with Cayenne. You really have to fix this.

As for me… I’m going to pay for the extra BLYNK wigets to get this book completed. I’ll promote BLYNK.

Take Care, Gentlemen.

you should have a look at the intro of the sketch (point 2) it mentions Connect the ESP8266 as a shield to your Arduino. This example uses the Serial1 hardware serial pins available on the Mega. You can also try using a software serial, though it may be less stable.
this is because, we have tired to have a stable code for only one serial port and it does not work. but if you search the forum a bit more then you will find solution for it.
You are free to choice any software which you want. Go ahead.
Thank You.

Actually, I did. I read everything. However, imagine this. A sketch is provided from a pulldown list SPECIFICALLY for a particular microcontroller that has only one serial port. You would expect that the programme/sketch would reflect that. But no. What we have is an assignment to a second serial port that doesn’t exist. I noticed this right away when the compiler refused to accept it. Now you wonder, if the compiler terminated, why didn’t Cayenne pick up on it? For a novice it is confusion. There are, of course, other issues such as the confusion with the libraries. A search on the internet will confirm this.

This is what I do for NANO for stability… I assigned the ESP port to the UART port D0 and D1. This is the hardware port (TTL) which is shared with the USB port and it easily handles the higher baud rates. I then assign the SerialSoftware port to D12 and D13 and reduce the baud rate to 9600. This I feed to the PC via a USB/TTL cable to a Putty terminal and now I can display status and debugging. This is perfect. The only trick is to disconnect the ESP-01 TX/RX when programming the NANO. For that, I just use a couple of switches. I mention this technique in an earlier comment on the thread some 3 years ago.

Going back to Blynk… They too seem to go with this SerialSoftware connection to ESP-01. The only logical explanation is this is the USB port shared with UART TX/RX. In any event, it was easy to source and install their master library that included BlynkSimpleShieldEsp8266.h and ESP8266_Lib.h. Within an hour I had a demo programme running that provided feedback on the Putty terminal of when the two ports were turned on, connection to the server was made, the APP designed and indication on the Putty when the APP on the iPhone was activated and deactivated. And the LED turned on and off when I pressed it immediately.

This is where Cayenne fails. The internet is littered with outdated instructions and the Github doesn’t provide up-to-date instructions reflecting at the very least the correct libraries to install in the Arduino IDE.

Now you have to ask yourself… same basic technology and approach. Then why is it that Blynk works and Cayenne doesn’t when starting up for the first time. There’s a couple of hiccups with Blynk that you can capitalize on but honestly, you have to clean up your act.

This is because we had not fully support esp as shield for single hardware serial port and the code in github is only specific to mega. the pulldown gets this code for mega.

you can send a push request if you want or send me a details list, we can test it out and add it. As cayenne is free we need the community to build it up. If you have just added a new topic on “how to connect Arduino Uno with esp8266” then it would help the community, just the same way you are writing the book for engineers in need as you mentioned above.

i am not sure, what you referring to but the cayenne Arduino GitHub library is pretty upto date and also as i mentioned earlier you can send a pull request for what you think is missing.

i simple answer is cayenne is free and depends on the user how they use it.

Hello Shramik_salgaunkar… well… its not a freebee. Cayenne is used to direct potential customers to myDevices and for branding. But yes, for hobbiests, it is free. I’m not complaining. And I would love to add Cayenne/myDevices in my book. It would get more traffic to flow to myDevices.

Let me illustrate to you my experience.

Go to Cayenne Features - Developer | On the left, click on “Downloads”. Under Cayenne Arduino Libraries, click on the link, “Downloading…”. The link points to the same originating page. You recirculate. What in the world was the intent of this link? Hasn’t anyone brought this issue to Cayenne’s attention? So what do to?

A savvy techie might know about Github.

Github… a search for Cayenne yields this: GitHub - myDevicesIoT/Cayenne-MQTT-ESP: Cayenne MQTT ESP8266, ESP32 & NodeMCU Library. This looks promising… a lot better than three years ago. But not quite what you want. So you move on and find this… GitHub - myDevicesIoT/Cayenne-MQTT-Arduino: Cayenne MQTT Arduino Library. Just a note, the ESP8266-01 is the ESP-01 with preinstalled AT commands.

Following the instructions on this GitHub page requires the installation of the CayenneMQTT library. After that, the Cayenne setup. And following that, the example: File → Examples → CayenneMQTT → Connections. Since we’re using the ESP8266-01 as a sheild, I would assume the ESP8266Shield example. Moving along, we find the following in the sketch:

//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space

We can’t have this. We have only one serial port. If we’re sending debug strings on the same port for ESP, we can mess things up. It must be commmented out with an explanation why and allow the Newbie the option to activate it.

Next we have:

#define EspSerial Serial1

This won’t work. NANO had only one serial. Hence, #define EspSerial Serial. The steps above are really a little hazy. Good comments here would go a long way because the compiler will catch it.

Next we compile for the first time. We get this:

C:\Users\fred2\OneDrive\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTESP8266Shield.h:31:10: fatal error: ESP8266SerialLibrary.h: No such file or directory

#include “ESP8266SerialLibrary.h”

CayenneMQTT doesn’t have it. Oh, but it does… in Extra directory → libraries → It was also explained up in the comments. Ohhhh… now I get it. Perhaps we should put that library in as a standard? Why make it an extra? There may be a reason and I’d like to know it.

So lets install the zip library.

We compile again and get this:

C:\Users\fred2\OneDrive\Documents\Arduino\libraries\CayenneMQTT\examples\Connections\ESP8266Shield\ESP8266Shield.ino:43:2: note: in expansion of macro ‘EspSerial’


We definitely have to change that Serial1 port to Serial. Doing that allows the compiling to complete successfully. But a comment at this line would have helped.

So lets upload to NANO (with the TX/RX disconnect to ESP-01), fire it up and see what happens on the dashboard. By the way, if you don’t disconnect ESP-01, it won’t upload.

Well, naturally it isn’t going to connect because the username, password, etc etc isn’t installed. The steps gave a vague idea. So now we need to move from Github and back to Cayenne. So there’s a bit of a disconnect between Cayenne Docs and Github. Alright. We put in a new project per the Docs. We pick Arduino NANO and decide on the only option that makes sense, Arduino ESP8266 WIFI. Clicking on it brings up the sketch with the username, etc, etc, preinstalled. However, with bad luck, we could have used WIFI Shield. This programme doesn’t use the CayenneMQTTESP8266Sheild.h library. Also, it uses two ports a little differently. For a newbie, he could be spinning his wheels for some time with this. So going back to the Arduino ESP8255 WIFI, we find it to be a carbon copy of the sketch we’ve been working on.

We upload again. And fire it up.

It connects!!!

Now what? The Github doesn’t say much. So it’s back to the Cayenne docs again.

We start up at Downloads. We know this is broken and simply move on to Getting Started.

We’ve already stumbled on this when we secured the necessary credentials. We continue with the instructions skipping Choose Device and head for Arduino. This is pretty much a rehash of Github. However, when we get to libraries… it gets tricky. Cayenne by myDevices library no longer exists. CayenneMQTT does along with other Cayenne libraries. Now we have confussion. These Docs do not reflect what went on in GitHub and the present libraries. If the Newbie was not aware of Github, he could be spinning his wheels right about now surfing the internet and support pages.

Lets continue with Docs. At Sensors we find what we need. We are going to light up an LED. We pick a light switch. Assign it to NANO, channel 1 with a button. Pulling up the sketch we are hit with yet another surprise.

Whereas the original sketch that allowed for connection shows this:

#include <CayenneMQTTESP8266Shield.h>

The new sketch for the NANO with a ESP shield shows this instead:

#include <CayenneMQTTEthernet.h>

Of course, the ssid and password no longer exist.

The rest of the new sketch shows this:

#define VIRTUAL_CHANNEL undefined
#define ACTUATOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.

void setup()
Cayenne.begin(username, password, clientID);

void loop()

// This function is called when data is sent from Cayenne.
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN, value);
//End of sketch

Whereas the sketch that allowed us to hookup was this:

#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”);
//End of sketch

Obviously, there’s some hacking to do. But what needs to get hacked?

At this point, the demo has become a complete mess. Experimentation may yield something that may work, or partially work. But the frustration starts to take a liftoff.

In closing, I would like to say that the demo for Arduino with an ESP shield must be a stand alone document. It should be able to guide the Newbie through from start to finish to make his first connection in a reasonable amount of time with as little stress as possible. Arduino UNO and NANO are very common as well as ESP-01. Everyone has one. Why not work it properly? NANO 33 IoT is fairly new.

I haven’t tried the other modes of connections. I do have ESPs that can be programmed to control on their own (sufficient I/Os) without Arduino and MKR1000. But I wanted to use a $5 NANO hooked up to a $3 ESP-01 to demonstrate a fully functional WIFI/Internet microcontroller. And I can do that quite easily with Blynk.

If you like, please direct me to a person in myDevices who might be of assistance. I would be more than happy to work with that person to iron this out. In exchange, if favourable, assistance to me to put Cayenne in my book. Otherwise, lets call it a day.

well, good you know it. We have to do some earning while providing the best free platform we can. I guess not like other platform, we have the entire cayenne platform free of charge.
It is okay, if you dont add cayenne in your book as you had bad experience with it.

Thanks for bringing this up, and will have it fixed as no one pointed this out before you.

Maybe check the last updated date or the forum to see which is listed more.

For the esp-01 as shiled there is a note which mention it is for arduino mega, i only see one issue at our end that, not to populate this code when the sketch is promted in the cayenne dashboard while adding the device (will have this fixed. thanks for reporting)

if you are willing to share a “how to do” tutorial as you have got it working, it would be more then helpful for newbie users.

You can private message if you want to.

you can point out the issue you have and we can work them out.