Calum Knott

I'm currently employed by Didactic Services, a FESTO Partner, as a Senior Applications Engineer.
I'm currently the WorldSkillsUK Mechatronics Training Manager
I'm also a Visiting Lecturer at Middlesex University
Occasionally I can be persuaded to Freelance!

Contact Me

These posts are archived
They were written with an old blogging platform, and are no longer really maintainable, however as they are linked too from various pages on the web - it seemed a good idea to try and archive them. I have written just enough code to get them to display - but there will probably be a few broken links and images.
Any major queries - feel free to contact me

ESP826, Arduino, Thingspeak

24 / 7 / 2015

This post has been written to aid in the teaching of an Arduino Course at Middlesex University.


The ESP8266 is a cheap chinese wifi module. It has recently become very popular with the Hobbiest community, mainly because of its price, but also because of its relative ease of use.

In this example, we are using the module to publish data to ThingSpeak

Technical Info

The ESP8266 can be programmed to run C-Code, In essence, it can be made to behave in a similar manor to an arduino, without any external components.

In this example, we are using the ESP8266 with the default ESPRESSIF firmware, which responds to simple commands, for example:












A more complecated command for joining an access point looks like this:







By using the serial port, we can send these commands to the ESP8266 from the arduino.


The ESP8266 is a 3.3v Device, however due to its fairly large current draw, it cannot be powered of the arduinos 3.3v supply.

We therefore need an external supply.

We SHOULD also need level shifters, but They are not 100% nessesary, and I have never used them and as of yet have not ran into problems!

The following schematic should work

You may also find the following diagram helpful:

You will also need to add any sensors you are interested in publishing.


Working, But poor quality code

First I want you to look through the code below. This code was quick and rough, it is badly structured, and exists within the setup routine. There is blocking in the espdo function, and many redundancies, However.. It works!

Much better quality code

Now lets look at the final example.

Here I have simplified the code, removed the blocking espdo() function and replaced it with a much nicer esp9266_wait() function

The Connection and data functions are now split, and comments have been added.

Feel free to expand the code below to work on your own projects.