Laboratory#4 NodeMCU - ThingSpeak Integration With ESP8266 and Web App Development
Laboratory#4 NodeMCU - ThingSpeak Integration With ESP8266 and Web App Development
1. Objective(s):
In this laboratory activity, you will:
1. Set up and configure ThingSpeak to receive data from the ESP8266.
2. Program the ESP8266 to send sensor data to ThingSpeak.
3. Create a simple web application to read and visualize data from ThingSpeak.
3. Materials
● ESP8266 development board (NodeMCU or similar)
● USB cable for programming the ESP8266
● Computer with Arduino IDE installed
● ThingSpeak account
● Text editor (for web app development)
● Wi-Fi network
● DHT 11
4. Discussion
ThingSpeak is an open-source Internet of Things (IoT) analytics platform that
provides a cloud-based solution for collecting, storing, analyzing, and
visualizing sensor data. It allows users
In this lab, we will explore how to use ThingSpeak to collect data from an
ESP8266 module. The ESP8266 will act as an IoT device, gathering sensor data
and transmitting it to ThingSpeak for visualization and analysis.
ESP8266 Integration
In this lab, we will use the ESP8266 to send data (e.g., temperature or humidity)
to ThingSpeak. The ESP8266 will be connected to a sensor to gather data and
will then transmit this data to a ThingSpeak channel over Wi-Fi using HTTP
requests. ThingSpeak's RESTful API will be used to send and retrieve data,
which means we can perform actions like logging sensor readings and
visualizing them in real time.
5. Procedures
Creating Account to Thingspeak
1. Visit the ThingSpeak Website:
● Go to https://thingspeak.com.
2. Sign Up for a MathWorks Account:
● ThingSpeak is owned by MathWorks, so you need a MathWorks account to
use ThingSpeak.
● On the homepage, click on the "Get Started for Free" button or the "Sign Up"
link.
3. Provide Personal Information:
● Enter your first name, last name, and email address. Make sure to use a
valid email address because you will need to verify your account.
● Create a password for your MathWorks account.
4. Verify Your Email Address:
● After submitting your information, MathWorks will send you a verification email.
● Open the email and click on the verification link to confirm your account.
5. Complete Registration:
● After verifying your email, log in to your MathWorks account using your email
and password.
6. Once logged in, go back to the ThingSpeak website.
● Click on "Sign In" and use your MathWorks credentials to access ThingSpeak.
Create a Channel:
1. Once logged in, click on the "Channels" tab from the top navigation bar and select
“my Channels”.
.
2. Click on the "New Channel" button to begin creating your new channel.
3. Configure your Channel
● Channel Name: Enter a meaningful name for your channel (e.g.,
"Home Temperature Monitoring").
● Description: Provide a description of your channel (e.g., "Channel to
monitor temperature and humidity at home").
● Field Setup:
■ Fields represent the different data types you will be collecting
(e.g., temperature, humidity).
■ You can add up to eight fields. Provide names for each field to describe
the data.
■ Create a field for:
■ temperature
■ humidity
● Metadata (Optional): You can enter metadata like latitude, longitude, and
elevation to provide geographic context if applicable. This is useful if you are
working with data related to a specific location.
● Channel Settings:
■ Make Channel Public: If you want others to be able to view your
channel, check the "Make Public" box.
■ Leave it unchecked if you want to keep your data private.
● Scroll down and click the "Save Channel" button to create your channel.
4. Once done, you will be redirected to Private view with the default design for
visualization of humidity and temperature.
5.
Getting Your Channel ID and API Keys
Once the channel is created, you will see a Channel ID at the top of your
channel's page. This is a unique identifier for your channel.
API Keys:
http://arduino.esp8266.com/stable/package_esp8266com_i
ndex.json
● Click OK.
● Go to Tools > Board > Boards Manager and search for ESP8266. Install
the ESP8266 by ESP8266 Community package.
2. Select the Correct Board and Port.
3. Install Required Libraries
● Ensure you have the following libraries installed in the Arduino IDE:
■ ESP8266WiFi.h: This library is used to connect your ESP8266 to a
Wi-Fi network.
■ ESP8266HTTPClient.h: This library is used for making HTTP requests
to ThingSpeak.
● To install a library, go to Sketch > Include Library > Manage Libraries
and search for the required library.
1. Open Arduino IDE, create a new sketch, and copy the code below:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
void setup() {
Serial.begin(115200); // Start serial communication for
debugging
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.println(ssid);
Serial.println("");
Serial.println("Connected to Wi-Fi");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
WiFiClient client;
HTTPClient http;
6. Supplemental Activity
Supplemental Activity #1: Reading Data from DHT11 Sensor
In this activity, you will replace the random data simulation with real-time readings from
the DHT11 sensor. The goal is to read temperature and humidity data from the DHT11
sensor and send it to ThingSpeak for visualisation.
Instructions:
1. Connect the DHT11 sensor to the ESP8266 using the wiring instructions
provided earlier.
2. Modify the Arduino code:
○ Replace the part of the code that simulates temperature and humidity
values with DHT11 sensor readings.
3. Send the Data to ThingSpeak:
○ Use the readings obtained from the DHT11 sensor to populate
the data fields for temperature and humidity and send them to
ThingSpeak.
4. Testing:
○ Upload your code to the ESP8266 and monitor the Serial Monitor to
ensure data is being read correctly from the sensor and sent to
ThingSpeak.
Expected Output:
● The ESP8266 will read temperature and humidity values from the DHT11
sensor and send them to ThingSpeak.
● ThingSpeak will display the actual sensor readings, which you can visualize on
your channel.
Supplemental Activity #2: Create Your Own Web App to Fetch Data from
ThingSpeak
In this activity, you will create a web app that retrieves data from ThingSpeak. The web
app should be designed using Bootstrap to ensure a modern, responsive layout.
Instructions:
Expected Outcome:
● The web app should have a responsive design and display the latest
temperature and humidity
readings from ThingSpeak.
● The data should be fetched in real-time and updated whenever new data
is available in your ThingSpeak channel.
● HTML File:
○ Bootstrap: Link to Bootstrap CSS and JS for responsive design.
○ JavaScript: Use JavaScript to make API requests to ThingSpeak.
○ User Interface:
■ A header titled "IoT Sensor Data Dashboard".
■ A section displaying real-time temperature and humidity.
■ A button to refresh the data manually (optional).
7. Conclusion:
SSID for the connectivity of Node MCU. The modified Arduino code comes with
a 1 sec (1000) interval. With the use of DHT11 sensor, the temperature and
humidity of the room should be fetched. Once done, test the code by connecting
to WIFI and the output or code data should be sent successfully. In order to view
interfaced our circuit and web app to interact together by setting up a channel
independently for the purpose of reading the temperature and humidity data the
provided RESTful API keys allowed us to either write or read sensor data in real
time. We first tried sending data to ThingSpeak to see if our circuit is responding
and by using serial monitor in the arduino IDE to see the status.