Categories: Example Projects

Plant humidity monitoring with ESP32 and Cayenne

A Plant humidity monitoring with ESP32 project demonstrates processing & remote access to real-time data and how the data is used for monitoring the real-time environment of the plant. In this IoT project, we will be using the DHTxx (DHT11/DHT22) board along with the IoT gateway board to set up the plant monitoring system accessible from anywhere using the internet. To monitor the data real-time we use a cloud service called Cayenne from myDevices, it is a free cloud platform best suitable for beginners in the IoT project development.

Temperature and Humidity monitoring with ESP32 – Connection description

Connect the DHTxx QuickInsert board to the available bus in the IoT board. By this connection, we will get the Power for the DHTxx QuickInsert board and the connection between the ESP32 module (GPIO32).

We have another detailed tutorial using DHT11/22 with ESP32.

Now Connect your IoT board to your computer using USB cable and find out the COM Port from device manager which is required for the Arduino IDE.

Cayenne setup

  • Once after you log in, you can access your dashboard and monitor your connected devices.
  • To add a new device, select Add new… and then Device/Widget

  • Then select “Bring your own thing

 

  • Then note down the MQTT username, MQTT Password and Client ID, these are required in our program.

Program description

First, include the required libraries and then define the Pin number and DHT sensor model

#include <CayenneMQTTESP32.h> // Library for Cayenne
#include "DHT.h" // Library for DHT sensor
#define CAYENNE_PRINT Serial
DHT dht(32, DHT11);

Then give the WiFi credentials and Cayenne user credentials

char ssid[] = "SSID";
char wifiPassword[] = "password";

char username[] = "b2b2e800-ef79-11e7-abe9-1721c4c13600";
char password[] = "d7bf162dc25c18346f5b34a5a70298f4e5509476";
char clientID[] = "8cab5460-0740-11e8-b10d-9981dfc22c01";

Then in the Setup section add the following lines

void setup() {
  Serial.begin(115200);    // Baud rate for serial monitor
  dht.begin();             // To start communication with DHT sensor
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);   // To Authenticate cayenne
}

In the loop, section add the following line

void loop() {
  delay(2000);      // Give some delay between each Sensor reading
  Cayenne.loop();   
  float h = dht.readHumidity();     // To get Humidity reading
  float t = dht.readTemperature();  // To get temperature reading
  if (isnan(h) || isnan(t)) {       // Condition to check whether the sensor reading was successful or not
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Serial.print("Humidity: ");       // To print the data in serial monitor
  Serial.print(h);
  Serial.print(" %\t Temperature: ");
  Serial.print(t);
  Serial.println(" *C ");
  Cayenne.virtualWrite(0, h);     // To write the Sensor reading to Cayenne Dashboard using channel 0
  Cayenne.celsiusWrite(1, t);     // To write the Sensor reading to Cayenne Dashboard using channel 1
}

After writing the program compile it and download to the IoT board from the Arduino IDE

Dashboard setup

  • Once after you upload the program go to the Cayenne dashboard and you can see as below
  • Click on the Plus sign on the readings to add it to the dashboard

  • To change the display data type select the settings icon

  • Then set it as humidity reading

  • Finally, your dashboard will be like this as below

 

 

Share