QuickStart with cheap eBay ultrasonic sensor
birdmun
Posts: 5
I purchased a number of HC-SR04 sensors off of eBay. I attempted to use the Vin(pin 40) and Gnd to power the sensor. I was getting 4.85+ volts at pin40. I attempted to use an object meant for the 4 pin ultrasonic sensors( http://forums.parallax.com/showthread.php?135899-Four-Buck-Ultrasonic-Sensor&p=1062380&viewfull=1#post1062380 ), but, I could not get a response. I wrote my own object and added a number of debug statements to tell me where in the program the function was. I could get as far as listening.
Thinking my issue was voltage, I managed to gain the use of a wall wart that could supply 5v. When I hooked it up a number of the LEDs on the QS board lit up in varying brightnesses. I am at a loss. I will gladly provide more information, when I know what it is anyone assisting me would like.
Thinking my issue was voltage, I managed to gain the use of a wall wart that could supply 5v. When I hooked it up a number of the LEDs on the QS board lit up in varying brightnesses. I am at a loss. I will gladly provide more information, when I know what it is anyone assisting me would like.
Comments
Otherwise, you could damage your Propeller.
I bet this is a power supply issue.
The quickest way to fix this type of power supply issure is to use a battery pack with the QS. Looking back at the post you linked to, I think I remember using four AA NiMH batteries to power the QS and sensor.
I find devices usually work better when powered by a battery pack than using power from the QS's USB power. I can get away with using small servos connected to the QS's Vin if I add a couple of capacitors to Vin when using USB for power. I have a 1000uF cap and sometimes a second smaller cap on my QS boards when powering additional items from USB power.
I believe I purchased ten of those sensors myself. Two of the ten didn't work so there's a chance you have a bad unit. (I see you have several units yourself, so that's probably not the problem here.)
I see I'm the one who used a 1K resistor. I generally use 10K resistors with 5V inputs. I'm not sure if I tried any resistors between 1K and 10K or not. As I mentioned in the thread, the Prop couldn't read from the sensor with a 10K resistor on the line. One really shouldn't use less than about 3K (I think the exact value is around 2.7K) when using 5V with a Prop. But lots of the old Prop threads mention a 1K resistor so I think 1K will work in a pinch but you shouldn't design a product with less the 2.7K ohm on any 5V line.
I don't suppose you have access to a oscilloscope of a logic analyzer? It's always helpful to see if the lines are doing what you think they're doing. Have you tried more than one of your sensors with the code?
Regarding your QS leds... Are you sure it's not from your hands touching the I/O pins on the 40-pin headers?
If the lights are flashing without any metal being touched, then I think something is very, very wrong...
Looking back at my code, I see I was using a serial 7-segment display for output. It sounds like you've already modified the code to use a terminal window. I'll do likewise and make sure it behaves the same with a terminlal as the display.
I'll also see if I can power a unit from the QS's Vin line.
Edit: I see the 1K resistor is just on the trigger line. The echo uses a 10K resistor. (At least that's what the comments in the demo object says.)
I modified the code to use PST as the serial driver.
This is the output I get from the terminal window.
I cleaned up the object a bit and updated the schematic.
Since the trigger pin is an output it should be fine with just a 1K ohm resistor. The echo pin in the input pin and it works fine with a 10K resistor.
I powered my SR04 from the QuickStart's Vin and Gnd pins without adding any extra capacitors. The QuickStart was powered by the USB connection.
If the unit you have doesn't work with this code and setup, I'd suggest trying one of your other sensors in case your first one doesn't work.
I'm almost positive they can be used with a BS2. I think the code for the Ping sensor could be modified to use two pins instead of one.
If you get one of these sensors and need help just let us know. If no one else has code to use these with a BS2, I'll write some. Based on the number of people who have purchased these, I'd be very surprised if there isn't already code available.
Hi, I was kindly given a copy of the What's a Microcontroller kit with the BS2 Homework board at the NY Maker Faire by a Parallax employee. Awesome! My son and I have worked our way through most of the book, and can do some stuff with it despite our complete lack of programming or electronics experience. However, we bought one of these HC-SR04 sensors to play with, and it has defeated my rudimentary programming skills on the BS2. I have looked at Arduino code and PING sensor code, but can't figure out exactly how to translate it.
In short, I would LOVE to take you up on that offer to write BS2 code.
I've simply set pin 10 to TRIG, pin 11 to ECHO, and hit 10 with a PULSOUT 10, 5 (because it's in increments of 2uS, right?) then PULSIN 11, echo (with echo as a variable measuring the time). I get... numbers, but they seem to be unrelated to distance...
I think erco has some code to use these sensors with the BS2. I just asked him about it in another thread.
If erco (or anyone else) doesn't have some BS2 code, I'll try changing some BS2 Ping code to work with these sensors.
In the meantime, how about posting the code you wrote? (Tell us what the output was also.)
See Phil's tutorial about posting code to the forum.
Here is the skeleton of what worked:
Here is what I had been trying, unsuccessfully:
Not really sure what the issue was, but now that I'm getting the echo readings and they seem accurate, I can build around it.
Thanks!
The comments may be off a bit off but the code seems to work well.
' {$STAMP BS2}
' {$PBASIC 2.5}
#SELECT $STAMP
#CASE BS2, BS2E
' Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
#ENDSELECT
time VAR Word
RawToIn CON 889 ' 1 / 73.746 (with **)
RawToCm CON 2257
rawDist VAR Word ' raw measurement
inches VAR Word
IsHigh CON 1 ' for PULSOUT
IsLow CON 0
DO
PULSOUT 10, 5
PULSIN 11, 1, rawDist
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
inches = rawDist ** RawToIn
DEBUG HOME, "inches = ", DEC3 inches
PAUSE 100
LOOP
The only thing that happens, is that the RX blinks on the Debug Terminal,
and on the bottom half which is blue, it reads: inches = 0000
On the Boe-Bot, the Red Led is flashing Pink.
My goal is to get a read out on the Parallax LCD, in inches I would guess..
I would appreciate it immensely if someone could help.
How do you have it connected. A picture would be a great help.
And which sensor are you using? ( be specific, and if you have a link, that would help).