

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.
5V and GND pins provide power to the I2C LCD, Relay Module, Photocell, Soil Moisture Sensor, and DHT11 sensor.A0 pin connected to the Photocell through a 200 Ohm resistor for light measurement.A2 pin connected to the Soil Moisture Sensor for moisture level detection.SCL and SDA pins connected to the I2C LCD for data display.D10 pin controls the Relay Module's IN1, which in turn controls the Water Pump.D8 pin controls the Relay Module's IN2, which in turn controls the LED bulb.D4 pin connected to the DHT11 sensor for temperature and humidity readings.SCL and SDA pins connected to the corresponding pins on the Arduino UNO for I2C communication.VCC (5V) and GND pins connected to the power supply lines.S pin connected to D4 on the Arduino UNO for data signal.5V and GND pins connected to the power supply lines.IN1 and IN2 pins connected to D10 and D8 on the Arduino UNO for control signals.VCC connected to the 5V power supply line.GND connected to the ground line.NO1 connected to the Water Pump's VCC.NO2 connected to the LED bulb's +.VCC connected to NO1 on the Relay Module.GND connected to the ground line.+ connected to NO2 on the Relay Module.- connected to the ground line.SIG pin connected to A2 on the Arduino UNO for signal output.VCC and GND pins connected to the power supply lines.A0 on the Arduino UNO through a 200 Ohm resistor.A0 on the Arduino UNO.#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.