Brightness controlled servo
Hi all,
I am trying to use my BASIC STAMP kit to control window blinds. Sensing light with a photo-transistor, I want to control a servo to open or close window blinds.
I've done the separate activities to move the servo and sense light. But, putting them together is kicking my butt.
Any tips or suggestions would be highly appreciated, thanks!
I am trying to use my BASIC STAMP kit to control window blinds. Sensing light with a photo-transistor, I want to control a servo to open or close window blinds.
I've done the separate activities to move the servo and sense light. But, putting them together is kicking my butt.
Any tips or suggestions would be highly appreciated, thanks!

Comments
Anyone is going to ask you for more information. Could give more detail as to exactly what is doing the butt-kicking? Possibly making your code available for review? Stuff like that.
Regards
I have my Homework Board set up now with the photo-transistors Anode connected to P2 through a 0.1uF capacitor and 220 ohm resistor. And I have the servo control line connected to P13.
I'm trying to wrap my head around connecting the output of the PT to the servo control line. Will post code when I get home.
' {$STAMP BS2} ' {$PBASIC 2.5} rcPin PIN 2 servoPin PIN 13 time VAR Word PAUSE 1000 DO HIGH rcPin PAUSE 100 RCTIME rcPin, 1, time IF time > 500 THEN PULSOUT servoPin, 1100 PAUSE 100 DO LOOP UNTIL time = 50 ELSEIF time < 50 THEN PULSOUT servoPin, 300 PAUSE 100 DO LOOP UNTIL time = 500 ELSE PAUSE 100 ENDIF LOOPA few questions. Where is your phototransistor, inside the room (behind and affected by the blinds) or just looking out of your window, unaffected by the blinds (I'm assuming this)? Did you want them to open slowly and proportionally to try to maintain a constant light level in the room, or just snap open and shut at a certain outdoor light level (I'm assuming this)? At any rate, you want to avoid oscillation and freakish performance. Google hysteresis and damping.
Let's look at your code. Your PAUSES are too long, since servos need a constant stream of pulses at ~50 hz. Looks like you're aware that DEBUG commands take too long, although they are useful in testing to determine what your range is for variable "time" (which I changed to "light" below). You just want a small, fast loop to read your photocell (use a small capacitor to minimize read time), do whatever math is necessary to calibrate the value returned to send one calibrated servo pulsout, something like below. Note that it is format checked, but untested.
' {$STAMP BS2} ' {$PBASIC 2.5} ' 2 positions of blinds, set by value "threshold" rcPin PIN 2 servoPin PIN 13 light VAR Word ' light level rctimed from photocell lower= brighter higher=darker pulse VAR Word 'servo pulsout value , either 300 or 1100 threshold CON 500 ' value to change blinds at (adjust as needed) pulse=300' initialize PAUSE 1000 DO HIGH rcPin:PAUSE 1:RCTIME rcPin, 1, light ' read ptx IF light>(threshold+100) THEN pulse=300 'adding 100 as a deadband IF light<(threshold-100) THEN pulse=1100 'subtracting 100 as a deadband ' you may need to swap the 300 and 1100 depending on your servo PULSOUT servoPin, pulse PAUSE 10 ' might need to adjust this to get ~50 hz output pulses, based on your particular RCtime hardware LOOPThat's probably because I slipped in and deleted the post after you received the notifcation copy.
I sitll haven't had enough coffee to think it through....and the most excellent Erco has responded in great detail.
[COLOR=#008000]' {$STAMP BS2}[/COLOR] [COLOR=#008000]' {$PBASIC 2.5}[/COLOR] [COLOR=#008000] rcPin PIN 2[/COLOR] ' Replaces instances of Pin 2 with rcPin [COLOR=#008000]servoPin PIN 13[/COLOR] ' Replaces instances of Pin 13 with servoPin [COLOR=#008000]time VAR Word[/COLOR] ' Sets the time variable to a max of 65,535 [COLOR=#008000]PAUSE 1000[/COLOR] ' Pause for 1 second [COLOR=#008000]DO[/COLOR] ' Starts main program [COLOR=#008000] HIGH rcPin[/COLOR] ' Sets a high at pin 2 to forward bias the [COLOR=#008000] PAUSE 100[/COLOR] ' phototranistor. The RC time is calculated [COLOR=#008000] RCTIME rcPin,[/COLOR] 1, time ' then displayed in the debug window for a [COLOR=#008000] DEBUG HOME, "time = ", DEC5 time[/COLOR] ' visual confirmation [COLOR=#008000] GOSUB Light_Close[/COLOR] ' Starts the first subroutine [COLOR=#008000] GOSUB Dark_Open[/COLOR] ' Starts the second subroutine [COLOR=#008000]LOOP[/COLOR] ' Returns to the first line of code [COLOR=#008000]Light_Close:[/COLOR] ' If the phototranistor is conducting due to [COLOR=#008000] IF time < 1000 THEN[/COLOR] ' bright light, then it commands the servo to [COLOR=#008000] PULSOUT servoPin, 1100[/COLOR] ' rotate CCW to 180 degrees [COLOR=#008000] PAUSE 100 ELSE PAUSE 100 ENDIF RETURN[/COLOR] ' Returns to the first line after the first ' subroutine [COLOR=#008000]Dark_Open:[/COLOR] ' If the phototransistor is conducting less [COLOR=#008000] IF time > 5000 THEN[/COLOR] ' due to darkness, then it commands the servo [COLOR=#008000] PULSOUT servoPin, 300[/COLOR] ' to rotate CW to 0 degrees [COLOR=#008000] PAUSE 100 ELSE PAUSE 100 ENDIF RETURN[/COLOR] ' Returns to the first line after the second ' subroutine. Infinite loopviper - I took the liberty of modifying your previous post with the "code /code" tags.
Edit the message and you'll see how they are used. It definitely helps maintain the format.