What does it do?
Sonar HC-SR04 sensor issues an ultrasonic pulse to determine a distance from the board itself. Sensors placement limits the min range to 2cm, and it is possible to detect objects as far as 400cm away (4m). The output is generated to the GPIO21 using the code linked below and the command to check for the distance is issued on GPIO2.
- Working Voltage DC 5 V
- Working Current 15mA
- Working Frequency 40Hz
- Max Range 4m
- Min Range 2cm
- Measuring Angle 15 degree
- Trigger Input Signal 10uS TTL pulse
- Echo Output Signal Input TTL level signal and the range in proportion
- Dimension 45*20*15mm
4 pin connector, pins as follows:
- VCC: 5V Supply
- TRIG: Trigger Pulse Input
- ECHO: Echo Pulse Output (5v)
- GND: 0V Ground
Echo Pulse Output requires Voltage to be stepped down to 3.3V to work with Raspberry and prevent damage.
How to use it?
Apart from power (5V Vcc and GND) you will need 2 GPIO pins to use the HC-SR04 ultrasonic sensor with a Raspberry Pi. Triggering pin (TRIG) sends a signal to the module to measure the distance which is returned back via ECHO pin.
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.