0% found this document useful (0 votes)
16 views3 pages

Arduino Moisture and Water Level Sensors

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)
16 views3 pages

Arduino Moisture and Water Level Sensors

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

makle thi 2 codes on 1 sketch

const int sensor1Pin = A0; // Analog pin for moisture sensor


const int outputPin1 = 3; // Digital pin for controlling an output (e.g., an
LED)
int moistureValue;

// Sensor 2 Setup
const int sensor2Pin = A1; // Analog pin for moisture sensor
const int outputPin2 = 4; // Digital pin for controlling an output (e.g., an
LED)
int moistureValue2;

// Sensor 3 Setup
const int sensor3Pin = A2; // Analog pin for the water level sensor
const int buzzerPin = 8; // Digital pin for the buzzer
const int threshold = 500; // Threshold for the water level sensor

void setup() {
pinMode(outputPin1, OUTPUT);
pinMode(outputPin2, OUTPUT);
pinMode(buzzerPin, OUTPUT);
[Link](9600);
[Link]("Reading from sensors...");
}

void loop() {
// Reading from Sensor 1
moistureValue = analogRead(sensor1Pin);
moistureValue = map(moistureValue, 550, 10, 0, 100);
[Link]("Moisture: ");
[Link](moistureValue);
[Link]("%");

if (moistureValue > 0) {
digitalWrite(outputPin1, HIGH); // Turn on the output if moisture value is
above 0
} else {
digitalWrite(outputPin1, LOW); // Turn off the output if moisture value is 0
or below
}

// Reading from Sensor 2


moistureValue2 = analogRead(sensor2Pin);
moistureValue2 = map(moistureValue2, 550, 10, 0, 100);
[Link]("Moisture: ");
[Link](moistureValue2);
[Link]("%");

if (moistureValue2 > 0) {
digitalWrite(outputPin2, HIGH); // Turn on the output if moisture value is
above 0
} else {
digitalWrite(outputPin2, LOW); // Turn off the output if moisture value is 0
or below
}

// Reading from Sensor 3


int sensor3Value = analogRead(sensor3Pin);
[Link]("Sensor 3 Value: ");
[Link](sensor3Value);

if (sensor3Value < threshold) {


digitalWrite(buzzerPin, HIGH); // Turn buzzer on
} else {
digitalWrite(buzzerPin, HIGH); // Turn buzzer on for 200ms
delay(200);
digitalWrite(buzzerPin, LOW); // Turn buzzer off
delay(200);
}

delay(1000); // Delay for stability


}

and this

#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);
}

Common questions

Powered by AI

The system's reliability in rapidly changing moisture environments might be limited due to the fixed delay of 1000ms between readings, which could cause it to miss rapid fluctuations. While this delay provides stability and readability in normal conditions, it may result in delayed response in dynamic settings, potentially failing to signal timely alerts. Moreover, mapped readings based on a specific range may not adapt to all environmental variances, risking incorrect representation if sensors aren't recalibrated for new conditions .

The code ensures stability and readability by implementing a delay of 1000ms at the end of each loop iteration to prevent rapid updates, which allows for stable readings that are easier to observe. For readability, the sketch maps the sensor values from their raw readings to a 0-100 percentage scale, providing a human-friendly representation. Additionally, conditional checks limit the maximum value to prevent erroneous readings beyond the expected sensor range .

The water level sensor connected to pin A2 monitors the water presence by comparing its reading to a threshold value of 500. If the reading is below this threshold, indicating sufficient water, the program keeps the buzzer on continuously. If above, indicating low water, the buzzer sounds intermittently (ON for 200ms, OFF for 200ms) to signal an alert .

The sketch reads moisture values from two sensors using analog inputs A0 and A1. These values are then mapped from a range of 550 (dry) to 10 (wet) to a percentage between 0 and 100. If the moisture value is greater than 0, the corresponding digital output pins (3 and 4) are set to HIGH to indicate activation, such as turning on an LED. Otherwise, the outputs are set to LOW .

Water presence is evaluated by reading the sensor3 value and comparing it to a threshold of 500. Values below the threshold indicate sufficient water, prompting the program to keep the buzzer on to denote normal operation. If the value exceeds the threshold, indicating absence of water, the buzzer alternates between ON and OFF, serving as an alert to the user. This mechanism allows the program to quickly notify when intervention is needed due to low water levels, thus aiding in decision-making for maintenance or system checks .

The program checks sensor1 and sensor2 readings against a predefined maximum sensor reading of 1000, capping values beyond this threshold to ensure only realistic, expected data is processed. This prevents erroneous or out-of-range values from affecting output. However, this approach could be improved by dynamically adjusting thresholds based on environmental conditions or through sensor recalibration mechanisms to handle inconsistencies between different deployment scenarios .

The LCD, addressed via I2C at 0x27, displays the moisture percentages for two sensors. The sensor values, read and mapped to a percentage, are printed on the LCD's first line. The sketch uses commands to set the cursor position and print 'S1:' followed by the percentage for sensor1 and ' S2:' for sensor2 on the same line. For the second line, it checks the water level sensor's status and prints 'Tank: Water OK' if water is present, or 'Tank: No Water' if absent .

The setup uses an LCD to visualize sensor data, providing instant feedback about moisture levels and water presence. While effective for immediate interaction, enhancements like adding a larger display with graphical capabilities could enhance user experience by showing historical trends or alerts. Additionally, integrating connectivity features, such as sending data to a mobile app or server for remote monitoring and data logging, could significantly improve user interaction and response capabilities .

Scalability is confined by the number of available analog and digital pins on the microcontroller. On the software side, additional sensors would require expanded mapping and conditional logic, possibly complicating the code. However, modularizing the code into functions for sensor reading and output control could improve manageability. On the hardware side, expanding beyond a few sensors or outputs would necessitate microcontroller upgrades or multiplexing techniques, adding complexity in wiring and potential for increased signal interference .

Mapping raw sensor values to a percentage range of 0 to 100 standardizes the output, making it easier for users to interpret moisture levels as a percentage of maximum expected sensor response. This conversion abstracts away the raw ADC values, which can differ between environments or applications, providing a consistent and intuitive measure that aligns with common understanding .

You might also like