Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Based Flood Alert System with pH Monitoring and Bluetooth Connectivity

Image of Arduino UNO Based Flood Alert System with pH Monitoring and Bluetooth Connectivity

Circuit Documentation

Summary

This circuit is designed to monitor water levels and pH values, providing visual and auditory alerts when water levels exceed a certain threshold. It utilizes an Arduino UNO as the central microcontroller to interface with a water level sensor, a pH sensor module (ph4502c), a buzzer, a servo motor, and a Bluetooth module for potential wireless communication. An LED is also included to provide a visual indication of the water level status.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P
  • It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.

Water Level Sensor

  • A sensor that detects the level of water in a tank or other reservoir.
  • It has three pins: SIG (signal), VCC (power), and GND (ground).

Tower Pro SG90 Servo

  • A small and lightweight servo motor capable of precise control.
  • It has three pins: Signal, +5V, and GND.

Buzzer

  • An electronic buzzer for audible alerts.
  • It has two pins: PIN (signal input) and GND (ground).

HC-05 Bluetooth Module

  • A wireless communication module that allows for Bluetooth connectivity.
  • It has six pins: Key, VCC, TXD, RXD, State, and GND.

PH Meter (ph4502c)

  • A sensor module used for measuring the pH level of a liquid.
  • It has six pins: VCC, G1, G2, Po, Do, and To.

LED: Two Pin (red)

  • A basic red LED for visual signaling.
  • It has two pins: cathode (-) and anode (+).

Resistor

  • A 220 Ohm resistor used to limit current to the LED.
  • It has two pins: pin1 and pin2.

Wiring Details

Arduino UNO

  • D2 connected to Resistor (for LED control)
  • GND connected to common ground net
  • D10 connected to Buzzer
  • D9 connected to Tower Pro SG90 Servo (Signal)
  • 5V connected to common VCC net
  • A0 connected to PH Meter (Po)
  • A5 connected to Water Level Sensor (SIG)
  • D7 connected to Water Level Sensor (VCC)
  • D1 connected to HC-05 Bluetooth Module (RXD)
  • D0 connected to HC-05 Bluetooth Module (TXD)

Water Level Sensor

  • SIG connected to Arduino UNO (A5)
  • VCC connected to Arduino UNO (D7)
  • GND connected to common ground net

Tower Pro SG90 Servo

  • Signal connected to Arduino UNO (D9)
  • +5V connected to common VCC net
  • GND connected to common ground net

Buzzer

  • PIN connected to Arduino UNO (D10)
  • GND connected to common ground net

HC-05 Bluetooth Module

  • VCC connected to common VCC net
  • TXD connected to Arduino UNO (D0)
  • RXD connected to Arduino UNO (D1)
  • GND connected to common ground net

PH Meter (ph4502c)

  • VCC connected to common VCC net
  • Po connected to Arduino UNO (A0)
  • G1 connected to common ground net

LED: Two Pin (red)

  • Cathode connected to common ground net
  • Anode connected to Resistor (pin2)

Resistor

  • Pin1 connected to Arduino UNO (D2)
  • Pin2 connected to LED (anode)

Documented Code

#include <Servo.h>

#define BUZZER_PIN 10  // Pin for the buzzer
#define POWER_PIN   7
#define SIGNAL_PIN  A5
#define THRESHOLD   500
#define LED_PIN     2
#define SERVO_PIN   9  // Pin for the servo motor

Servo servo; // create servo object to control a servo
int value = 0; // variable to store the water level sensor value
int angle = 0; // the current angle of servo motor
const int pHSensorPin = A0;

// Calibration values for pH sensor
const float neutralVoltage = 2.5; // Voltage corresponding to pH 7.0 (adjust based on your measurement)
const float scaleFactor = 3.5;    // pH sensitivity (adjust if necessary)

void setup() {
  Serial.begin(9600);
  pinMode(BUZZER_PIN, OUTPUT);  // set buzzer pin as output
  pinMode(LED_PIN, OUTPUT);      // configure D2 pin as an OUTPUT
  pinMode(POWER_PIN, OUTPUT);    // configure D7 pin as an OUTPUT
  digitalWrite(POWER_PIN, LOW);  // turn the sensor OFF
  digitalWrite(LED_PIN, LOW);    // turn LED OFF
  servo.attach(SERVO_PIN);       // attaches the servo on pin 9 to the servo object
  servo.write(angle);            // initialize the servo at 0 degrees
}

void loop() {
  digitalWrite(POWER_PIN, HIGH);  // turn the water level sensor ON
  value = analogRead(SIGNAL_PIN); // read the analog value from the water level sensor
  digitalWrite(POWER_PIN, LOW);   // turn the sensor OFF

  // Display the water level value on the serial monitor
  Serial.print("Water Level: ");  
  Serial.println(value);          // Print the actual water level value
  
  // Read and display the pH sensor value
  int sensorValue = analogRead(pHSensorPin);  // Read the analog value from the pH sensor
  float voltage = sensorValue * (5.0 / 1023.0); // Convert the analog value to voltage
  
  // Adjust the formula to invert pH scaling
  float pHValue = 7.0 - ((voltage - neutralVoltage) * scaleFactor);
  pHValue = constrain(pHValue, 0.0, 14.0); // Constrain pH value to a valid range
  
  Serial.print("pH Value: ");    // Show the pH value on the serial monitor
  Serial.println(pHValue);

  delay(100);  // wait 100 milliseconds
  
  // Water level detection and actions when the value is greater than THRESHOLD (500)
  if (value > THRESHOLD) {
    Serial.println("AMARAN BANJIR! Air melebihi Paras Normal"); // Custom alert message
    digitalWrite(LED_PIN, HIGH);  // Turn LED ON

    // Calculate the siren speed and frequency range based on the water level
    int beepDelay = map(value, 500, 700, 500, 100);  // Faster beeps as value increases
    int freqMin = map(value, 500, 700, 500, 800);  // Lower frequency increases with water level
    int freqMax = map(value, 500, 700, 1000, 1500);  // Higher frequency increases with water level

    // Create a sweeping siren effect between freqMin and freqMax
    for (int freq = freqMin; freq <= freqMax; freq += 50) {
      tone(BUZZER_PIN, freq);  // Start with low frequency and increase
      delay(beepDelay / 10);   // Shorter delay for smooth frequency sweep
    }
    for (int freq = freqMax; freq >= freqMin; freq -= 50) {
      tone(BUZZER_PIN, freq);  // Decrease frequency to create the siren sweep
      delay(beepDelay / 10);   // Same shorter delay
    }

    // Control the servo to rotate to 180 degrees, then back to 0 degrees
    servo.write(180);  
    delay(500);       // Wait for the servo to reach the position
    servo.write(0);

    // Turn off LED after the sequence
    digitalWrite(LED_PIN, LOW);
  }
  else {
    // Turn off LED and stop the buzzer when the water level is below the threshold
    digitalWrite(LED_PIN, LOW);
    noTone(BUZZER_PIN);  // Stop the buzzer
    servo.write(0);      // Keep the servo at 0 degrees
  }
}

This code is designed to run on the Arduino UNO microcontroller. It initializes the connected devices and enters a loop where it reads the water level and pH values, providing alerts and actuating a servo motor if the water level exceeds a predefined threshold. The code includes comments for clarity and can be adjusted for calibration and sensitivity of the pH sensor.