Skip to main content

Temperature and Humidity Data on Cloud using NodeMCU ESP8266 over ThingSpeak Server

In this project, we will be using NodeMCU ESP8266, DHT11 Sensor and ThinkSpeak Server with a WiFi connection.

Introduction to Resources:

NodeMCU ESP8266:

NodeMCU is an open-source LUA language-based firmware developed for ESP8266 wifi chip, although many students make the mistake of thinking the ESP8266 to be the entire chip name whereas it is just the WiFi module. By exploring functionality with ESP8266 chip, NodeMCU firmware comes with ESP8266 Development board/kit i.e. NodeMCU Development board.
NodeMCU Dev Kit/board consist of ESP8266 wifi enabled chip. The ESP8266 is a low-cost WiFi chip developed by Espressif Systems with TCP/IP protocol.

Here fo this project I've used Version2 (V2) NodeMCU Dev Kit i.e. NodeMCU Development Board v1.0 (Version2), although there isn't much significant change from its predecessors.
I've used Arduino IDE if you want you may use ESPlorer IDE also. The primary difference between them is a programming language difference we can say while developing an application for NodeMCU using ESPlorer IDE and Arduino IDE. We need to code in C\C++ programming language if we are using Arduino IDE for developing NodeMCU applications and Lua language if we are using ESPlorer IDE.

Basically, NodeMCU is Lua Interpreter, so it can understand Lua script easily. When we write Lua scripts for NodeMCU and send/upload it to NodeMCU, then they will get executes sequentially. It will not build a binary firmware file of code for NodeMCU to write. It will send Lua script as it is to NodeMCU to get executed.

DHT11 (Basic Temperature and Humidity) Sensor:

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds old.

ThingSpeak Server:

ThingSpeak which is an IoT analytics platform service that allows you to aggregate, visualize and analyze live data streams in the cloud. ThingSpeak provides instant visualizations of data posted by your devices (or for our case the ESP8266 module) to ThingSpeak. With the ability to execute MATLAB code in ThingSpeak you can perform online analysis and processing of the data as it comes in. ThingSpeak is often used for prototyping and proof of concept IoT systems that require analytics. 
So, this was all about the introduction to the resources we will be using so let's get started.

Design and Working:

The basic work is to connect the Node MCU ESP8266 with the Temperature and Humidity sensor DHT11. For that identify the (+),(-) and (out) terminals on the sensor and connect them to 3V (Voltage In), G (Ground) and D4 (Digital Signal Port 4) respectively.
Now, within the Arduino application install the libraries. Visit this link Interface DHT11 (Humidity Sensor) Using NodeMCU for installing the libraries (This had been a great help for me). After a successful connection and compilation of the code upload it to the NodeMCU and open the Serial Monitor Terminal to check if it's working.


It should appear like this and if you are successful then you have completed the basic setup.
Now that the temperature sensor is working, we need to set up the wifi connection. Just type the code from Github, replace the "SSID" and "PASSWORD" with your own and then upload it to ESP8266.


After uploading, when you see this output then your ESP8266 is connected to the network.

So, the project is done halfway. Now we need to connect the sensor data to the ThingSpeak server through the wifi module.

Create an account in ThingsSpeak and then create a channel on My Channel.


Enter a name for your channel, add the temperature and humidity fields and save the channel. Then in the channel use the API Keys tab and get the Write API Key (since we intend to write the data onto the server).


So, now we have a server up and running and now we just have to connect the data stream to it. Also, we cannot send data for two fields at a time so we need to toggle the states, i.e. when the state 1 is being executed then we change the state to 2 and vice versa. This helps us to stream to data simultaneously without crashing. Moreover, this was all about the logical part of this project.

 Furthermore just in the setup() just connect to the WiFi and then make a WiFi client to be parsed to the ThingSpeak module.

And, in the loop() read the data from the DHT sensor and print them and then push each data onto the server by toggling the states.

This was all about the code. You may have it from my GitHub repo.

After completing all this you'll have a ThingSpeak channel with both the fields updating simultaneously.


You can also edit the graph appearance in the edit menu.

So that is all about Temperature and Humidity Data on Cloud using NodeMCU ESP8266 over ThingSpeak Server. Try it yourself and feel free to share your experience. Also, let me know what you feel about this project.

Comments

Popular posts from this blog

Building my Actions on Google bot

Since the time when Google Assistant was launched, I was intrigued by the thought that a machine would be able to talk to us. But that was a long time back, now when we use it quite often I thought why not make one of them. Firstly I wasn't so talented to make a talking assistant of my own, so had to use the Actions on Google to make it happen. What is an Action? In the simplest terms, an Action defines support for a user request (represented as an intent) and the corresponding fulfillment that can carry out the request. You can build Actions that fulfill requests with web content, Android apps, or with experiences built specifically for the Assistant.  So I visited the Actions on Google page. Then see the "Get Started" button I clicked it. I was redirected to the Documentation Page . There it was written all kinds of ways to get started. Being a lazy person, although I got through the whole documentation, I decided to start off with the templates, b

HACK'N'PITCH 2020: My First Overnight Hackathon Experience

This article is about the first overnight Hackathon I attended as team Pseudo Automata with members Debdut Goswami , Aniket Mitra , Sayan Kundu and myself .   What is a Hackathon in the first place? An idea makes an entrepreneur, but a smart financial sense builds a successful entrepreneur. 'Hackathon' comprises two words: 'Hack', which means doing clever programming and 'Marathon', which marks an event of endurance. It is a competition where participants try and use technology to hack into real-world problems.                  It is often told to be a 'social coding' event that brings young and bright computer programmers together to contribute to the digital revolution. With risk management, trading, investing, personal finance, Big Data, retail banking, regulatory compliance, mobile payments and enterprise social as some of the heads.                  The Hackathon will stimulate the participants to innovate and apply their knowledge,