Skip to the content.

IoT Plant Monitor

This project is essentially a smart watering system that can detect the current temperature, humidity, intensity of light, and soil moisture of a plant of your choosing and displays them on Blynk. You are also able to pump water into the plants by turning on the Switch toggle in Blynk.

Engineer School Area of Interest Grade
Alison L Cupertino High School Computer Science/Product Design Incoming Sophomore

Photo of myself Photo of my project

Final Milestone

My final milestone was finishing everything up and making a setup that can not only track the plant’s information but also pump water into the plant. I had to order a tube that can connect to the water pump to be able to carry water from a bowl of water into the plant itself. My motor would not work for the longest time because I had been powering my board with 3.3 volts because that was the amount the ESP8266 required, except my motor need 5 volts. So, once I plugged the wire that was connecting the VCC in the motor driver board to 5 volts in the arduino, my motor worked and could pump water into my plant. A modification I did for this project was using a LED and a buzzer to notify me when the soil was too dry. After wiring the LED and the buzzer up, I edited my code that would get the LED to light up and the buzzer to sound whenever the soil moisture was too dry. Something I noticed was that the higher the number being displayed for soil moisture meant the drier the soil instead of the other way around. So, in the code I had to write that whenever the soil moisture is greater than a certain amount, the LED would flash and the buzzer would sound.

Second Milestone

My second milestone was mostly getting familiar with Blynk and using the Arduino IDE, as this is my first time using such programs. I started off by connecting my Arduino board to Blynk, then I started adding virtual pins into my Blynk dashboard. A big step I took for my project was actually trying it out. I inputted code into the Arduino IDE, then I put my soil moisture sensor in a plant and had the temperature, humidity, soil moisture etc. data to be displayed on Blynk. You are also able to turn on the water pump by pressing the on and off button on the Blynk dashboard. The main issue that I had to fix for this milestone was getting my Arduino Uno online in Blynk, which was mostly due to my ESP8266 wifi module.

First Milestone

My first milestone was first building my circuit and making sure that all the necessary parts were wired correctly. Then, I made sure that my soil moisture sensor and my humidity and temperature sensor worked by plugging my board into my computer, then I imputted code into the Arduino IDE that would display the temperature, humidity, and soil moisture on the serial monitor. A problem I faced was that my ESP8266 chip could not be plugged directly into the breadboard, so I had to order an adapter for it. It was very frustrating and took a lot of time get the wifi module to work, but with help I managed to get it to work and then I could continue with my project.

Schematics

Schematic

Code

Below is the main code used to send all the data collected from the sensors to Blynk:

#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "ssid";
char pass[] = "password";

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);

#include <DHT.h>
#define DHTPIN 4       // The pin connected to the DHT11 sensor
#define DHTTYPE DHT11  // DHT 11
DHT dht(DHTPIN, DHTTYPE);

#define lightPin A0
#define moisturePin A1
#define pumpA 8

double roomHumidity = 0;
double roomTemperature = 0;

BlynkTimer timer;

BLYNK_WRITE(V0)
{
  if (param.asInt() == 1) {
    digitalWrite(pumpA, HIGH);
  } else {
    digitalWrite(pumpA, LOW);
  }
}

int readMoisture() {
  return analogRead(moisturePin);
}

int readLight() {
  return analogRead(lightPin);
}

void readDHT() {
  roomHumidity = dht.readHumidity();
  roomTemperature = dht.readTemperature();
}

void myTimerEvent()
{
  readDHT();
  int light = readLight();
  int moisture = readMoisture();

  if (!isnan(roomHumidity) && !isnan(roomTemperature)) {
    Serial.print("Humidity: ");
    Serial.print(roomHumidity);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(roomTemperature);
    Serial.println(" *C");
    
    Blynk.virtualWrite(V4, roomHumidity);
    Blynk.virtualWrite(V5, roomTemperature);
  }
  Blynk.virtualWrite(V6, light);
  Blynk.virtualWrite(V7, moisture);
}

void alert(){
  const int buzzerPin = 10; // Change this to the desired digital pin
const int ledPin = 9;  // Change this to the desired digital pin for the LED

void setup() {
  pinMode(buzzerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // Sound the buzzer with a frequency of 1000 Hz for 500 milliseconds (0.5 seconds)
  tone(buzzerPin, 1000);
  delay(500);
  
  // Silence the buzzer for 500 milliseconds
  noTone(buzzerPin);
  delay(500);
    for (int brightness = 0; brightness <= 255; brightness++) {
    analogWrite(ledPin, brightness);
    delay(10); // Adjust the delay time to control the speed of the glow
}
  for (int brightness = 255; brightness >= 0; brightness--) {
    analogWrite(ledPin, brightness);
    delay(10); // Adjust the delay time to control the speed of the glow
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  dht.begin(); // Initialize DHT sensor

  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);

  timer.setInterval(1000L, myTimerEvent);

  pinMode(pumpA, OUTPUT);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}


Here is the code I used to test the DHT11 humidity and temperature sensor:

#include "DHT.h"

#define DHTPIN 4  // The pin connected to the DHT11 sensor

// Uncomment the type of sensor in use:
#define DHTTYPE DHT11   // DHT 11 

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600); 
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again)
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.println(" *C");
}

Here is the code I used to test the soil moisture sensor and the photoresister:

const int soilMoisturePin = A1; // Connect the capacitive soil moisture sensor to analog pin A0
const int photoResistorPin = A0; // Connect the photoresistor to analog pin A1

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Read soil moisture value
  int soilMoistureValue = analogRead(soilMoisturePin);
  int moisturePercentage = map(soilMoistureValue, 0, 1023, 0, 100);
  Serial.print("Soil Moisture Percentage: ");
  Serial.print(moisturePercentage);
  Serial.println("%");

  // Read illumination value
  int illuminationValue = analogRead(photoResistorPin);
  Serial.print("Illumination Value: ");
  Serial.println(illuminationValue);

  delay(1000); // Delay between readings, adjust as needed
}

Bill of Materials

Part Note Price Link
Elegoo Uno R3 Board with USB Cable Microcontroller $15.99 Link
Solderless Breadboards Base for all the components $9.99 for 4pc Link
ESP8266 Module Enables the microcontroller to connect to WiFi $8.99 for 3 pc Link
ESP8266 ESP-01 Breakout Board Adapter to connect the ESP8266 to the breadboard $8.99 for 3 pc Link
Soil Moisture Sensor Sensor to track the plant’s soil moisutre $11.99 for 5 pc Link
DHT11 Humidity Sensor Sensor to track the temperature and humidity of the room $9.99 for 5 pc Link
Photoresistor Sensor to track illumination $5.99 for 30 pc Link
Motor Driver Connects the water pump to the Arduino $11.49 for 4 pc Link
Water Pump and Tube Pumps water into the plant $13.99 for 3 water pumps and a 3M clear tube Link
Jumper Wires Used to make connections between breadboard and Arduino $9.99 for 40 pc each of male to male, female to male, and femae to female jumper wires Link
Buzzers Sounds when plant reaches a certain soil moisture $5.99 for 10 pc Link
LED Lights Lights up when plant reaches a certain soil moisture $5.99 for 60 pc Link