0% found this document useful (0 votes)
5 views2 pages

Arduino I2C LCD Water Sensor Display

Uploaded by

yejixx999
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Arduino I2C LCD Water Sensor Display

Uploaded by

yejixx999
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <Wire.

h>
#include <LiquidCrystal_I2C.h>

// Create an LCD object with I2C address 0x27 (common for many I2C LCDs)
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define the analog pins for the sensors


const int sensor1Pin = A0;
const int sensor2Pin = A1;
const int sensor3Pin = A2;

// Define threshold for the sensor3 to determine water presence


const int waterThreshold = 500; // Adjust based on sensor calibration

// Define maximum sensor values observed


const int maxSensorValue = 1023; // Assuming 10-bit ADC resolution

void setup() {
// Initialize the LCD
[Link]();
[Link](); // Turn on the backlight (if applicable)

// Print initial messages to the LCD


[Link](0, 0);
[Link]("S1: % S2: %");
}

void loop() {
// Read the moisture levels from the sensors
int sensor1Value = analogRead(sensor1Pin);
int sensor2Value = analogRead(sensor2Pin);
int sensor3Value = analogRead(sensor3Pin);

// Check if the sensor value is within a reasonable range (e.g., 0 to 1000)


int maxSensorReading = 1000; // Adjust this based on your sensor's expected range
if (sensor1Value > maxSensorReading) sensor1Value = maxSensorReading;
if (sensor2Value > maxSensorReading) sensor2Value = maxSensorReading;

// Convert the sensor readings to percentages


int sensor1Percent = map(sensor1Value, 0, maxSensorReading, 0, 100);
int sensor2Percent = map(sensor2Value, 0, maxSensorReading, 0, 100);

// Clear the first line and update it with the new sensor values
[Link](0, 0);
[Link]("S1:");
[Link](sensor1Percent);
[Link]("% S2:");
[Link](sensor2Percent);
[Link]("%");

// Clear the second line


[Link](0, 1);
[Link](" "); // Clear previous message

// Check the sensor3 for water presence


[Link](0, 1);
if (sensor3Value < waterThreshold) {
[Link]("Tank: Water OK");
} else {
[Link]("Tank: No Water");
}

// Wait for a second before updating


delay(1000);
}

You might also like