Arduino-Based Water Quality Monitoring System with Ultrasonic, pH, and Temperature Sensors
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor the water level, pH, and temperature of a water tank. It uses an Arduino UNO microcontroller to read data from an ultrasonic sensor, a pH meter, and a temperature sensor. The data is displayed on a 20x4 I2C LCD. The system alerts the user if the water level is high or low.
Component List
Lcd 20x4 i2c
- Description: 20x4 character LCD with I2C interface.
- Pins: GND, 5V, SCA, SCL
Arduino UNO
- Description: Microcontroller board based on the ATmega328P.
- 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
Ultrasonic Sensor
- Description: Sensor to measure distance using ultrasonic waves.
- Pins: +VCC, Trigger, Echo, GND
PH Meter
- Description: Sensor to measure the pH level of a solution.
- Pins: Signal, VCC, GND
Temperature Sensor
- Description: Sensor to measure temperature.
- Pins: Temp GND Black, Temp VDD Red, Temp DQ Data Yellow
Wiring Details
Lcd 20x4 i2c
- GND connected to Arduino UNO GND
- 5V connected to Arduino UNO 5V
- SCA connected to Arduino UNO SDA
- SCL connected to Arduino UNO SCL
Arduino UNO
5V connected to:
- Lcd 20x4 i2c 5V
- Ultrasonic Sensor +VCC
- Temperature Sensor Temp DQ Data Yellow
- PH Meter VCC
GND connected to:
- Lcd 20x4 i2c GND
- Ultrasonic Sensor GND
- Temperature Sensor Temp GND Black
- PH Meter GND
D9 connected to Ultrasonic Sensor Trigger
D8 connected to Ultrasonic Sensor Echo
D10 connected to Temperature Sensor Temp VDD Red
SCL connected to Lcd 20x4 i2c SCL
SDA connected to Lcd 20x4 i2c SCA
D11 connected to PH Meter Signal
Ultrasonic Sensor
- +VCC connected to Arduino UNO 5V
- GND connected to Arduino UNO GND
- Trigger connected to Arduino UNO D9
- Echo connected to Arduino UNO D8
PH Meter
- Signal connected to Arduino UNO D11
- VCC connected to Arduino UNO 5V
- GND connected to Arduino UNO GND
Temperature Sensor
- Temp GND Black connected to Arduino UNO GND
- Temp VDD Red connected to Arduino UNO D10
- Temp DQ Data Yellow connected to Arduino UNO 5V
Documented Code
Arduino UNO Code
/*
* This Arduino Sketch reads data from an ultrasonic sensor, pH meter, and
* temperature sensor to monitor the water level, pH, and temperature of a
* water tank. The data is displayed on a 20x4 I2C LCD. The system alerts
* the user if the water level is high or low.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define TRIGGER_PIN 9
#define ECHO_PIN 8
#define PH_PIN 11
#define TEMP_PIN 10
LiquidCrystal_I2C lcd(0x27, 20, 4);
OneWire oneWire(TEMP_PIN);
DallasTemperature sensors(&oneWire);
void setup() {
lcd.begin();
lcd.backlight();
pinMode(TRIGGER_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
sensors.begin();
Serial.begin(9600);
}
void loop() {
// Measure water level
digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);
long duration = pulseIn(ECHO_PIN, HIGH);
float distance = (duration / 2.0) * 0.0343;
// Read pH value
int phValue = analogRead(PH_PIN);
float voltage = phValue * (5.0 / 1023.0);
float ph = 3.5 * voltage;
// Read temperature
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
// Display data on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Water Level: ");
if (distance < 10) {
lcd.print("High");
} else {
lcd.print("Low");
}
lcd.setCursor(0, 1);
lcd.print("pH: ");
lcd.print(ph);
lcd.setCursor(0, 2);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
delay(2000); // Update every 2 seconds
}
Lcd 20x4 i2c Code
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}