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

Arduino UNO-Based Water Level and Distance Monitoring System with LCD Display and Buzzer Alert

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Water Level and Distance Monitoring System with LCD Display and Buzzer Alert

Circuit Documentation

Summary

This circuit is designed to monitor water levels and detect proximity using an ultrasonic sensor. It uses an Arduino UNO microcontroller to process sensor data and control various output devices, including LEDs, a buzzer, and an LCD display. The water level sensor detects the presence of water, while the ultrasonic sensor measures distance. The system provides visual and auditory alerts based on the sensor readings.

Component List

  1. Water Level Sensor

    • Pins: SIG, VCC, GND
    • Description: Detects the presence of water.
    • Purpose: Monitors water levels.
  2. Arduino UNO

    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
    • Description: Microcontroller board.
    • Purpose: Central processing unit for the circuit.
  3. HC-SR04 Ultrasonic Sensor

    • Pins: VCC, TRIG, ECHO, GND
    • Description: Measures distance using ultrasonic waves.
    • Purpose: Detects proximity.
  4. Buzzer

    • Pins: PIN, GND
    • Description: Emits sound.
    • Purpose: Provides auditory alerts.
  5. 16x2 I2C LCD

    • Pins: GND, VCC, SDA, SCL
    • Description: Displays text.
    • Purpose: Provides visual feedback.
  6. LED: Two Pin (green)

    • Pins: cathode, anode
    • Description: Green LED.
    • Purpose: Indicates safe condition.
  7. LED: Two Pin (yellow)

    • Pins: cathode, anode
    • Description: Yellow LED.
    • Purpose: Indicates alert condition.
  8. LED: Two Pin (red)

    • Pins: cathode, anode
    • Description: Red LED.
    • Purpose: Indicates danger condition.
  9. Resistor (220 Ohms)

    • Pins: pin1, pin2
    • Description: Limits current.
    • Purpose: Protects LEDs from excessive current.

Wiring Details

Water Level Sensor

Arduino UNO

HC-SR04 Ultrasonic Sensor

Buzzer

16x2 I2C LCD

LED: Two Pin (green)

LED: Two Pin (yellow)

LED: Two Pin (red)

Resistor (220 Ohms)

Code Documentation

#include <LiquidCrystal_I2C.h>

// Inisialisasi LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Konstanta dan variabel
const int waterSensor = A0;  // Pin analog untuk sensor air
const int buzzer = 8;        // Pin digital untuk buzzer
const int greenLed = 4;      // Pin LED hijau (Aman)
const int yellowLed = 3;     // Pin LED kuning (Siaga)
const int redLed = 2;        // Pin LED merah (Bahaya)
const int threshold = 600;   // Ambang batas untuk mendeteksi basah (disesuaikan dengan sensor)

// Pin untuk Sensor Ultrasonik
const int trigPin = 11;      // Pin Trigger HC-SR04
const int echoPin = 12;       // Pin Echo HC-SR04

int waterValue = 0;

// Variabel untuk jarak
long duration;
int distance;

void setup() {
  lcd.init();              // Inisialisasi LCD
  lcd.backlight();         // Aktifkan lampu latar LCD
  lcd.setCursor(0, 0);
  lcd.print("Water Sensor"); // Tampilkan judul di LCD

  // Set pin LED dan buzzer sebagai OUTPUT
  pinMode(greenLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(redLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
  
  // Set pin untuk sensor ultrasonik
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  
  // Matikan LED dan buzzer di awal
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(redLed, LOW);
  digitalWrite(buzzer, LOW);
}

void loop() {
  // Membaca nilai dari sensor air
  waterValue = analogRead(waterSensor);
  
  // Menghitung jarak menggunakan sensor ultrasonik
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2); 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.0344 / 2;  // Menghitung jarak dalam cm

  // Menampilkan nilai jarak pada LCD
  lcd.setCursor(0, 1); 
  lcd.print("Dist: ");
  lcd.print(distance);
  lcd.print(" cm    ");  // Menampilkan jarak dalam cm
  
  // Logika untuk mengontrol LED dan buzzer berdasarkan jarak
  if (distance <= 10) { // Jika jarak sangat dekat, misalnya 10 cm atau kurang
    digitalWrite(buzzer, HIGH);  // Nyalakan buzzer
    lcd.setCursor(0, 0);
    lcd.print("Danger - Very Close");
  } else if (distance <= 20) { // Jarak cukup dekat, misalnya 20 cm
    digitalWrite(buzzer, HIGH);  // Nyalakan buzzer
    lcd.setCursor(0, 0);
    lcd.print("Alert - Close");
  } else {
    digitalWrite(buzzer, LOW);   // Matikan buzzer
    lcd.setCursor(0, 0);
    lcd.print("Safe - Far Away");
  }

  // Logika untuk LED berdasarkan kondisi sensor air
  if (waterValue > threshold) {
    // Bahaya (Merah)
    digitalWrite(redLed, HIGH);        // Menyalakan LED merah
    digitalWrite(yellowLed, LOW);    // Mematikan LED kuning
    digitalWrite(greenLed, LOW);     // Mematikan LED hijau
    digitalWrite(buzzer, HIGH);        // Nyalakan buzzer
    lcd.setCursor(0, 1);
   // Tampilkan pesan bahaya di LCD
  } else if (waterValue > (threshold - 500)) {
    // Siaga (Kuning