Program an ESP01: The easy way!

Hello world! This article marks the first post on this website, the ancestor to all that follows and the one that will start it all. And what better topic to start with than learning how to dip your toes into the exciting field of Internet of Things!

In this post we will be looking at a super awesome chipset that you can use to start your IoT projects right away, $6 and some spare time is all you need! So, without further delay let me introduce you to the star of the show: ESP01.

ESP 01 Module

So there you go, isn’t he handsome? (or is it a she?). Its a tiny package that has WiFi transceiver built in and costs around $3. When it was introduced first by a company called expressif, people used it as a sidekick to the Arduino Uno/Mega and similar boards that were already a maker’s staple at that time (and still is). The humble device was used to help these common boards connect to the internet via WiFi.

But behind that tiny frame resides a super powerful processor that could put those boards to shame! It has a 32 bit microprocessor built in which can run up to 160MHz, compare that to an Uno which has an 8 bit chip and runs at 16MHz. So not a sidekick but a hero in disguise. Let me now put down the specs for those with a more technical inclination:

  • Power Supply: +3.3V only
  • Current Consumption: 100mA
  • I/O Voltage:  3.6V (max)
  • I/O source current: 12mA (max)
  • Built-in low power 32-bit MCU @ 80MHz
  • 512kB Flash Memory
  • Can be used as Station or Access Point or both combined 802.11 b/g/n
  • Supports Deep sleep (<10uA)
  • Supports serial communication hence compatible with many development platform like Arduino
  • Can be programmed using Arduino IDE or AT-commands or Lua Script

Ok, now that’s that and what’s the takeaway? Look at the last point. Yes, you can use your Arduino IDE to code this guy! And that’s how it became popular. Today you can program it using Micropython as well, but that’s gonna be a different post. So, should you throw your Uno into that recycle bin? NO. Even though ESP01 is very handy, it has a lot of limitations. First, it has only two GPIOs compared to 14 on Uno. Also no SPI, PWM and stuff. You have an RX and TX pin for serial communication, those can also be used as GPIOs if you are so inclined, at the cost of not being able to debug it with serial. It is also not breadboard friendly. Let me show you the pinout for a better understanding:

It is to be noted that ESP01 is just one avatar of ESP8266 based chipsets, some like the Node MCU has 11 GPIOs with SPI, I2C, PWM and all those bells and whistles. We will try to explore this family in later posts.

Yeah nuff chit chat, lets code it shall we? There are a number of ways out there, but in this post we will take a look at the method I use, and in my opinion it is the easiest one. All you need is a $3 CH340 USB Serial Communication Module. Here is a picture:

CH340 USB Serial Communication Module

This stuff makes programming plug and play. But there is a caveat, you need some soldering to get it to work due to the way an ESP01 has to be handled on boot to get it into programming mode. Fear not, Its a simple trick and we just need a push button switch soldered at the right place. And that is between GPIO0 and GND. The theory is that, the ESP01 GPIO0 has to be pulled to the ground on startup to get it to accept code. Here is a module I have prepared:

Now follow these steps to get your first sketch into ESP01:

  1. Connect ESP01 to the CH340 Module we have prepared.

2. Push and hold the button and insert it into your PC, then release it.

3. Download and install CH340 Drivers from here, google it if this link doesn’t work for you, it is easy to find.

4. Download and install Arduino IDE from here.

5. Go to File>Preferences, locate ‘Additional Boards Manager URLs‘ tab and paste ‘‘ into it without the quotes and click on OK.

6. Go to Tools>Boards>Board>Boards Manager… Don’t worry if the window doesn’t look the same as below, you might have something else written on Board:”” part.

7. Search for ‘esp8266’ in the search box and then click install button on the entry titled ‘esp8266 by ESP8266 Community’.

8. Once the installation is done close the window and then go to Tools>Board>ESP8266 Boards> and select ‘Generic ESP8266 Module’.

9. Go to Tools>Port> and select the right COM port, yours might be named differently. Check your device manager on windows if you are confused.

10. We will now try and upload an example sketch which will show you the networks in your area. Go to File>Examples>ESP8266WiFi> and click on WiFiScan.

11. Once the sketch window opens, click on the upload button.

12. The IDE will compile the code and upload the sketch into your ESP01 module. Once it is uploaded take out the CH340 module and plug it back in, this time without pressing the button, the CH340 module can now be used as a serial communication device.

13. Go to your IDE and click on the serial monitor button on the top right corner. That will launch your serial monitor and you can see the networks being listed there!

14. Try your own code and enjoy!

There you go, you have learned how to program ESP01! I hope you enjoyed this post.

Interested in starting right away? Use the following affiliate links to buy the ESP01 module and/or ESP01 Programmer from Amazon, if it doesn’t cost you any extra.

  1. ESP01 :
  2. ESP01 Programmer :

See you in the next one!