Light sensor (LDR)
Hello, I have just started to run my Boe-Bot, I am novice. I would like to do a detector of light. The idea is when the LDR is by below a concrete value (shadow), the Led works. I have made the following circuit:
I know that I have to use RCTIME but I don't know how to do it.
Anybody can help me?
Thank you very much
I know that I have to use RCTIME but I don't know how to do it.
Anybody can help me?
Thank you very much
Comments
Post Edit -- dwg attached
Experiment for values of "C"
Post Edited (PJ Allen) : 11/30/2008 1:49:39 AM GMT
Jax
' {$STAMP BS2}
' {$PBASIC 2.5}
RC············· PIN···· 1
result········· VAR···· Word
Main:
· DO
··· HIGH RC···························· ' charge the cap
··· PAUSE 1···························· '·· for 1 ms
··· RCTIME RC, 1, result··············· ' measure RC discharge time
··· DEBUG HOME, DEC result············· ' display value
··· PAUSE 50
· LOOP
· END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
' {$STAMP BS2}
' {$PBASIC 2.5}
RC PIN 1
result VAR Word
Led PIN 10
Main:
HIGH RC ' charge the cap
PAUSE 1 ' for 1 ms
RCTIME RC, 1, result ' measure RC discharge time
IF (result<200) THEN Main
HIGH Led
GOTO Main
but, It has not just worked well, seems that only it obeys the first order.
What is the problem?
Thank you
The PAUSE 50 is an integral and important part of the example program. It's missing from your program.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When all else fails, try inserting a new battery.
I have just changed the pause to 50, but It does the same. The LED lights when there is little light but when I return to bring light it does not shut down.
why it happens?
Thank you very much
-Edu-
Simply put, your program is in an infinte loop. If you want to get out of the loop, you must change IF (result<200) THEN Main to branch to another target label.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When all else fails, try inserting a new battery.
' {$STAMP BS2}
' {$PBASIC 2.5}
RC PIN 1
result VAR Word
LEDon VAR Byte
Led PIN 10
'set Var.
LEDon = 0
LOW Led
Main:
LOW RC
HIGH RC ' charge the cap
PAUSE 1 ' for 1 ms
RCTIME RC, 1, result ' measure RC discharge time
IF result < 200 AND LEDon = 0 THEN GOTO Main ' return to Main only if results is less than 200
IF LEDon = 1 THEN GOTO LEDoff ' and LED is off if LED is on turn it off
LEDon = 1
HIGH Led
GOTO Main
LEDoff:
LEDon = 0
LOW Led
GOTO Main
let me know if this doe not work but I do believe it will. If you have any more questions let me know.
Jax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
' {$STAMP BS2}
' {$PBASIC 2.5}
RC PIN 1
result VAR Word
Led PIN 10
Main:
HIGH RC
PAUSE 50
RCTIME RC,1, result
IF (result<200) THEN Ledoff
IF (result>200) THEN Ledon
Ledoff:
LOW Led
GOTO Main
Ledon:
HIGH Led
GOTO Main
On the other hand I have a problem, I'm doing a tracking color object with boe bot and I have to put the led code with the other code. How can I do?
The other code is:
' {$STAMP BS2}
' {$PBASIC 2.5}
x VAR Word
y VAR Word
tilt VAR Word
main:
SERIN 0,84,[noparse][[/noparse]WAIT ("!"),DEC4 x,DEC4 y,DEC4 tilt]
PULSOUT 14, x
PULSOUT 15, y
PULSOUT 13, tilt
PAUSE 5
GOTO main
So, I need to put the two codes in basic stamp.
Anybody can help me?
Thank you
It is not possible to have the Stamp do both things at the same time although sometimes you can interleave two separate tasks if the timing works out. In this case, the SERIN prevents you from doing this because it waits indefinitely for the "!" and that cannot be controlled from your program. A timeout on the SERIN would not help because of the high Baud. There's not enough time after the "!" is received to set up to receive the numbers.
' {$STAMP BS2}
' {$PBASIC 2.5}
' set pins
RC PIN 1
LED PIN 10
'set var
result VAR Word
x VAR Word
y VAR Word
tilt VAR Word
Main:
GOSUB LightCheck ' check light conditions
GOSUB ColorCheck ' get color x,y,tilt varables
'continue code here
GOTO main
LightCheck:
HIGH RC
PAUSE 1 ' charge cap for 1ms
RCTIME RC,1, result
IF result < 200 THEN LOW LED
IF result >= 200 THEN HIGH LED
LOW RC ' discharge cap to reduce current flow from stamp
return
ColorCheck:
SERIN 0,84,[noparse][[/noparse]WAIT ("!"),DEC4 x,DEC4 y,DEC4 tilt]
PULSOUT 14, x
PULSOUT 15, y
PULSOUT 13, tilt
return
end
Jax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
GWJax your code works very well. I would like to do you a question, The led only works when I click run in Roborealm. If I want that the led works without running roborealm, What could I do?
Thank you again
Jax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
Thank you for your time
Jax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
IF resultat < 200 THEN LOW LED .............
(Now, I would like to work the speaker with this frequency)
FREQOUT 5,250,3000
FREQOUT 5,250,6000
FREQOUT 5,250,3000
FREQOUT 5,250,6000
and
IF resultat >= 200 THEN HIGH LED ............
(another frequency when the LED turn on)
FREQOUT 5,250,8000
FREQOUT 5,250,6000
FREQOUT 5,250,8000
FREQOUT 5,250,6000
One question more, Is it possible to save a short missage voice and later play in the boe bot ?
Thank you very much
If you want voice then you need the Emic-Text-To-Speach module and I can show you how to embed this into your code as well.
Jax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
This is the code in BS2:
' {$STAMP BS2}
' {$PBASIC 2.5}
' set pins
RC PIN 1
LED PIN 10
'set var
result VAR Word
x VAR Word
y VAR Word
tilt VAR Word
Main:
GOSUB LightCheck ' check light conditions
GOSUB ColorCheck ' get color x,y,tilt varables
'continue code here
GOTO main
LightCheck:
HIGH RC
PAUSE 1 ' charge cap for 1ms
RCTIME RC,1, result
IF result < 200 THEN LOW LED
IF result >= 200 THEN HIGH LED
LOW RC ' discharge cap to reduce current flow from stamp
return
ColorCheck:
SERIN 0,84,[noparse][[/noparse]WAIT ("!"),DEC4 x,DEC4 y,DEC4 tilt]
PULSOUT 14, x
PULSOUT 15, y
PULSOUT 13, tilt
return
end
...................
I have a another code in Roborealm program·too. This code is in Vbscript. You can find it in a post of www.roboreal.com
This here:
· ' initialize our start motor values to neutral
left_base = 750
right_base = 750
tilt = 700··
· ' get current image size
· width = GetVariable("IMAGE_WIDTH")
· center = width / 2
· ' get the size (width or height) of the current
· ' bounding box
· size = GetVariable("COG_BOX_SIZE")
· ' if it is equal to "" then no object was detected
· if size <> "" then
··· ' get the horizontal center of gravity found by the COG
··· ' module
··· cogX = GetVariable("COG_X")
··· ' if it is less than 75 the blob is on the left side
··· ' of the screen so move that way
··· if cogX < center-5 then
· left_base = 750
····· right_base = 750-(cogX-center)/2··
··· ' otherwise move to the right if above 85 pixels (and no
··· ' movement if 75 < cogX < 85 )
··· elseif cogX > center+5 then
left_base = 750+(center-cogX)/2
····· right_base = 750
······
··· end if
··· ' if the ball is too close then we have to move backwards
size = GetVariable("COG_BOX_SIZE")
· if· (size > 60)· then
left_motor = left_base+((60-size)*2)
right_motor = right_base-((60-size)*2)
··· else
left_motor = left_base-((size-60)*3)
···· right_motor = right_base+((size-60)*3)
·· end if
··· ' set the final motor values to be picked up by
··· ' the SSC module
end if
if (size<10) then
left_motor=750
right_motor=750
end if
SetVariable "LEFT_MOTOR", CInt(left_motor)
SetVariable "RIGHT_MOTOR", CInt(right_motor)
' now lets work on the tilt ... grab the current
··· ' tilt value
··· tilt = GetVariable("TILT")
··· ' if it was not set then default to 700 (in our case
··· ' this is horizontal to the floor)
··· if tilt = "" then
······· tilt = 700
··· end if
··· ' if the blob is below 55 then tilt down up a bit more
··· ' otherwise tilt up a little more
··· cogY = GetVariable("COG_Y")
··· if cogY < 55 then
······· tilt = tilt - (60-cogY)/5
··· elseif cogY > 65 then
······· tilt = tilt + (cogY-60)/5
··· end if
··· ' we don't want to look up more than horizontal to the
··· ' floor as we don't expect the
··· ' ball to be on the ceiling
·· if (cogY<5)or(cogY>105) then
tilt =700
end if
··· ' and set that value for the bs2
··· SetVariable "TILT", CInt(tilt)
.........................................................
I have seen the Emic-Text-To-Speach module in parallax website.·The problem is that I'm using the eb500 (bluetooth) and I can't connect in slot Boe-Bot but I supose that· I can connect to pins. (you have the image below). If I have the eb-500 with Emic-Text, Will I have problems?
If it is not possible to connect I have found a Synthesizer voice·http://www.electronickits.com/kit/complete/audi/a63.htm· I can·record a message and later playing when the pin is HIGH(1). What is your opinion?
Adding a·my school project, I think that I can put a temperature sensor, when the temperature is·up to a concrete value then the speaker says "warning the temperature is hot".
In conclusion, I would like·add·3·missatges. 1-When the led·is going to off ..........." the level of light is·good"
2-When the les is going to on ...................." the level of light is bad,·led activated"
3-When the temperature is up to a normal level·...................."warning the temperature is hot"
I had said you that I would like add voice with the movements of robot but I have thought that it is better.
I appreciate your help much
Thank you· ; )
Jax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..