Arduino - Smart Greenhouse Monitoring

by Bar_Kestenboum in Circuits > Arduino

475 Views, 1 Favorites, 0 Comments

Arduino - Smart Greenhouse Monitoring

WhatsApp Image 2024-03-04 at 20.58.33.jpeg

Join us as we embark on a journey to build your smart greenhouse, powered by an ESP32! If you love the fusion of gardening and cutting-edge technology, then this project is an ideal fit for you. Utilizing the capabilities of the ESP32, we'll design a greenhouse that nurtures your plants and keeps a vigilant eye on their vital conditions.

Imagine being able to remotely manage and monitor the temperature, humidity, and water of your plants. With this smart greenhouse, you can curate the perfect environment for your precious plants, ensuring their growth and prosperity under your watchful eye.

By integrating sensors and actuators with the ESP32, we will metamorphose a traditional greenhouse into an automated marvel. Whether you're a seasoned gardener seeking to enhance your cultivation skills or a technology enthusiast prepared to embark on an exhilarating DIY adventure, this project promises a delightful synergy of nature and innovation.


Supplies

finalProjectCirwithPaint.png

Now, we'll describe the components you'll need to bring your smart greenhouse project to life. Here are the essential hardware components and platforms you'll use to create a smart environment for your greenhouse.

Components:

  1. ESP32: This will serve as the brain of your smart greenhouse, responsible for controlling and managing various sensors and actuators.
  2. Water Sensor: This sensor measures the moisture level in the soil, enabling you to automate watering processes and ensure your plants receive the appropriate amount of hydration.
  3. Speaker: The speaker is utilized for emitting alerts or notifications in case of any issues or abnormalities detected within the greenhouse, ensuring prompt attention and intervention when necessary.
  4. Air Temperature and Humidity Sensor: This sensor provides real-time data on the temperature and humidity levels inside the greenhouse, enabling you to maintain optimal growing conditions for your plants.
  5. LED Strip: Functioning as a visual indicator, the LED strip helps track watering activities. A green light indicates that watering has occurred, while a red light may signify different stages or alerts requiring attention.

In addition to the hardware components, you'll also be using:

  1. Blynk: Blynk is a platform that allows you to build custom IoT applications for controlling and monitoring connected devices. You'll use Blynk to create a user interface to remotely access and control your smart greenhouse.
  2. Make.com: Make.com is likely a platform or service for DIY projects or maker communities. You may use it for accessing tutorials, project ideas, sourcing components, or sharing your project progress.

Make sure to gather all the necessary hardware components and familiarize yourself with the Blynk platform and any other resources provided by Make.com for the successful implementation of your smart greenhouse project.

General Description of the System

ESP32 to the Internet:

  1. Water Sensor to Google Sheets: Our system equips water sensors for each of the 12 plants in the greenhouse. Whenever watering occurs, the water sensor detects the elevated water level and updates the relevant Google Sheets. This generates a comprehensive report tracking watering events throughout the day, including timestamps. Thus, the greenhouse owner receives a detailed report ensuring their employees water the plants at the designated times.
  2. Air Temperature and Humidity Sensor to Email: The humidity and temperature sensor plays a pivotal role in our system, ensuring sensitivity to abnormal greenhouse conditions. Whenever either parameter surpasses the standard threshold, our system promptly alerts the greenhouse owner via email, notifying them of the deviation from normal conditions.

Internet to ESP32:

  1. Speaker Alarm: Upon receiving the email alert, the owner can promptly notify employees of the temperature and humidity exceeding by activating a noisy alarm. By accessing the Blynk dashboard, the owner can easily activate the alarm, which emits sound through the speaker connected to the ESP32.
  2. Strip Light: Additionally, the owner can inform employees about the number of plants requiring watering from the first 12. Similar to the speaker alarm, the owner can control the strip light via the Blynk dashboard. Employees will immediately observe the corresponding number of lights illuminated on the strip, indicating the plants requiring watering.

