Arduino Uno & HC-SR04

Hi everyone,

I'm not sure if I have connected the distance sensor correctly to the uno board. I've attached some pics of the setup to show you how I have connected it. Is it done correctly?

I'm interested in polling the sensor periodically to obtain it's distance reading. Is there a software sample available that will allow me to do that?

http://imageshack.us/photo/my-images/689/img8640z.jpg/ http://imageshack.us/photo/my-images/194/img8642u.jpg/ http://imageshack.us/photo/my-images/21/img8643q.jpg/

Is this right from the pics:

1) VCC - black 2) TRIG - blue 3) ECHO - green (turquoise?) 4) GND - red

If so - so far it looks ok, except your color choice for VCC and GND are backwards; typically the V+ rail is done with red (in the case of 5 volts, generally; in the case of 12 volts, yellow - but these aren't hard/fast conventions), and GND done with black (black typically -always- denotes ground, though, in DC circuits).

It is difficult to tell from your pics whether/how you have VCC and GND connected to the Arduino, but if you have the wires running to the correct pins, it should be OK in that regard. Now, your echo wire (green/turquoise) is going to Pin 0? That -won't- work (well, at least not if you expect to be able to communicate with the Arduino via USB). You'll want to move it to a different digital pin. Also, where did your TRIG (blue) wire go? I didn't see it hooked up -anywhere-?

As far as software is concerned, check out this discussion thread on a new library called "NewPing":

http://arduino.cc/forum/index.php/topic,106043.0.html

Thanks for the response.

I have hooked it up in the following manner:

1) VCC - black(hooked up to 5V on arduino) 2) TRIG - blue (Not hooked up to anything on the arduino) 3) ECHO - green (rx0 on the arduino) 4) GND - red (gnd on the arduino)

I don't have a trigger. Do I need to have a trigger in order to activate the sensor? Should I move the green wire to digital pin 5?

I don't have a trigger. Do I need to have a trigger in order to activate the sensor?

Guess.

Thanks for the sample code.

I connected echo to pin 13 and trigger to pin 12 and the sample application is working for me.

Can I connect 12 HC-SR04 sensors to one Arduino board?

I should think so, though without external hardware, say a counter to operate the triggers sequentially, you'd run short of pins, unlessyou were using a Mega.

Is there a trigger that you can suggest?

Would I need to use a power adapter if I connected 12 distance sensors and one trigger, or can the USB connection could power up everything?