Recently bought a HC_SR04 sensor for my Arduino and testing it with NewPing library. Main problem was wiring because, I’m using Arduino Nano and there is no internet resources available on how to wire this.
The sensor comes with 4 pins
VCC and GND are for power purposes. Trig is the pin the instruct the sensor to send a ping. Trig invokes sending 8 cycles of 40KHz audio for a period of not less than 10 microseconds from the transmitter. Then you have Echo that is the detector for the audio.
I have connected the pins in the following way
It is a simple logic. If the distance is less than 5cm, power the LED on.
US_ROUNDTRIP_CM is available via NewPing.h file. We use
(ultrSonic / US_ROUNDTRIP_CM) operation to convert ping time to distance.
Thats all. Finally output was
— Isham Mohamed (@Isham_M_Iqbal) August 5, 2016