20 cm to 400 cm (4 meters)
20 cm to 400 cm (4 meters)
1% of measured distance
1 cm
Analog voltage (0-5V), PWM, UART, I2C
5V DC
20 mA (average), 50 mA (peak)
-20C to 70C
-30C to 80C
5% to 95% RH
20 grams
Diameter | 30 mm, Height: 15 mm |
Applications
The Waterproof Ultrasonic Sensor is suitable for a wide range of applications, including |
Obstacle detection and avoidance
Proximity detection
Level measurement
Distance measurement
Object detection
Robotics
Automotive systems
Industrial automation
Weather stations
Agriculture monitoring systems
Pinout and Dimensions
For detailed pinout and dimension information, please refer to the datasheet or contact the manufacturer.
Waterproof Ultrasonic Sensor Documentation
Overview
The Waterproof Ultrasonic Sensor is a durable and weather-resistant sensor designed to measure distances up to 4 meters with high accuracy. It operates by emitting high-frequency ultrasonic sound waves and measuring the time it takes for the sound to bounce back from an object. This sensor is ideal for outdoor and industrial applications where moisture and water exposure are a concern.
Pinout
VCC: 5V power supply
GND: Ground
TRIG: Trigger input
ECHO: Echo output
Technical Specifications
Operating Voltage: 5V
Operating Frequency: 40kHz
Measurement Range: 2cm to 400cm
Accuracy: 1cm
Waterproof Rating: IP67
Code Examples
### Example 1: Basic Distance Measurement using Arduino
This example demonstrates how to use the Waterproof Ultrasonic Sensor with an Arduino board to measure the distance from the sensor to an object.
```c
const int trigPin = 2; // Trigger pin
const int echoPin = 3; // Echo pin
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
int duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration 0.034 / 2; // Convert time to distance
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(50);
}
```
### Example 2: Obstacle Detection using Raspberry Pi (Python)
This example demonstrates how to use the Waterproof Ultrasonic Sensor with a Raspberry Pi to detect obstacles within a certain range.
```python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
trigPin = 17
echoPin = 23
GPIO.setup(trigPin, GPIO.OUT)
GPIO.setup(echoPin, GPIO.IN)
def get_distance():
GPIO.output(trigPin, False)
time.sleep(0.01)
GPIO.output(trigPin, True)
time.sleep(0.00001)
GPIO.output(trigPin, False)
while GPIO.input(echoPin) == 0:
pulse_start = time.time()
while GPIO.input(echoPin) == 1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration 17000
return distance
try:
while True:
distance = get_distance()
if distance < 20:
print("Obstacle detected!")
else:
print("No obstacle detected.")
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
```
### Example 3: Measuring Water Level using ESP32 (MicroPython)
This example demonstrates how to use the Waterproof Ultrasonic Sensor with an ESP32 board to measure the water level in a tank.
```python
import machine
import time
trigPin = 26
echoPin = 25
machine.Pin(trigPin, machine.Pin.OUT)
machine.Pin(echoPin, machine.Pin.IN)
def get_distance():
machine.Pin(trigPin, machine.Pin.LOW)
time.sleep_us(2)
machine.Pin(trigPin, machine.Pin.HIGH)
time.sleep_us(10)
machine.Pin(trigPin, machine.Pin.LOW)
pulse_start = time.ticks_us()
while machine.Pin(echoPin, machine.Pin.LOW):
pass
pulse_end = time.ticks_us()
pulse_duration = time.ticks_diff(pulse_end, pulse_start)
distance = pulse_duration 0.034 / 2
return distance
while True:
distance = get_distance()
water_level = 100 - (distance / 400) 100
print("Water level: {:.2f}%".format(water_level))
time.sleep(1)
```
These examples demonstrate how to use the Waterproof Ultrasonic Sensor in various contexts, including distance measurement, obstacle detection, and water level measurement.