A non-contact water level sensor is an electronic device that uses ultrasonic technology to measure the distance to the water surface. This sensor provides accurate water level readings without requiring any physical contact with the liquid, making it ideal for applications where traditional contact-based sensors may be impractical or unsanitary. Common applications include water conservation systems, fluid tanks in industrial processes, and household appliances like coffee makers or washing machines.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (5V DC) |
2 | GND | Ground |
3 | TRIG | Trigger input (TTL level) |
4 | ECHO | Echo output (TTL level) |
5 | OUT | Analog or digital output (model dependent) |
// Define the Arduino pins connected to the sensor's TRIG and ECHO pins
const int trigPin = 9;
const int echoPin = 10;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Define the TRIG pin as an output and the ECHO pin as an input
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// Clear the TRIG pin by setting it LOW
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
// Trigger the sensor by setting the TRIG pin HIGH for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the time duration of the returned ECHO signal
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance based on the speed of sound (34300 cm/s)
// and the time duration of the ECHO signal. Since the sound wave travels
// to the water surface and back, we divide the duration by 2.
float distance = duration * 0.0343 / 2;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Delay between measurements
delay(1000);
}
Q: Can the sensor be used with liquids other than water? A: Yes, but the sensor's accuracy may vary depending on the liquid's surface properties.
Q: Is the sensor waterproof? A: The sensor's body is typically water-resistant, but the component should not be submerged unless specified by the manufacturer.
Q: How can I extend the sensor's range? A: The range is determined by the sensor's design and cannot be extended beyond its maximum specified limit.