Temperature and Humidity Monitor

Project Description

This project is meant to monitor the temperature and humidity for a certain room: the room where the sensor will be placed.

Users can download the mobile app, create an account and set limits for temperature and humidity. When the temperature is lower than the limit, the heating system will start. To simulate this behavior, an RGB LED was used and the red light was turned on. On the other hand, if the temperature is higher than the limit, the air conditioning will start. This behavior was simulated by turning on the blue light. Lastly, if the temperature is between limits, the green light will be turned on.

Also, when air conditioning or heating system is started, a notification will be sent to inform the user regarding the taken action.

Hardware Description

Following hardware components were used in order to achieve the wanted result:

  • ESP-WROOM-32 ESP-32S
  • DHT22 temperature and humidity sensor
  • Breadboard
  • RGB LED to simulate air conditioning/heating system
  • Wires

Software Description

The following libraries were necessary:

#include  <WiFi.h>               // to connect ESP32 via WiFi
#include "DHT.h"                 // to read data from DHT22 sensor
#include <Firebase_ESP_Client.h> // to read/write data to Firebase

The Wi-Fi setup and connection:

Serial.print("Connecting to Wi-FI...");
while (WiFi.status() != WL_CONNECTED) {

The DHT22 setup:

#define DHTPIN 14
#define DHTTYPE DHT22   


Firebase setup:

config.api_key = API_KEY;
config.database_url = DATABASE_URL;

// Sign up with Firebase
if (Firebase.signUp(&config, &auth, "", "")){
  signupOK = true;
  Serial.printf("%s\n", config.signer.signupError.message.c_str());
config.token_status_callback = tokenStatusCallback;


RGB LED setup (all pins were set to OUTPUT mode):

#define LED_PIN_HS 25
#define LED_PIN_OK 26
#define LED_PIN_AC 33

// used to change LED color
void setLEDColor(int R, int G, int B) {
  analogWrite(LED_PIN_HS,   R);
  analogWrite(LED_PIN_OK, G);
  analogWrite(LED_PIN_AC,  B);

The loop() function:

// get data from sensor
float hum = dht.readHumidity();
float temp = dht.readTemperature();

if (Firebase.ready() && signupOK) {
  // write temperature read from sensor to Firebase
  if (!Firebase.RTDB.setFloat(&firebaseData, "IOT_Project/Temperature", temp)){
    Serial.println("Failed to write temperature to Firebase: " + firebaseData.errorReason());
  // write humidity read from sensor to Firebase
  if (!Firebase.RTDB.setFloat(&firebaseData, "IOT_Project/Humidity", hum)){
    Serial.println("Failed to write humidity to Firebase: " + firebaseData.errorReason());

// read humidity superior limit
if (Firebase.RTDB.getFloat(&firebaseData, "/IOT_Project/Limit_Humidity_Sup")) {
  limitHumSup = firebaseData.floatData();
} else {
  Serial.println("Failed to get Limit_Humidity_Sup from Firebase: " + firebaseData.errorReason());

// read humidity inferior limit
if (Firebase.RTDB.getFloat(&firebaseData, "/IOT_Project/Limit_Humidity_Inf")) {
    limitHumInf = firebaseData.floatData();
} else {
  Serial.println("Failed to get Limit_Humidity_Inf from Firebase: " + firebaseData.errorReason());

// read temperature superior limit
if (Firebase.RTDB.getFloat(&firebaseData, "/IOT_Project/Limit_Temperature_Sup")) {
    limitTempSup = firebaseData.floatData();
} else {
  Serial.println("Failed to get Limit_Temperature_Sup from Firebase: " + firebaseData.errorReason());

// read temperature inferior limit
if (Firebase.RTDB.getFloat(&firebaseData, "/IOT_Project/Limit_Temperature_Inf")) {
    limitTempInf = firebaseData.floatData();
} else {
  Serial.println("Failed to get Limit_Temperature_Inf from Firebase: " + firebaseData.errorReason());

// check humidity related to limits
if (hum > limitHumSup || hum < limitHumInf) {
  Serial.println("Humidity is not between limits");

// check temperature related to limits
if (temp > limitTempSup && !isACOpen) {
  isACOpen = true;
  setLEDColor(0, 0, 200);
  Serial.println("Temperature is higher than limit - AC started");
} else if (temp < limitTempInf && !isHSOpen) {
  isHSOpen = true;
  setLEDColor(200, 0, 0);
  Serial.println("Temperature is lower than limit - heating system started");
} else if (temp >= limitTempInf && temp <= limitTempSup) {
  isACOpen = false;
  isHSOpen = false;
  setLEDColor(0, 200, 0);

As said before, the data read from sensor is saved in Firebase and is updated in real time in the mobile app:

Mobile App

This is the mobile application interface:


iothings/proiecte/2022sric/tempandhummonitor.txt · Last modified: 2023/06/02 00:43 by amalia.palaghiu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0