IoT Data Logger with ESP8266 – part 1

The Internet of Things space has never been more active. Ethernet/WiFi shields for non-connected Arduino boards like the UNO or the Leonardo were quite expensive, and the Arduino YUN, which has Bluetooth and WiFi connectivity, costs at least seven times as much as an UNO. A Chinese company called Espressif came out with a new module, called the ESP8266, which included WiFi capabilities, and costs below $5, which is about 300 rupees in India. This essentially connects your Arduino to the internet for just 300 rupees more. You can set up a wireless data logger for $20 or about 1200 rupees!

I got two new ESP8266 WiFi modules from here. They can act as WiFi access points or WiFi clients, which allows me to upload sensor data from the Arduino to a cloud server, from where any computer anywhere in the world can access it. I used Mathwork’s (MATLAB’s parent company) ThingSpeak cloud platform for uploading data.

To make my IoT device, I used:

  1. Arduino UNO board (or any higher version board)
  2. ESP8266 12E WiFi module
  3. Any Arduino cellphone charger
  4. CP2102 USB to Serial converter (for debugging)
  5. Breadboard (for prototyping)
  6. Grove VOC sensor (from SeeedStudio)

There are at least 12 different versions of the ESP8266 board being manufactured, and mine is the 12E version. The one I bought had the Serial pins for FTDI broken out to a separate header, which was quite useful for debugging. Another important point to note is that the WiFi connection requires a lot of power, in my case, 5V voltage and around 300-700mA while connecting to a WiFi network and sending data to the cloud. The Arduino UNO cannot provide more than 40 mA current from a single pin. It needs an external DC power supply. So I took a standard Android cellphone charger (5V, 700mA) and cut off the micro-USB end, and soldered jumper wires to the positive and negative strands. This was able to provide enough power for the ESP8266.

The ESP8266 modules operate at different baud rates, depending on the firmware they are running. The ones I have are from Explore Embedded, and are the popular AI-Thinker boards. They have been flashed with the ESP8266 IoT firmware, so the URL doesn’t show up when I send commands to it. Some experimentation with the USB to Serial converter provided some insights. Connect the 5V and GND on the ESP8266 to the cellphone charger wires, and the FTDI header pins 5V and GND to their counterparts on the CP2102. Connect RX to TX and TX to RX from the ESP8266 to the CP2102.

Connect the CP2102 to the computer and power up the ESP8266. Open the Arduino software, and choose the serial port (USB) that shows up. Open the Serial Monitor and choose NL and CR (newline and carriage return) in the options below the window. Change the baudrate and reset the module using the hardware switch until you see a “ready” response. Try looking through your module’s datasheet, if it is provided by the seller. Mine communicates at 115200 baud.

There is a set of AT commands used to communicate with the ESP8266. As soon as you identify the correct baud rate for the module, send it an AT command. It will respond with an OK. If you see garbage on the screen, try resetting the module, or checking your baud rate. Make sure the NL and CR option is set.

After seeing the OK response, send AT+RST, to which the immediate response is OK, then there is a delayed response after about half a second, which prints several lines of information about the module, ending with the word ready.

To check your firmware version, send AT+GMR. Search for WiFi access points in the vicinity using AT+CWLAP. This lists nearby access points within 5 seconds. To join a known access point, send AT+CWJAP=”WiFiSSID”,”WiFipassword”, having replaced the fields in quotes with your WiFi SSID and password. After each of these commands, the module responds with an OK.

To connect to, you need an API key. So I made an account on (for free) and created a channel with one field. To upload data to ThingSpeak, you need to send AT+CIPSTART=”TCP”,””,80 and after successful connection, send AT+CIPSEND=70 where 70 is the length of the string you will be sending. You will see ‘>’ in the Serial Monitor, which means you can send the GET request.

To send the request, use GET /update?api_key=……&field1=55 where you need to fill your API key and the value you would like to upload to field1. To close the uplink, send AT+CIPCLOSE. After successfully closing the link, you will see CLOSED on the screen. And that’s it! You have successfully uploaded data to the internet from an ESP8266! For more AT commands to try out, have a look at this.

Now how about making it wireless? So that you can connect it to an Arduino, power it from a mobile phone power bank, and stick it somewhere remote to sense and upload data which you can access online? That’s what I did in part 2 of the same IoT series. Part 2 is here!

Some references (several on Googling too):

  1. Instructables – DAFlabs
  2. SeeedStudio
  3. Reddit /r/arduino



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s