Functionality

Let's detail the scenarios of the system deeply:

Esp32 to the Internet:

  1. Sensors collect data and send an HTTP request to Blynk.
  2. Blynk's functionality divides the data into two sub-processes:
  3. One sub-process involves displaying the data on the dashboard for user monitoring.
  4. The other sub-process initiates an HTTP request to Make.com.
  5. Make.com receives the data and evaluates the scenario. Based on the scenario, Make.com triggers actions accordingly. For example, Make.com may update Google Sheets with the received data. Alternatively, Make.com may send email alerts if certain conditions are met.

Internet to Esp32:

  1. The owner accesses the Blynk dashboard to activate the alarm or specify watering requirements.
  2. Upon completion, Blynk generates an HTTP request directed to the ESP32.
  3. The ESP32 receives the HTTP request from Blynk and triggers the relevant output. For example, it may activate the alarm or illuminate the strip light indicating the number of plants that should be watered.

Set Up Make.com

make.com.png

Begin by launching Make.com on your laptop, then navigate to the left toolbar and select "Scenarios." Click on "Create New Scenario" to proceed.

Now the first application you need to choose is Webhooks - custom webhooks, and create new webhooks.

After it is created we will get a URL that we will have to use later in Blynk.

Then select Router in the application and from the router select Google Sheets and Microsoft 365 Email (or any email that you have).

To see more about the settings of each of the apps we selected here, go to the attached PDF where there are pictures of how everything is set up.

Downloads

Set Up Blynk

blynk - dasdboard.png

To begin, access Blynk on your laptop and locate the "Templates" section in the left-hand menu. From there, initiate a new template, labeling it as "FinalProject" and specifying "Esp32" as the hardware and "WiFi" as the connection type. Once the template is created, proceed to the datastreams section within the template. Generate new datastreams:

  1. Virtual Pin - named "Integer V0", alias "Strips", assign pin V0, designate the datatype as an Integer, and choose min as 0 and max as 12.
  2. Virtual Pin - named "Double V1", alias "Temperature Sensor", assign pin V1, designate the datatype as a Double, units as Celsius, min as 0 and max as 100, decimals #.0000.
  3. Virtual Pin - named "Double V2", alias "Humidity Sensor", assign pin V2, designate the datatype as a Double, min as 0 and max as 100, and decimals #.0000.
  4. Virtual Pin - named "String V3", alias "MakeUrlParams", assign pin V3, designate the datatype as a String.
  5. Virtual Pin - named "Integer V4", alias "Speaker", assign pin V4, designate the datatype as an Integer, and choose min as 0 and max as 1.


Moving forward, navigate to the web dashboard and incorporate these widgets from the control panel onto the main screen:

  1. Slide - title as "Strips" and associate it with the Strips datastream (V0).
  2. Label - title "Temperature Sensor" and associate it with the Temperature Sensor datastream (V1). Turn on the Widget Background and choose green-red.
  3. Label - title "Humidity Sensor" and associate it with the Humidity Sensor datastream (V2). Turn on the Widget Background and choose green-red.
  4. Switch - title as "Speaker" and associate it with the Speaker datastream (V4). Additionally, activate the On/Off values as 1 to On and 0 to Off.

