Shop OBEX P1 Docs P2 Docs Learn Events
Daylight Sensor — Parallax Forums

Daylight Sensor

unoxunox Posts: 4
edited 2012-07-24 20:11 in BASIC Stamp
Hi everyone

i've this circuit & the code below.

i want light sensor that can automatically adjust the light intensity based on the ambient lighting, which will turn down the lights if a significant amount of sunlight is entering the room, and turn up the lights when there is little sunlight entering the room.

please help me with the coding if u have any. Thanks.
' {$STAMP BS2}
' {$PBASIC 2.5}

LOOP
resut VAR Word
HIGH 15
PAUSE 1
RCTIME 15, 1, result
DEBUG ? result
IF resut > 40 THEN turn ON
LOW 00
GOTO LOOP
turn ON:
HIGH 00
GOTO LOOP



BasicStamp.png
612 x 328 - 17K

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2012-07-23 04:57
    Your schematic doesn't match your program.

    However, if your CDS were connected to the pin used by the RCTIME, and the transistor were connected to pin 0 you should be able to get it to work.

    Obviously, you'll adjust the value that triggers the turn ON: to an appropriate level based on your tests. Also, the variable in the IF statement must be spelled the same as the one on the RCTIME statement and the VAR declaration. Or, vice versa.
  • RDL2004RDL2004 Posts: 2,554
    edited 2012-07-23 12:18
    You can't use GOTO LOOP, because LOOP is a reserved word (instruction) and must be preceded by DO, so that part probably needs to be put in a subroutine with an Address (label). Also, IF...THEN needs an Address (label) to jump to.

    No guarantee that this code works, but something like this:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    result VAR Word
    
    
    MySub:
    
    DO
        HIGH 15
        PAUSE 1
        RCTIME 15, 1, result
        DEBUG ? result
        IF result > 40 THEN TurnON
        LOW 00
    LOOP
    
    turnON:
    
    HIGH 00
    
    GOTO MySub
    
  • unoxunox Posts: 4
    edited 2012-07-23 20:37
    Hi

    the LED light up but photoresistor has no afffect on the circuit.

    how do i make the LED to adjust light intensity base on the ambient light level falling on the photoresistor?

    thanks.
  • aldude999aldude999 Posts: 4
    edited 2012-07-23 20:43
    I would try something like:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    Result VAR Word ' Result doesnt need to be created multiple times
    Main:
    HIGH 15
    PAUSE 1
    RCTIME 15, 1, Result
    DEBUG HOME, Result
    IF (result > 40) THEN
    GOTO TurnON
    ELSEIF (result <= 40) THEN
    LOW 0
    GOTO Main
    ENDIF
    TurnOn:
    HIGH 0
    GOTO Main

    I tested it, it works.

    Btw, other than FREQOUT and the digital variable resistor, I don't see a way to to adjust the LED intensity.
  • unoxunox Posts: 4
    edited 2012-07-24 20:11
    thanks.

    the LED does light up but the LED doesn't seem to change brightness.

    do i need to add anymore components or change the circuit?

    pls help..
Sign In or Register to comment.