Hcsr04
tanuagg13
Posts: 5
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.
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.
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