Finally, click on the Developer Zone again and select the Webhooks option to create an HTTP request with the Make.com website. (Don't forget to use the URL that we got from webhook in Make.com, for example in the attached PDF you will see this URL - https://hook.eu2.make.com/k3ly7g15v4w8p6cejveqrf7arlsp7rvw)

The attached PDF contains pictures of how to set it up exactly so that it will work.

Downloads

Code

Copy and paste the following code into the Arduino IDE. Replace the first three lines of code with your specific template data which can be found in Blynk:

  • Go to Devices
  • Click your project
  • In your project click on Device Info

Also, replace your wifi name and wifi password with your name and password.

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

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define BLYNK_PRINT Serial
#define LED_PIN 2 // Defines the pin number (2) where an LED is connected.
#define LED_COUNT 12 // Specifies the total number of LEDs (12) connected to the Arduino.
#define WATER_PIN 35 // Defines the pin number (35) where an water sensor is connected.
#define SPEAKER_PIN 26 // Defines the pin number (26) where an speaker is connected.
#define DHTPIN 15 // Defines the pin number (15) where the DHT22 temperature and humidity sensor is connected.
#define DHTTYPE DHT22 // Specifies the type of the DHT sensor, in this case, DHT22
DHT_Unified dht(DHTPIN, DHTTYPE);
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

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

unsigned long previousMillis = 0;
int playMusicValue = 0;
float temperature, humidity;

// Define the melody for the alarm
int alarmMelody[] = {
  494, 659, 783, 987, 1047, 1175, 1319, 1568
};
int alarmNoteDurations[] = {
  200, 200, 200, 200, 200, 200, 200, 200
};

void setup() {
  Serial.begin(115200);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  pinMode(WATER_PIN, INPUT);
  pinMode(SPEAKER_PIN, OUTPUT);
  dht.begin();
  strip.begin(); 
  strip.setBrightness(150);
}

void loop() {
  Blynk.run();
  if( millis() - previousMillis >= 5000)
  {
    int waterValue = analogRead(WATER_PIN);
    Serial.println(waterValue);
    readDHT22();
    Blynk.virtualWrite(V1, temperature); // Temperature
    Blynk.virtualWrite(V2, humidity); // Humidity
    String MakeUrlParams = String(humidity)
+ "&temperature=" + String(temperature)
+ "&water=" + String(waterValue);
    Blynk.virtualWrite(V3, MakeUrlParams); // MakeUrlParams
    
    previousMillis = millis();
  }

// This condition checks if we received an event (from V4) from Blynk to trigger the alarm
  if (playMusicValue) {
    for (int i = 0; i < sizeof(alarmMelody) / sizeof(alarmMelody[0]); i++) {
      playMusic(alarmMelody[i], 1000 / alarmNoteDurations[i]);
    }
  }
}


/* This function will be called every time Slider Widget
in Blynk app writes values to the Virtual Pin V0
*/
BLYNK_WRITE(V0) {
  int pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
  Serial.printf("got value: %d\n", pinValue);
  
  for (int i = 0; i < pinValue; i++) {
    strip.setPixelColor(i, strip.Color(0, 255, 0));
  }
  for (int i = pinValue; i < 12; i++) {
    strip.setPixelColor(i, strip.Color(255, 0, 0));
  }
  
  strip.show();
}

/*
Blynk event handler for receiving data from virtual pin V4.
This function updates the 'playMusicValue' variable with the incoming value
and prints it to the serial monitor for debugging purposes.
*/
BLYNK_WRITE(V4) {
  playMusicValue = param.asInt(); // assigning incoming value from pin V4 to a variable
  Serial.printf("got value: %d\n", playMusicValue);
}

// This function reads the temperature and humidity from a DHT22 sensor connected to an Arduino board
void readDHT22() {
  sensors_event_t event;
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println(F("Error reading temperature!"));
  }
  else {
    Serial.print(F("Temperature: "));
    Serial.print(event.temperature);
    Serial.println(F("°C"));
    temperature = event.temperature;
  }
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    Serial.println(F("Error reading humidity!"));
  }
  else {
    Serial.print(F("Humidity: "));
    Serial.print(event.relative_humidity);
    Serial.println(F("%"));
    humidity = event.relative_humidity;
  }
}

/* This function allows you to easily play musical notes of different pitches and durations on
an Arduino using a speaker connected to a specific pin
*/
void playMusic(int pitch, int duration) {
  tone(SPEAKER_PIN, pitch, duration);
  delay(duration + 50); // Adding a small delay between notes
  noTone(SPEAKER_PIN);
}

Authors

Bar Kestenboum And Tom Polak