The Ultrasonic Distance Measurement Control Board, manufactured by diymore, is an electronic device designed to measure distances using ultrasonic waves. It integrates an HC-SR04 ultrasonic sensor with an 8-bit microcontroller unit (MCU) and a 3-bit LED display to provide immediate visual feedback. This component is commonly used in robotics, obstacle avoidance systems, parking sensors, and various automation projects where precise distance measurements are required.
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply (5V DC) |
2 | TRIG | Trigger input (TTL pulse) |
3 | ECHO | Echo output (TTL level signal) |
4 | GND | Ground |
5 | OUT | Digital output (optional, not always used) |
// Define the pins for the ultrasonic sensor
const int trigPin = 9;
const int echoPin = 10;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Define sensor pins as input/output
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// Clear the trigPin by setting it LOW
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Trigger the sensor by setting the trigPin high for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin; pulseIn returns the duration (length of the pulse)
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance
int distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
// Display the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
// Delay between measurements
delay(500);
}
Q: Can the sensor measure distances beyond 4 meters? A: No, the maximum reliable range for the HC-SR04 is 4 meters.
Q: Is it possible to use this sensor with a 3.3V system? A: The sensor is designed for 5V operation. Using it with 3.3V may result in unreliable performance or no operation at all.
Q: How can I increase the refresh rate of the sensor? A: The refresh rate can be increased by reducing the delay between measurements, but ensure that the sensor has enough time to process the signal and provide a stable reading.