Pages: [1]   Go Down
Author Topic: problem about sensor hc sr04  (Read 424 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :
http://barcadero.wordpress.com/2012/02/14/sensore-a-ultrasuoni-hc-sr04-e-arduino/
Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 smiley-wink

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 );

[edit]
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.
[/edit]
« Last Edit: February 14, 2013, 05:49:16 am by 0AlphaOmega » Logged

For whom does the clock pulse? It pulses for you!

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks  smiley. I will try and I will inform you to results!
Logged

Pages: [1]   Go Up
Jump to: