Arduino Nano

Arduino basic Tutorial

Blynk iot Tutorial

Visit all the Links

ArduinoTutorial by Manmohan Pal

Temperature and Humidity Monitoring using DHT11 Sensor on Blynk IoT

 Temperature and Humidity Monitoring using DHT11 Sensor on Blynk IoT










Tutorial: Temperature and Humidity Monitoring using DHT11 Sensor on Blynk IoT

In this tutorial, we’ll guide you step-by-step on how to use a DHT11 sensor to monitor temperature and humidity and visualize the data on the Blynk IoT platform. This is a simple IoT (Internet of Things) project that can help you get started with both hardware and software.

What You’ll Learn

  • How to set up the DHT11 sensor with Arduino.
  • How to use the Blynk app to monitor the data.
  • How to send real-time sensor data to the Blynk platform.

What You’ll Need

  1. DHT11 Sensor (Temperature and Humidity sensor)
  2. Arduino Uno (or ESP8266/ESP32)
  3. Jumper wires
  4. Breadboard (optional)
  5. Smartphone with Blynk app installed
  6. Wi-Fi network (for internet connectivity)
  7. Arduino IDE (installed on your computer)

Step 1: Wiring the DHT11 Sensor to Arduino

Let's begin by connecting the DHT11 sensor to the Arduino board.

The DHT11 sensor has 3 pins:

  • VCC (Power)
  • GND (Ground)
  • DATA (Signal)

Here’s how to connect the sensor to the Arduino:

  1. Connect the VCC pin of the DHT11 to the 5V pin of the Arduino.
  2. Connect the GND pin of the DHT11 to the GND pin of the Arduino.
  3. Connect the DATA pin of the DHT11 to digital pin 7 on the Arduino.

Your setup should look like this:

DHT11 PinArduino Pin
VCC5V
GNDGND
DATAPin 7

Step 2: Setting Up the Blynk App

Before coding the Arduino, we need to set up the Blynk app on your smartphone.

  1. Download the Blynk app: Install the Blynk app from the App Store (iOS) or Google Play (Android).
  2. Create an account: Open the app and sign up or log in.
  3. Create a new project:
    • Tap New Project.
    • Give your project a name (e.g., "Temperature and Humidity Monitor").
    • Select Arduino Uno as your hardware type.
    • Choose Wi-Fi for the connection type (if you are using ESP8266 or ESP32, select the appropriate board).
  4. Get the Auth Token: After creating the project, Blynk will send you an Auth Token to your registered email. This token will allow your Arduino to communicate with the Blynk server.

Step 3: Installing Libraries in Arduino IDE

To communicate with the DHT11 sensor and Blynk app, you need to install the following libraries in the Arduino IDE:

  1. DHT Sensor Library
  2. Blynk Library

To install these libraries:

  1. Open the Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries.
  3. In the Library Manager, search for:
    • DHT sensor library (by Adafruit)
    • Blynk (by Blynk)

Click Install on both libraries.


Step 4: Writing the Arduino Code

Now, let’s write the code to read data from the DHT11 sensor and send it to the Blynk app.

  1. Open the Arduino IDE.
  2. Create a new sketch and paste the following code
/////////////////////////////////////////////////////////////////////////////////////

/// code to upload DHT sesnor data on Blynk Cloud and APP

#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID           "TMPxxxxxx"
#define BLYNK_TEMPLATE_NAME         "Device"
#define BLYNK_AUTH_TOKEN            "YourAuthToken"


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

#define DHTPIN D1

#define DHTTYPE DHT11

DHT dht (DHTPIN, DHTTYPE);

void setup()
{
  // Debug console
  Serial.begin(115200);
  dht.begin();
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}

void loop()
{
  Blynk.run();
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

Serial.println("Temperature: ");
Serial.println(temperature);
Serial.println(" °C, Humidity: ");
Serial.println(humidity);
Serial.println(" %");

  Blynk.virtualWrite(V0, humidity);
  Blynk.virtualWrite(V1, temperature);

  delay(3000); // Update every 2 seconds
}
////////////////////////////////////////////////////////////////////////////////////

Explanation of the code:

  • Pin Setup: The DHT11 sensor is connected to pin 7 of the Arduino.
  • Blynk Setup: The Auth Token, Wi-Fi SSID, and password are used to authenticate and connect the Arduino to the Blynk platform.
  • Reading Data: The sendSensorData() function reads the temperature and humidity from the DHT11 sensor and sends it to the Blynk app every second.

Step 5: Uploading the Code to Arduino

  1. Connect the Arduino to your computer using a USB cable.
  2. Select your board type and port in the Arduino IDE:
    • Go to Tools > Board > Arduino Uno.
    • Go to Tools > Port and select the correct port.
  3. Click the Upload button in the Arduino IDE to upload the code to your Arduino board.

Step 6: Viewing the Data on the Blynk App

After uploading the code to your Arduino, you can now view the temperature and humidity data on your smartphone:

  1. Open the Blynk app.
  2. You’ll see the temperature and humidity data displayed on the virtual pins (V5 for humidity and V6 for temperature).
  3. The data will update every second in real-time.

Step 7: Customizing the Blynk Dashboard (Optional)

You can further customize your Blynk dashboard to make it more user-friendly:

  1. Tap on the widget area in the Blynk app and select Gauge or Value Display to display the temperature and humidity readings in a more visual way.
  2. Customize the widgets with your preferred colors and labels to make the data clearer.

Conclusion

Congratulations! You’ve successfully built a Temperature and Humidity Monitoring System using the DHT11 sensor and the Blynk IoT platform. You can now monitor temperature and humidity remotely from your smartphone in real time. This project is a great starting point for IoT beginners and can be expanded with additional sensors and features.

Feel free to experiment with the code and the Blynk app to customize this project to suit your needs.


Next Steps:

  • Explore additional sensors like DHT22 for more accurate readings.
  • Integrate the system with other platforms like ThingSpeak or Google Firebase.
  • Add features like notifications or triggers based on sensor data.

Happy tinkering and happy learning!





No comments:

Post a Comment