Joseph Adigwe
Published © GPL3+

Monitoring Humidity and Temperature from your phone! (Blynk)

Monitor your room temperature right from the comfort of your phone! A beginner friendly project to get you started with Iot and Sensors!

BeginnerFull instructions provided2 hours84
Monitoring Humidity and Temperature from your phone! (Blynk)

Things used in this project

Hardware components

DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
USB Cable, USB Type C Plug
USB Cable, USB Type C Plug
×1
ESP32 DevKit V1
×1

Software apps and online services

Blynk
Blynk
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Monitoring Humidity and Temperature from your phone! (Blynk) Fritzing Circuit Connection Diagram

This is the Circuit Connection Diagram for the project.

I made use of the white DHT sensor because I could not find the DHT11 component (blue) but the connection is still the same.

The resistor is a 10k Ohm Resistor.

Code

Monitoring Humidity and Temperature from your phone! (Blynk) Code

Arduino
This is the Arduino IDE code for the project. It has been reviewed and commented to help you understand line by line. All you have to do is copy the code, paste into your Arduino IDE and then read through the code comments for any few other changes you need to make.
//defining information constants that will carry the information from my online blynk account that will be used to connect to blynk cloud
//You are to copy these from the blynk website after making your template and adding your device
#define BLYNK_TEMPLATE_ID "YourTemplateID" 
#define BLYNK_TEMPLATE_NAME "YourTemplateName"
#define BLYNK_AUTH_TOKEN "YourBlynkAuthToken"
#define BLYNK_PRINT Serial //prints to serial monitor the status of the blynk when connecting or connected

#include <WiFi.h> //including for WiFi functionalities 
#include <WiFiClient.h> //including to allow the esp32 exhibit WiFI client qualities (i.e be able to connect to WiFI)
#include <BlynkSimpleEsp32.h> //including for the basic Blynk functionalities for the esp32 (need to download lbrary first)

//initialising a character array "auth" to take blynk auto token which will later serve as a parameter to setup Blynk to begin
char auth[] = BLYNK_AUTH_TOKEN;

//initialising WiFi credentials to be able to connect esp32 to wifi so that it can be online and send data to your phone
char ssid[] = "YourWiFiOrHotspotSSID";
char password[] = "YourWiFiOrHotspotPassword";

#include <DHT.h> //including for DHT (Digital Humidity and Temperature Sensor) functionalities like creating objects and using methods

#define DHTPIN 26 //define the pin you are connecting the data pin (2nd pin from the left) of the DHT11 to

#define DHTTYPE DHT11 //define the type of DHT you are using as this would be fed into a constructor when creating the DHT object

DHT myDHT(DHTPIN, DHTTYPE); //initialising dht sensor object in DHT class feeding in connection pin and DHT type

void setup() {
  Serial.begin(9600); //beginning serial monitor which can also be used to monitor the readings of humidity and temperature from the sensor
  delay(1500); //delaying to enable the serial monitor fully open before text is printed (This is to avoid double printing)
  Serial.println("Digital Humidity & Temperature (DHT) Sensor Monitor!"); //print this text to serial monitor to start your monitoring process
  
  Blynk.begin(auth, ssid, password, "blynk.cloud", 80); //setting up the blynk by inputting necessary parameters to allow it begin 
  //try 8080 instead of 80 for the port for blynk cloud if 80 does not work
  
  myDHT.begin(); //use the begin method on the MyDHT object to beginning the humidity and temperature tracking process
}

void loop() {
  delay(2000); //delay for 2 seconds to afford continuous outputting of sensor values  
  float humidity = myDHT.readHumidity(); //use the readHumidity to store the read humidity value in a float variable
  float temperature = myDHT.readTemperature(); //use the readTemperature to store the read Celsuis temperature value in a float variable

  //this if statement checks whether the DHT sensor read both values if not it returns to attempt to read values again
  if (isnan(humidity) || isnan(temperature)) 
  {
    Serial.println("Failed to read from DHT Sensor!");
    return;
  }
  
  Blynk.run(); //running set up Blynk to be able to output values to the Blynk app

  Blynk.virtualWrite(V1, humidity); //writing the humidity value to the first virtual pin (V1)
  Blynk.virtualWrite(V2, temperature); //writing the temperature value to the second virtual pin (V2)

  //this last part of the code outputs the values to the serial monitor also so that you can track values from there if you like and check for errors  
  Serial.print("Humidity: ");
  Serial.print(humidity);

  Serial.print("%\tTemperature in Celsuis: ");
  Serial.print(temperature);
  Serial.println("*C");
}

Credits

Joseph Adigwe

Joseph Adigwe

2 projects • 1 follower
I'm a student with an interest in electronics, robotics and automation. It started from watching movies and reading articles about robotics.

Comments