A water sensor is an electronic device that is designed to detect the presence of water or other conductive liquids. It is commonly used in applications such as flood or leak detection in homes, offices, and industrial settings. The sensor can trigger alarms, notifications, or activate pumps to prevent water damage.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Connect to 3.3V or 5V power supply |
2 | GND | Connect to ground |
3 | DO | Digital output; goes high when water is detected |
4 | AO | Analog output; outputs a voltage proportional to water level |
// Define the water sensor digital output pin
int waterSensorPin = 2;
// Define the variable to store the sensor status
int sensorStatus;
void setup() {
// Initialize the water sensor pin as an input
pinMode(waterSensorPin, INPUT);
// Begin serial communication at a baud rate of 9600
Serial.begin(9600);
}
void loop() {
// Read the sensor value
sensorStatus = digitalRead(waterSensorPin);
// Check if water is detected
if (sensorStatus == HIGH) {
Serial.println("Water detected!");
} else {
Serial.println("No water detected.");
}
// Wait for a bit before reading again
delay(500);
}
Q: Can the water sensor be used to measure the exact water level? A: The basic water sensor is not designed for precise water level measurement. It is typically used for water detection. For precise measurements, consider using an ultrasonic or float-based level sensor.
Q: Is the water sensor reusable after being submerged? A: This depends on the design of the sensor. Some are designed for single-use, while others can be dried and reused. Check the manufacturer's specifications.
Q: How long can the sensor be exposed to water? A: It varies by model. Some sensors are designed for brief exposure, while others can withstand prolonged periods. Always refer to the manufacturer's guidelines.
Q: Can the sensor detect other liquids? A: Yes, the sensor can detect the presence of any conductive liquid, but it may not perform optimally with liquids other than water. Calibration or different sensor types might be necessary for other liquids.