This is one of my older ESP8266 articles. Please check out my more recent ESP8266 projects below:
The ESP8266 WiFi Module
The ESP8266 is a WiFi module that costs less than 5 USD. This makes putting your sensors on the net actually feasible. (Hooking up the $75 Arduino Yun to each of your sensors - not no feasible.) There’s a lot of excitement about this sensor on the Internet currently, and people have done an amazing job deciphering the obscure command structure of this device that comes from China. There seems to be three ways of using this module, in order of increasing complexity:
- Sending it AT commands from a computer via an USB to serial adapter. This is mostly useful for testing and setup.
- Interfacing with an Arduino or any other microcontoller and using this board as a peripheral.
- Programming the module directly and use its GPIO pins to talk to your sensors, eliminating the need for a second controller.
I’ve explored options #1 and #2 above, and that’s what I’ll be talking about here. If you are new to this whole thing, I recommend that you watch this video from Great Scott Labs first.
Setting up the ESP8266
The first thing you want to do with ESP8266 (as with any aliens) is to establish communication. For this, you hook up a USB to TTL adapter to the module, and talk to it using a serial port terminal application like CoolTerm. One thing to be careful about when you hook up this module is to remember that this module operates at 3.3 V - even the serial lines should not exceed this voltage. So here is how I hooked up my ESP8266:
In the above circuit, you can see that I used a 3.3 V regulator to power the board, and a resistor dividor on the RX line to keep the voltages on spec. The sessions below use CoolTerm. My board worked with a baud rate of 9600, since its firmware was already upgraded to 0.9.2.2. You may need to try other baud rates - 115200, for instance.
Now, you can send it AT commands. You can see the full command reference here. First let’s send “AT”:
Now let’s get the firmware version:
Now, let’s get the operation mode.
3 implies that we are in Standalone + Access Point mode. That’s fine. Now, let’s do something fun. Let’s list all the available WiFi access points.
Now let’s connect to my WiFi network.
Now, let’s check if we actually got an IP address:
Whoohoo! We are on the network. We’ll actually make use of the Internet in the next section. Also, the above settings are now actually stored in the module. Even if you power it on and off, it will connect automatically to this network.
LM35 Temperature Plot using an Arduino
Now that we have put the module on the network, let’s make use of it by creating a small IoT (Internet of Things) device. I had written a previous post on plotting sensor data on ThingSpeak. This time, I’ll use an LM35 temperature sensor. I’ll talk to the ESP8266 using an Arduino Mini Pro clone. Here’s what the LM35 looks like:
In the code below, I use the SoftwareSerial library to talk to the ESP8266. I use the hardware Serial for debugging. (You could try the opposite.) I also assume that the ESP8266 is already setup to connect to the WiFi network.
In the code above, I read the analog pin, compute the temperature, and send that information to a ThingSpeak channel via a GET request.
Here is how the circuit is hooked up. I am using a cheap Arduino Pro Mini clone for this experiment, and the battery is a rechargeable one meant for charging cell phones.
And here is the plot at thingspeak.com:
I think this module is great value for the money. A very practical way of putting your sensors on the Internet. Although this module can be programmed directly, I’ll probably just use it as a peripheral due to the ease of using it that way.
- A nice introductory video from Great Scott Labs about the ESP8266.
- Seeed Studio article on Getting Started with ESP8266.
- electrodragon’s web page on the ESP8266.
- ThingSpeak website.
- My small project on using ThingsSpeak to plot sensor data.
- esptool.py - a Python script to update firmware.
- CoolTerm - nice serial terminal software.
We love hearing from our readers. Email us at email@example.com for questions or comments on this article. If you found this article useful, please support us by buying some of our Open Source hardware products - like ZeroDriver - an Arduino Zero compatible motor driver for robotics. ZeroDriver is crowdfunding right now. Please click here to support our campaign. and bring this product to market!