Monitor Temperature and Humidity With AM2301 on NodeMCU & Blynk

by AmruthKumarSala in Circuits > Microcontrollers

4143 Views, 3 Favorites, 0 Comments

Monitor Temperature and Humidity With AM2301 on NodeMCU & Blynk

Humidity And Temperature.jpg
02.jpeg
03.jpeg
04.jpeg
06.jpeg

It is a very well known fact that in most of the industry verticals, temperature, humidity, pressure, air quality, water quality, etc., play important factors to be monitored continuously and necessary alert systems need to be in place when the values go away from the thresholds set.

This prototype will help us understand the process to monitor temperature and humidity using "AM2301 Capacitive Digital Temperature & Humidity Sensor".

Building this prototype is very simple and easy. I hope that the instructions in this "Instructable" will help readers give a clear picture of its practical implementation.

Supplies

Circuit Diagram & Connections.

Circuit Diagram.png
07.jpeg
08.jpeg

The connections are very simple and are as follows:

  1. 3V of AM2301 to 3V of WeMos D1 Mini
  2. GND of AM2301 to GND of WeMos D1 Mini
  3. Signal Wire (Yellow) of AM2301 to D4 (GPIO 2) of WeMos D1 Mini

Note: To build this prototype, we will not need any breadboard as we just have three wires to connect. I leave the choice to the reader of this document, whether to make use of breadboard (or) just connect WeMos D1 mini with AM2301 directly with Jumper wires.

Configuring Blynk to Monitor Temperature and Humidity.

11.jpeg
12.jpeg
13.jpeg
14.jpeg
15.jpeg
16.jpeg
19.jpeg
18.jpeg
17.jpeg
20.jpeg
21.jpeg
22.jpeg
23.jpeg
24.jpeg
26.jpeg

Step-by-step screenshots have been provided for a better understanding of the process to configure Blynk. Readers are requested to go through the screenshots and have the application configured with two "Gauge" components, one to represent Humidity and the other the Temperature.

The Code.png
25.jpeg
09.jpeg

Start of Code >>>>>

#define BLYNK_PRINT Serial

#include SPI.h

#include ESP8266WiFi.h

#include BlynkSimpleEsp8266.h

#include DHT.h

char auth[] = "hQqK5jvA0h5JqubLnnpxV94eEltFbw1Y"; //Enter the Auth code which was send by Blink

char ssid[] = "Smaragd25"; //Enter your WIFI Name

char pass[] = "Smaragdine@2017"; //Enter your WIFI Password

#define DHTPIN 2 // Digital pin 4

// #define DHTTYPE DHT11 // DHT 11

// #define DHTTYPE DHT22 // DHT 22, AM2302, AM2321

#define DHTTYPE DHT21 // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);

BlynkTimer timer;

void sendSensor()

{

float h = dht.readHumidity();

float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {

Serial.println("Failed to read from DHT sensor!");

return; }

Blynk.virtualWrite(V5, h); //V5 is for Humidity

Blynk.virtualWrite(V6, t); //V6 is for Temperature

}

void setup()

{

Serial.begin(9600); // See the connection status in Serial Monitor

Blynk.begin(auth, ssid, pass);

dht.begin();

timer.setInterval(1000L, sendSensor);

}

void loop()

{

Blynk.run();

timer.run();

}

End of Code >>>>>

In the above code, especially in the #include statements, please enclose all header files (that end with .h extension) in "<" and ">", else the code will throw errors.

Note: In case you have selected a wrong Temperature and Humidity Controller statement in the code, the values you get are obviously not correct (Sample screenshot attached), even though the sensor is working. Please comment/uncomment the following lines to meet your needs. Only one of the following lines is uncommented, rest have to be commented.

  1. #define DHTTYPE DHT11 // DHT 11
  2. #define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
  3. #define DHTTYPE DHT21 // DHT 21, AM2301

In my case, I have uncommented the last line, i.e: "#define DHTTYPE DHT21 // DHT 21, AM2301", and have commented rest lines.

For better appearance, I packed both the WeMos D1 Mini and the AM2301 sensor in Styrofoam. I am planning to have an acrylic sheet case to neatly embed the complete hardware and make it look more professional.

In case of any queries, please write back to amruth@smaragdine.work (or) ping me on WhatsApp on +91 9398472594. I will be very happy to receive the comments and improve my articles.