Shop OBEX P1 Docs P2 Docs Learn Events
Hcsr04 — Parallax Forums

Hcsr04

tanuagg13tanuagg13 Posts: 5
edited 2014-08-07 14:30 in BASIC Stamp
Hi,

I'm having trouble getting my HC-SR04 ultrasonic sensor to work properly. It works perfectly for distances larger than 4-5 cm, but I need it to work right up to its tolerance level of 0.2 cm.

This is a 4-pin module, and I have directly wired Vcc and Gnd pins to Vdd and Vss. Trigger and echo are directly wired to pins 0 and 1.

Here is my code.
' {$STAMP BS2}
' {$PBASIC 2.5}




time VAR Word
distance VAR Word


OUTPUT 0
INPUT 1


DO


 PULSOUT 0, 5
 PULSIN 1, 1, time
 distance = time ** 22510
 DEBUG CR, "Distance = ", DEC distance/10,".",DEC2 distance," cm"


LOOP

Basically, what's happening is that if I go below 2-3 cm in distance to the sensor, the sensor readings go to 4,5,6 cm and then eventually drop directly to 0.00 cm.

Comments

  • Hal AlbachHal Albach Posts: 747
    edited 2014-07-29 09:14
    All the HC_SR04 data sheets I looked up state a minimum distance of 2 cm and a resolution of .3 cm. Perhaps you can provide a link to the datasheet for a unit that has a minimum distance of 0.2 cm.
  • goleagtgoleagt Posts: 1
    edited 2014-08-07 10:54
    Hello I am super new, is there a wiring diagram of how to connect HC-SR04 to the boe bot? Any help would be great
  • Hal AlbachHal Albach Posts: 747
    edited 2014-08-07 14:30
    If you look at the first post above you will see that he has the trigger connected to Pin 0 and Echo to Pin 1. Also connect ground and +5 to the device. Use the program in Post 1 to start.
Sign In or Register to comment.