Introduction: ESP8266 With Thingspeak and DHT11 Tutorial | Web Server

Hey, what's up, Guys! Akarsh here from CETech.

This project of mine is more of a learning curve to understand the thingspeak platform along with the idea of MQTT and then using Thingspeak with an ESP8266.

Towards the end of the article, we will be connecting the ESP8266 with a DHT11 and will be sending the temperature and humidity data to the Thingspeak platform over the internet. We will also be looking at the code for controlling hardware over the internet again using Thingspeak.

At the end of the tutorial, we will be able to send/receive data over the internet to the ESP8266/ESP32.

Let's start with the fun now...

Step 1: Get PCBs for Your Project Manufactured

You must check out PCBGOGO for ordering PCBs online for cheap!

You get 10 good quality PCBs manufactured and shipped to your doorstep for 5$ and some shipping. You will also get a discount on shipping on your first order.

PCBGOGO has the capability of PCB assembly and stencil manufacture as well as keeping good quality standards.

Do check them out If you need to get PCBs manufactured or assembled.

Step 2: Looking at the Thingspeak Platform:

The platform is primarily aimed towards IoT Projects and data analytics using visuals.

To get started with the free services of Thingspeak you will first need to Sign Up using your email ID, once that is done along with the email verification you will be greeted with a similar-looking page:

Now looking at some terminologies that might help you understand this better and make your work with web servers like these smoother:

1) Reading/Downloading Data: Getting data on your ESP8266/ESP32 from the server is a read operation.

2) Writing/Uploading Data: Sending data from your ESP8266/ESP32 to the server is a write operation.

3) API Key: To have data security and to prevent anyone randomly from reading/writing data to your server there needs to be some sort of security/password and the API Key is something intended towards this. API Key is a long alphanumeric key which is needed to read/data to the server. There are separate keys for reading and writing data.

4) Channel: A channel in thingspeak is a software counterpart of an IoT hardware device that you connect to Thingspeak, in our case an ESP8266 will utilise one entire channel of our bandwidth. In a free account of thingspeak, you can have a maximum of 4 channels.

5) Field: Each channel has 8 fields. A field is a variable and stores/shares a data type, for example when we send temperature and humidity from our device to the server, both the parameters will use one field each of the channel.

That's pretty much it about thingspeak!

Copy and keep the Write API Key, we will need it later while testing out the link to Thingspeak.

Step 3: MQTT by Mosquitto

MQTT is a lightweight data transfer protocol which can be used by us for similar purposes that we're using Thingspeak for. Mosquitto is an organisation providing MQTT server/broker for free for test purposes.

More on Mosquitto.org can be found at this link.

I will not be going into deep about MQTT in this article and will be covering MQTT in a separate article/video!

Step 4: Setting Up the ESP8266 for the Tests

Connect the DHT11 to the ESP8266 module on the D0 pin and the power lines to 3.3v on the ESP module.

Once this step is complete you can move over to the software part.

Step 5: Download and Setup the Arduino IDE

Download the Arduino IDE from here

1. Install the Arduino IDE and open it.

2. Go to File > Preferences

3. Add http://arduino.esp8266.com/stable/package_esp8266com_index.json to the Additional Boards Manager URLs.

4. Go to Tools > Board > Boards Manager

5. Search for esp8266 and then install the board.

6. Restart the IDE.

Step 6: Coding the Module

1. Download the code for writing to thingspeak from here: https://bit.ly/2RaZJMW

2. Open the code in Arduino IDE and make the required changes to the API Key/SSID/Password at the top of the code.

3. Navigate to Tools > Board. Select the appropriate board that you are using NodeMCU(12E) works in most of the cases.

5. Select the correct comm. port by going to Tools > Port.

6. Hit the upload button.

7. When the tab says Done Uploading you are ready to use the device.

Step 7: The ESP8266 Sends Data to Thingspeak

As soon as the code gets uploaded and you open the serial monitor you will be greeted with messages as I got in the above picture. The module connects itself to the WiFi first and then sends the data to the server after reading the parameters from the DHT11.

On the thingspeak page you can find the entries like the below picture:

That's it from this demonstration!

If you want to take the other route and control things from Thingspeak using the ESP8266 and read server data you can use this code: https://bit.ly/2OC8PQZ