Internet of Things-IoT Blynk+NodeMCU ESP8266
How it works
An IoT system consists of sensors/devices which “talk” to the cloud through some kind of connectivity. Once the data gets to the cloud, software processes it and then might decide to perform an action, such as sending an alert or automatically adjusting the sensors/devices without the need for the user.
IoT Advantages
IoT Cloud Platforms
IoT Hardware Platforms
Project Description
It is a digital conversation between the IoT hardware platform (NodeMCU ESP8266) and the IoT Cloud platform (Blynk application on the android tablet).
The NodeMCU is physically connected to a DHT11 Temperature/Humidity sensor through digital pin 5(GPIO 14), a COB LED panel through a relay on digital pin 7(GPIO 13), and a mini Fan through a relay on digital pin 8 (GPIO 15).
The Temperature/Humidity sensor detects the temperature and humidity levels and sends them to the Blynk application through the Blynk cloud server. The Blynk application will display the temperature and humidity values using a digital gauge and labeled value display.
DHT11 > NodeMCU > Blynk server > Blynk application on the android tablet
The process of controlling the appliances is done in the opposite way. The COB Led panel and the mini Fan will turn on or off accordingly when the push buttons on the Blynk interface are pressed.
Button pressed (on the tablet)> Blynk server > NodeMCU > Relay > Light/Fan
The Implementation
Computer science IGCSE Students from grades 9 and 10 had many practical sessions on how to program the NodeMCU and setup the Blynk application on their tablets. They practiced in school, and had to complete some individual tasks on how to read sensors' values through the serial monitor by their own. Robotics family provided the students with the required hardware, tutorials, and support in order to improve their self learning skills.
Required Hardware/Appliances
- NodeMCU ESP8266
- DHT11 Temperature/Humidity sensor
- 2 Channel relay
- 12V COB led panel
- 12V Fan
- Android Tablet
- 12V Power supply(adapter or battery)
Mobile Application
- Blynk IoT platform
Schematics and connections
Blynk Setup
Full tutorial on how to setup the interface can be found on the Blynk official website
The Code
#include <DHT.h> // import the DHT library
#include <ESP8266WiFi.h> // import the ESP8266WiFi library
#include <BlynkSimpleEsp8266.h> // import the BlynkSimpleEsp8266 library
DHT dht(14, DHT11); // create dht instance of the class DHT with two arguments (connection pin, DHT sensor type))
BlynkTimer timer; // create BlynkTimer instance of the class timer
char auth[] = "c52*****25ce"; // your Blynk Auth Token
char ssid[] = "******"; // Your wifi ssid
char pass[] = "********"; // your password
void setup()
{
pinMode(13,OUTPUT); // relay GPIO 13 (Light) set as output pin
pinMode(15,OUTPUT); // relay GPIO 15 (Fan) set as output pin
digitalWrite(13, LOW); // Turn off the light
digitalWrite(15, LOW); // Turn off the fan
Blynk.begin(auth, ssid, pass); // start the communication with blynk server
dht.begin(); // start reading from the dht11 sensor
timer.setInterval(1000L, sendSensor); //calls the sendSensor function at specified time interval
}
void loop()
{
Blynk.run(); // execute the Blynk function
timer.run(); // execute the timer function
}
void sendSensor() // a function that reads the dht11 values and sends them to the virtual pins
{
float h = dht.readHumidity(); //read the humidity value and assign it to 'h'
float t = dht.readTemperature(); //read the temperature value and assign it to 't'
Blynk.virtualWrite(V4, t); // send the value of 't' to virtual pin 4
Blynk.virtualWrite(V3, h); // send the value of 'h' to virtual pin 3
}
BLYNK_WRITE(V1) //execute the BLYNK_WRITE function on virtual pin 1
{
int pinValue = param.asInt();// read the state of light button
if (pinValue == 1) // if 1 (pressed)
{
digitalWrite(13, HIGH); //turn on the light (turn on relay on GPIO 13)
}
else
{
digitalWrite(13, LOW); //turn off the light (turn on relay on GPIO 13)
}
}
BLYNK_WRITE(V2) // execute the BLYNK_WRITE function on virtual pin 2
{
int pinValue2 = param.asInt(); // read the state of fan button
if (pinValue2 == 1) // if 1 (pressed)
{
digitalWrite(15, HIGH); //turn on the light (turn on relay on GPIO 15)
}
else
{
digitalWrite(15, LOW); //turn off the light (turn on relay on GPIO 15)
}
}
The presentation
The IoT concept and project were introduced and presented at Robotics Family's annual robotics fair. Yorgo and his Team made an outstanding presentation. Parents, staff, and attendees were Amazed by the achievement, proving again that our students are in parallel with present and future technologies.