Go Down

Topic: problem about sensor hc sr04 (Read 543 times) previous topic - next topic

mmauror

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/

0AlphaOmega

#1
Feb 14, 2013, 11:43 am Last Edit: Feb 14, 2013, 11:49 am by 0AlphaOmega Reason: 1
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 ;)

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]
For whom does the clock pulse? It pulses for you!

mmauror

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

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview