Hack an HC SR04 to a 3 Pin Sensor


Introduction: Hack an HC SR04 to a 3 Pin Sensor

About: The world is a Roller coaster, Im the operator.

I hope you all have heard of that expensive-but-awesome parallax ping))) sensor. I cannot buy one of them it blasts my budget into tiny little pieces of debris floating around (30$ i mean). So what do you do? literally hack your problems into pieces. So guys with the hcsr04 if you are like me pondering over the ping))). Follow this hack and get amazed:)

Step 1: Get the Stuff

1x HC SR04 ultrasonic distance sensor

Lot of 22 awg solid core hookup wire



Programming A/B cable.

Now let us begin

Step 2: The Circuit

Connect this circuit.

Step 3: Code

//this is a code for using a 4 pin hc sr04 sensor as a 3 pin ping sensor By robobot3112

#include <NewPing.h>

#define PING_PIN 12 // Arduino pin for both trig and echo

NewPing sonar(PING_PIN, PING_PIN );

void setup() {



void loop() {

delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay

unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).

Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM); // convert time into distance

Serial.println("cm"); }

Step 4: Results

Here are the results.

Let me know any error i shall revise it.

Please vote



  • Creative Misuse Contest

    Creative Misuse Contest
  • Clocks Contest

    Clocks Contest
  • Water Contest

    Water Contest

52 Discussions

Am doing a project on obstacle detector using Hcsr04 (I need to use it outdoor so going for ultrasonic). Earlier i had DYP-ME007TX which is 3 pin sensor gives out serial output. as i have problem in converting 32 bit serial output to 8 bit, i brought this HC-SR04 , Am using it with AT89S52. I dono where am making mistake.

I gave 5v to vcc, then gnd. later high pulse to trig input and after that no response from echo. Please help me out!

Thanks in advance.

6 replies

Does the code get uploaded to your microcontroller ? if so; test the hc-sr04 with an arduino or a clone.

ps sorry for the late reply

Yes i completed the project successfully. The thing i missed early was time frame. when the trig pin receives high pulse for 10 us it emits ultrasonic test signals immediately. thus we must be ready right from the 11th microsec to recieve the signal.

I'll look into the microcontroller you are using and send you the problem. Sorry for the late reply.

hello sir i want to use two sensors .

but trigger on one hscr04

echo on other ultrasonic sensor .

can u please tell me how to do

2 replies

Im not sure what you mean, but i think youre trying to integrate two sensors into one.

So, instead of using trig on one an echo on one,

just short the two pins, and connect the wire as shown in the instructable, because integrating the 2 sensors into one is a difficult task.

Best of luck.

first i will say thank you for answering me.

what i am trying to do is transmit on one ultrasonic .receive from another ultrasonic sensor .

I've found it: http://playground.arduino.cc/Code/NewPing#Download


2 years ago

3112 Hello robot,

thank you for your work , because these cheap sensors are really difficult to operate.now it's ok

.is it possible to run three sensors at the same time?

thank you

2 replies

yes you can run upto as many sensors as pins on your arduino as long as you have powered it correctly.

thank you,

i will try to make this project but I'm beginning in arduino world, it's not simple for me.if I can I put my code here.

do I need a library for the sensor to work?

1 reply

hi! can you help please? I put the extracted the newPing file containing the header into the same folder as my file is with your code and it still can not find the header and I get an error message, when I try to compile. Any ideas what I am doing wrong? thanks in advance!

1 reply