I am doing a watch with GPS tracker project. I am using an Ultrasonic HC-SR04 sensor. I don't know where to connect the Echo and trig pins with my Arduino. Please let me know how to connect it.
2 Answers
To any 2 free IO pins.
To quote sparkfuns datasheet:
(1) Using IO trigger for at least 10us high level s ignal,
(2) The Module automatically sends eight 40 kHz and detect whether there is a pulse signal back.
(3) IF the signal back, through high level , time of high output IO duration is the time from sending ultrasonic to returning.
Test distance = (high level timeĆvelocity of sound (340M/S) / 2,
In other words you send a short pulse to trigger pin and then wait for the echo pulse and measure how long it was high. Divide the number of microseconds it was high by 58 and you have the distance in centimetres ( use 148 for inches)
- 3,267
- 1
- 13
- 12
You can connect them to two GPIO pins. It does not matter much which ones (probably between 2 and 12 since these are not used by other functions like the builtin led or RX/TX).
In the following example pins 9 and 10 are used:
Fragment related to the pins:
The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.
- 13,014
- 7
- 41
- 58