0% found this document useful (0 votes)
2 views1 page

Arduino Code for Water Level Monito

This document provides Arduino code for a water level monitoring system using a flip-flop output mechanism. It reads the water level from a sensor and toggles an output pin based on defined high and low thresholds. The code includes setup and loop functions for initializing the output and continuously monitoring the water level, with serial output for debugging purposes.

Uploaded by

Asanka
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)
2 views1 page

Arduino Code for Water Level Monito

This document provides Arduino code for a water level monitoring system using a flip-flop output mechanism. It reads the water level from a sensor and toggles an output pin based on defined high and low thresholds. The code includes setup and loop functions for initializing the output and continuously monitoring the water level, with serial output for debugging purposes.

Uploaded by

Asanka
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
You are on page 1/ 1

Arduino Code for Water Level Monitoring with Flip-Flop Output

cpp

Copy
const int waterSensorPin = A0; // Analog pin for water level sensor
const int outputPin = 13; // Output pin (LED or relay)
const int lowThreshold = 300; // Low water level threshold (adjust based on
sensor)
const int highThreshold = 600; // High water level threshold (adjust based on
sensor)
boolean outputState = false; // Tracks output state (false = OFF, true = ON)

void setup() {
pinMode(outputPin, OUTPUT); // Set output pin as OUTPUT
digitalWrite(outputPin, outputState); // Initialize output state
Serial.begin(9600); // Start Serial for debugging
}

void loop() {
int waterLevel = analogRead(waterSensorPin); // Read water level (0-1023)

// Print water level for debugging


Serial.print("Water Level: ");
Serial.println(waterLevel);

// Flip-flop logic based on water level thresholds


if (waterLevel >= highThreshold && !outputState) {
outputState = true; // Toggle output ON
digitalWrite(outputPin, HIGH);
} else if (waterLevel <= lowThreshold && outputState) {
outputState = false; // Toggle output OFF
digitalWrite(outputPin, LOW);
}

delay(100); // Small delay for stable readings


}

You might also like