Go Down

Topic: problem about sensor hc sr04 (Read 1 time) previous topic - next topic


problem about sensor hc sr04 use help with the sensor HC-SR04 and arduino because the arduino always detects 2 or 3 microseconds of the echo signal and convert to 0 cm, so I used various programs from various sites but the result is always the same .. could you help me please? Connect the sensor vcc to 5-volt arduino and gnd to gnd, the trigger to pin 7 and echo to pin 8. For example I get the code here :


Feb 14, 2013, 11:43 am Last Edit: Feb 14, 2013, 11:49 am by 0AlphaOmega Reason: 1
long r = 0.034 * duration / 2;

That could be simplified.
long r = 0.017 * duration;

I've not run the code but it looks about right.

What distance are you trying to measure, 2 to 3 cm is about minimum, and the supposed maximum was probably obtained in an test chamber - or I have edge of the bell curve devices ;)

many code snippets give...

digitalWrite( triggerPort, LOW );
17    delayMicroseconds( 1 );
18   //invia un impulso di 10microsec su trigger
19   digitalWrite( triggerPort, HIGH );
20   delayMicroseconds( 10 );

Just read your post again, are you suggesting that it is pre-triggering? (reading the outgoing chirp?) I would think that was unlikely, although your device may be faulty. you could add a few uS delay before the pulseIn()
I've not hooked a scope to one of these yet, but I do note that there are several models and some can be set to single pin mode - do check your device.
For whom does the clock pulse? It pulses for you!


Thanks  :). I will try and I will inform you to results!

Go Up