Ultrasonic Sensor Module
Ultrasonic Sensor Module
DESCRIPTION:
This HC-SR04 Ultrasonic Ranging Sensor is a non-contact distance measurement
module with stable performance and high ranging accuracy. With the inexpensive
price, The measurment range if it can be upto 5M, which would be helpful for your
project such as robotic Obstacle Avoidance and so on.
Specification:
● Power supply: 5V DC.
● Effectual angle: <15°.
● Ranging distance: 2cm – 500 cm.
● Resolution: 1 cm.
● Ultrasonic Frequency: 40k Hz.
PIN CONFIGURATION:
● VCC: The VCC pin powers the sensor,typically with +5V
● Trigger: Trigger pin is an Input pin. This pin has to be kept high for 10us to initialize
measurement by sending US wave.
● Echo: Echo pin is an Output pin. This pin goes high for a period of time which will
be equal to the time taken for the US wave to return back to the sensor.
● Ground: This pin is connected to the Ground of the system.
1/3
Example:
Code:
#define TRIGGER 12
#define ECHO 11
void setup()
{
2/3
pinMode(ECHO, INPUT);
pinMode(TRIGGER, OUTPUT);
digitalWrite(TRIGGER, LOW);
[Link](9600);
}
void loop()
{
long distance, duration;
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER, LOW);
duration = pulseIn(ECHO,HIGH);
distance = duration / 2 / 7.6;
[Link](distance);
}
3/3