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

Arduino UNO Based Environmental Monitoring System with LCD Feedback

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Environmental Monitoring System with LCD Feedback

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions and provide alerts through a buzzer and an LCD display. It includes an Arduino UNO microcontroller, a DHT11 temperature and humidity sensor, a photocell (LDR) for light sensing, a water level sensor, a piezo buzzer for audible alerts, and an LCD screen with I2C interface for visual feedback. The circuit is likely used for monitoring plant growth conditions, such as light intensity, temperature, humidity, and water level, and alerting the user when these parameters are outside of the desired range.

Component List

Arduino UNO

DHT11

Photocell (LDR)

Water Level Sensor

Piezo Buzzer

LCD screen 16x2 I2C

Resistor (10k Ohms)

Wiring Details

Arduino UNO

DHT11

Photocell (LDR)

Water Level Sensor

Piezo Buzzer

LCD screen 16x2 I2C

Resistor (10k Ohms)

Documented Code

#include <Arduino.h>
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Define pins
const int lightSensorPin = A0;
const int buzzerPin = 3;
const int waterLevelSensorPin = 4;
const int dhtPin = 5;

// LCD setup (I2C address 0x27 is common, check your LCD address)
LiquidCrystal_I2C lcd(0x27, 16, 2);

// DHT sensor setup (DHT22 or DHT11)
#define DHTTYPE DHT11
DHT dht(dhtPin, DHTTYPE);

// Set thresholds for Chinese Money Plant
const int lightHighThreshold = 800;  // Too much light (bright direct light)
const int lightLowThreshold = 300;   // Too little light (dim light)
const float tempHighThreshold = 30.0; // Max temperature (too hot)
const float tempLowThreshold = 18.0;  // Min temperature (too cold)
const int waterLevelHighThreshold = 1;  // Water sensor detects high water level (overwatering)
const int waterLevelLowThreshold = 0;   // Water sensor detects low water level (underwatering)
const unsigned long buzzerDuration = 1000; // Buzzer on duration

bool isAlarmActive = false;
unsigned long buzzerStartTime = 0;

void setup() {
  pinMode(lightSensorPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(waterLevelSensorPin, INPUT);
  
  dht.begin();
  lcd.init();  // Initialize the LCD
  lcd.backlight();  // Turn on the LCD backlight
  
  Serial.begin(9600);
  lcd.clear();  // Ensure the LCD is cleared on startup
}

void loop() {
  // Read sensor values
  int lightValue = analogRead(lightSensorPin);
  float temperature = dht.readTemperature();
  int waterLevel = digitalRead(waterLevelSensorPin);

  // Print sensor values for debugging
  Serial.print("Light: ");
  Serial.println(lightValue);
  Serial.print("Temperature: ");
  Serial.println(temperature);
  Serial.print("Water Level: ");
  Serial.println(waterLevel);

  // Check for errors and alarms
  bool errorCondition = false;
  String errorMessage = "";

  // Light intensity check
  if (lightValue > lightHighThreshold) {
    errorMessage = "Too much light!";
    errorCondition = true;
  } else if (lightValue < lightLowThreshold) {
    errorMessage = "Too little light!";
    errorCondition = true;
  }

  // Temperature check
  if (temperature > tempHighThreshold) {
    errorMessage = "Temp too high!";
    errorCondition = true;
  } else if (temperature < tempLowThreshold) {
    errorMessage = "Temp too low!";
    errorCondition = true;
  }

  // Water level check
  if (waterLevel == waterLevelHighThreshold) {
    errorMessage = "Water too high!";
    errorCondition = true;
  } else if (waterLevel == waterLevelLowThreshold) {
    errorMessage = "Water too low!";
    errorCondition = true;
  }

  // Activate alarm if an error condition is detected
  if (errorCondition) {
    activateAlarm(errorMessage, lightValue, temperature, waterLevel);
  } else {
    deactivateAlarm();
  }
}

// Function to activate alarm and show on LCD
void activateAlarm(String errorMessage, int lightValue, float temperature, int waterLevel) {
  if (!isAlarmActive) {
    isAlarmActive = true;
    buzzerStartTime = millis();
    Serial.println("Alarm activated: " + errorMessage);
    lcd.clear();  // Clear the LCD to show the new message
  }

  // Keep the buzzer on for the specified duration
  if (millis() - buzzerStartTime < buzzerDuration) {
    digitalWrite(buzzerPin, HIGH);
    
    // Display alarm message and sensor values on the LCD
    lcd.setCursor(0, 0);
    lcd.print("ALARM: ");
    lcd.print(errorMessage);

    // Display light and temperature values on the second line
    lcd.setCursor(0, 1);
    lcd.print("L:");
    lcd.print(lightValue);
    lcd.print(" T:");
    lcd.print(temperature);
    lcd.print("C");
  } else {
    digitalWrite(buzzerPin, LOW);
    isAlarmActive = false;
  }
}

// Function to deactivate alarm and clear LCD
void deactivateAlarm() {
  if (isAlarmActive) {
    digitalWrite(buzzerPin, LOW);
    isAlarmActive = false;
    lcd.clear();  // Clear the LCD when no alarm is active
  }
}

This code is responsible for reading sensor data, determining if any of the readings are outside of the predefined thresholds, and then activating an alarm if necessary. The alarm consists of an audible alert from the buzzer and a visual message on the LCD screen. The code also includes debugging outputs to the serial monitor for monitoring sensor values.