Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Automated Plant Watering and Light Management System

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Automated Plant Watering and Light Management System

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with various sensors and actuators for environmental monitoring and control. It includes an I2C LCD for display, a DHT11 sensor for temperature and humidity measurements, a soil moisture sensor, a photocell (LDR) with a resistor for light detection, a relay module to control a water pump and an LED bulb, and the water pump and LED bulb as the actuators.

Component List

Arduino UNO

I2C LCD 16x2 Screen

KY-015 DHT11

Relay Module 2 Channel

Water Pump

LED bulb AC / Bombillo AC

SparkFun Soil Moisture Sensor

Photocell (LDR)

Resistor

Wiring Details

Arduino UNO

I2C LCD 16x2 Screen

KY-015 DHT11

Relay Module 2 Channel

Water Pump

LED bulb AC / Bombillo AC

SparkFun Soil Moisture Sensor

Photocell (LDR)

Resistor

Documented Code

#include <dht11.h>
#define DHT11PIN 4

// Including Libraries for I2C LCD
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Initialize the DHT sensor
dht11 DHT11;

// Initialize LCD
LiquidCrystal_I2C lcd(0x27, 20, 2); // Set the LCD address to 0x27 for a 20 chars and 4 line display

const int maxLDRValue = 1023;
const int maxSMSValue = 1023;

// Light duration variables
const unsigned long lightDurationThreshold = 50400000; // 14 hours in milliseconds
const unsigned long resetDuration = 86400000; // 24 hours in milliseconds
unsigned long lightDuration = 0;
unsigned long startTime = 0;
bool lightDetected = false;

void setup() 
{
  pinMode(A0, INPUT); // Photoresistor
  pinMode(A2, INPUT); // Soil Moisture
  pinMode(D10, OUTPUT); // Pump
  pinMode(D8, OUTPUT); // Lamp
  Serial.begin(9600); 
  lcd.begin();
  startTime = millis(); // Initialize start time
}

void loop() 
{
  delay(1000);
  int chk = DHT11.read(DHT11PIN);
  int photoresistorValue = analogRead(A0);
  int soilmoistureValue = analogRead(A2);
  float percentage = (float)photoresistorValue / maxLDRValue * 100;
  float percentageSMS = (float)soilmoistureValue / maxSMSValue * 100;
  
  // Soil moisture control
  if (percentageSMS < 40) {
    digitalWrite(D10, HIGH); // Turn on pump
  } else {
    digitalWrite(D10, LOW); // Turn off pump
  }

  // Light control
  if (percentage > 20) {
    lightDetected = true;
    lightDuration += millis() - startTime; // Accumulate time in light
  } else {
    lightDetected = false;
  }

  // Reset light duration after 24 hours
  if (millis() - startTime >= resetDuration) {
    lightDuration = 0; // Reset light duration
    startTime = millis(); // Reset start time
  }

  // Check light duration
  if (lightDuration >= lightDurationThreshold) {
    digitalWrite(D8, LOW); // Turn off lamp
  } else if (!lightDetected) {
    digitalWrite(D8, HIGH); // Turn on lamp if light duration not reached
  }

  // Display data on LCD
  lcd.setCursor(0, 0);
  lcd.print("Temperature,");
  lcd.setCursor(0, 1);
  lcd.print("Lumen & humidity");
  delay(1000);
  lcd.clear();
  
  lcd.print("Temp: ");
  lcd.print(DHT11.temperature);
  lcd.print((char)223);  
  lcd.print("C");
  
  lcd.setCursor(0, 1);
  lcd.print("Hum: ");
  lcd.print(DHT11.humidity);
  lcd.print("%  ");
  delay(1000);

  lcd.setCursor(0, 1);
  lcd.print("SM percentage:");
  lcd.print(percentageSMS);
  delay(1000);

  lcd.clear();
  if (percentage > 40) {
    lcd.print("Light: ");
    lcd.print(percentage);
    lcd.print("%");
  } else {
    lcd.print("There isn't ");
    lcd.setCursor(0, 1);
    lcd.print("enough light");
    delay(800);
    lcd.clear();
    lcd.print("Light percentage is:");
    lcd.setCursor(0, 1);
    lcd.print(percentage);
    lcd.print("%");
  }
  delay(1000);
  lcd.clear();
}

This code is responsible for reading sensor data, controlling the actuators, and displaying information on the LCD. It includes a light duration feature to control the LED bulb based on the amount of light detected during a 24-hour period. The water pump is controlled based on the soil moisture level. The temperature and humidity are read from the DHT11 sensor and displayed on the LCD along with the light and soil moisture percentages.