A off brand PING issue
__da__boss__
Posts: 9
Hey! Just a simple question for the smart ones. I gave up because I cannot get this to work correctly.
I have this _(http://www.amazon.com/SainSmart-HC-SR04-Ranging-Detector-Distance/dp/B004U8TOE6/ref=sr_1_5?ie=UTF8&qid=1391193537&sr=8-5&keywords=ping#productDetails)_
and as you see it has four prongs instead of three. I hear the ping clicking when I run this
***
' {$STAMP BS2}' {$PBASIC 2.5}
Ping_Pin CON 0
InConstant CON 890
inDistance VAR Word
time VAR Word
DO
PULSOUT Ping_Pin, 5 ' Send short pulse to Ping
PULSIN Ping_Pin, 1, time ' Wait for echo
inDistance = inConstant ** time ' Convert to inches
DEBUG CR, DEC inDistance ' Display result
PAUSE 200 ' Short delay until next read
LOOP
***
But it is not sending feedback on the prompt that comes up it is just '0's
There is one port that I dont have hooked up cause I don't know where to wire it to it's called " Echo "
This is how I have it wired
Right to left -
GND ( Ground ) to Vss
Echo ( Not sure ) to no where
Trig ( Trigger ) to P0 ( Next to X2 )
VCC ( Positive Power ) to VDD ( Next to X3 )
I have this _(http://www.amazon.com/SainSmart-HC-SR04-Ranging-Detector-Distance/dp/B004U8TOE6/ref=sr_1_5?ie=UTF8&qid=1391193537&sr=8-5&keywords=ping#productDetails)_
and as you see it has four prongs instead of three. I hear the ping clicking when I run this
***
' {$STAMP BS2}' {$PBASIC 2.5}
Ping_Pin CON 0
InConstant CON 890
inDistance VAR Word
time VAR Word
DO
PULSOUT Ping_Pin, 5 ' Send short pulse to Ping
PULSIN Ping_Pin, 1, time ' Wait for echo
inDistance = inConstant ** time ' Convert to inches
DEBUG CR, DEC inDistance ' Display result
PAUSE 200 ' Short delay until next read
LOOP
***
But it is not sending feedback on the prompt that comes up it is just '0's
There is one port that I dont have hooked up cause I don't know where to wire it to it's called " Echo "
This is how I have it wired
Right to left -
GND ( Ground ) to Vss
Echo ( Not sure ) to no where
Trig ( Trigger ) to P0 ( Next to X2 )
VCC ( Positive Power ) to VDD ( Next to X3 )
Comments
You need to hook up the ECHO pin to an INPUT pin on your Stamp. When the ECHO line goes high after a trigger, that's what your PULSIN measures. This should probably work (presuming you hook ECHO up to PIN 1, but you can use any pin).
Also, you are much better off defining pins as PIN, not CON. There are reasons to do the latter, but not in the case.
I use the same 4pin HC-SR04 sensor and it works OK with this subroutine, as in the PING example code;
Is that the burglar alarm for your Saab?
I do not want to hijack this topic, but I started this thing as an extension of a project elsewhere on this forum, where somebody built a ´Solar Flower´ out of a vegetable cooker. I would like to think it is, but since I programmed it, it´s like me, so it hardly is.
What it does in short;
- see if it´s light or dark,
:if it´s dark, close flower and show randomly blinking bi color LEDS
:if it´s light, open flower, turn to light source, listen for sound, look for IR movement
:: if there´s a sound or IR movement, turn to source, measure distance to object in front of solar flower
:: if distance is less than 30 cm, close flower, keep measuring distance and make beeping sounds while distance is less than 30 cm
loop forever
@prof braino; yes, a lot cheaper on ebay, less than $7.
Hm... that´s an idea, but who would want to steal a 40+ year old Saab Sonett?
Then the answer is 'no one'. If it's one of the earlier models, then the answer is 'everyone'.
The earlier ones can give a Jaguar E-type a run for its money in the looks department. The later ones, only if the Jaguar fell from a high-rise...
I'm a Citro
Once I get this set up, I want to have it roam freely and dodge stuff, where is a simple script to do this?
The PING(( has 3 pins, it uses 1 pin for both trigger and echo. The SRO4 has 4, it uses separate pins for trigger and echo so you need to connect those pins to separate ports on the BStamp and rewrite the PING(( code accordingly, as indicated earlier by Zoot and me. 'Simple' is a subjective term... My guess is that you'll have to do a lot of reading before you'll be able to do that.
Start with a tutorial and first build simple things, like making an LED blink.