Introduction
In this experiment, we will use a water level sensor to detect the presence of water at various levels in a container. This sensor can be useful in applications such as automatic water level control in tanks.
Components Needed
- Water Level Sensor
- Arduino (e.g., Uno, Nano)
- Jumper wires
- Breadboard
Circuit Setup
- Connect the VCC pin of the water level sensor to the 5V pin of the Arduino.
- Connect the GND pin of the sensor to the GND pin of the Arduino.
- Connect the Signal (S) pin of the sensor to pin A0 on the Arduino.
Check the connections and ensure the sensor is positioned in a water container.
Code for Water Level Sensor
Upload the following code to your Arduino to read the water level:
const int sensorPin = A0; // Pin connected to the water level sensor
void setup() {
Serial.begin(9600); // Start serial communication
}
void loop() {
int sensorValue = analogRead(sensorPin); // Read the sensor value
Serial.println(sensorValue); // Display the water level in the Serial Monitor
delay(500); // Delay for stability
}
Explanation
The sensor detects the water level based on electrical conductivity. The analog value is read by the Arduino and displayed on the Serial Monitor, indicating the water level.
Troubleshooting
- If no data appears, check the wiring and ensure the sensor is correctly connected to the analog pin.
- If the values are inconsistent, try stabilizing the water and ensuring the sensor is fully submerged.