LDR Programming Help!
jmathews8
Posts: 2
I've been working on a project that has been going well until I got the programming portion of it. I'm making a set of blinds that open when light strikes the LDR and then closes when a decreased amount hits it. The only problem is that I don't know how to get started with that. The programming knowledge of our class doesn't encompass this much stuff. How do I get the LDR to tell the Servo motor to begin turning the blinds open?
Comments
This is two separate problems:
1) reading the sensor.
2) controlling the actuator.
We need to know something about the LDR (such as a link to its datasheet). Then you can start to ask about getting reading from it.
Then we need to know a little something about the servo, such as is it a stock hobby servo, and which one.
Once you determine how to accomplish steps 1 & 2, then step three, writing code to that brings these together as your application, is a piece of cake.
John Abshier
' {$STAMP BS2sx}
' {$PBASIC 2.5}
LdrValue VAR Byte
PIN6 PIN 6 'ldrsensor
pin12 PIN 12 'servo
pin15 PIN 15 'led
Baud CON 396 '9600 Baud
counter VAR Word
OUTPUT pin12
LOW PIN12
'the lightness has levels from 0 TO 255 AND I choose 150 AND beyond TO turn LED ON
LdrValue = 0
DO
here: SERIN pin6, Baud, [LdrValue]
'DEBUG CLS, DEC LdrValue, CR
IF LdrValue >= 250 THEN
FOR counter =1 TO 100
PULSOUT pin12, 2125
PAUSE 20
NEXT
FOR counter = 1 TO 100
PULSOUT pin12, 1875
HIGH 15
PAUSE 20
NEXT
ENDIF
IF LdrValue <= 250 THEN
FOR counter =1 TO 100
PULSOUT pin12, 1625
LOW 15
PAUSE 20
NEXT
FOR counter =1 TO 100
PULSOUT pin12, 1875
NEXT
ENDIF
LOOP
Any assistance would be greatly appreciated.
You might also use the [ code ] and [ /code ] tags along with indenting to show the structure of your program, namely which statements are under control of which IF / THEN and FOR / NEXT statements. Comments also can help describe a program's functioning to another person and often help you in your own understanding of the program and its errors.