HC-SR04 is one of a proximity sensor. This sensor is very cheap, so many developers that use these sensors to the system they developed.
HC-SR04 can measure distances with ultrasonic wave method. This sensor has two part which is important, namely the transmitter and receiver. The transmitter will throw ultrasonic waves and will be reflected by a particular object. This reflected wave will be captured by the receiver. The delivery time can be determined from the calculation of the transmitting and catching time.
HC-SR04 has a 4 pin connector: VCC, Trig (T), echo (R), GND. VCC is connected to the voltage of 5V, GND connected to Ground, Trig (T) is connected to the data pin microcontroller, and echo (R) is connected to the data microcontroller (different pin).
– Model: HC-SR04
– Color: Blue + Silver
– Working voltage : 5V(DC)
– Static current: Less than 2mA.
– Output signal: Electric frequency signal, high level 5V, low level 0V.
– Sensor angle: Not more than 15 degrees.
– Detection distance: 2cm~450cm.
– High precision: Up to 3mm
– Mode of connection: VCC / trig(T) / echo(R) / GND
– Module Working Principle:
– Adopt IO trigger through supplying at least 10us sequence of high level signal
– The module automatically send eight 40khz square wave and automatically detect whether receive the returning pulse signal
– If there is signals returning, through outputting high level and the time of high level continuing is the time of that from the ultrasonic transmitting to receiving
For example, you can connect Trig (T) pin and echo (R) pin on the Arduino Uno as shown above. In the picture can be seen that Trig is connected to the pin number 11 and the echo is connected to the pin number 12. For source code and the programming tutorial you can read here.