Shop OBEX P1 Docs P2 Docs Learn Events
LED, photoresistor, transistor, and 555 timer help — Parallax Forums

LED, photoresistor, transistor, and 555 timer help

Toby2Toby2 Posts: 3
edited 2011-01-11 00:55 in BASIC Stamp
Hello.

I am trying to write a program that will cause a transistor to switch an LED on and off depending on the light level sensed by a photoresistor while using the 555 timer circuit to "measure" the light level. The LED should come on when the light level is low and go off when the light level is high, repeating this on/off activity indefinitely. I need to be able to reduce the response time of the "light resistor" by playing with parameters in the COUNT command. The system should immediately turn the LED on when the photoresistor is covered and the LED should immediately go off when the photoresistor is uncovered.

So I'm pretty much a novice at this. I tried just going about the straight-forward way:
' {$STAMP BS2}
' {$PBASIC 2.5}

cycles VAR word

DO 
       COUNT 10, 1000, cycles
       DEBUG DEC cycles, " "

IF (IN10 = 0) THEN
       HIGH 3
ELSE
       LOW 3
ENDIF

LOOP
So, from that you can see that the LED is on 3 (really, the resistor leads to the transistor which leads to the LED) and the photoresistor is on 10 as well as the 555 timer circuit.

However, this code does not do what I ask of it. The LED blinks sporadically with no pattern and is not dependent on the photoresistor.

Does anyone know what's up with this?

Thanks.

Comments

  • ercoerco Posts: 20,256
    edited 2011-01-10 10:04
    Why are you using a 555 timer? Please describe your goals with more detail.

    Sounds like you just need to read a photoresistor with RCtime and switch on an LED. You could also set up your photoresistor in a voltage divider to hit 1.3V at your desired light level and switch a Stamp input pin directly.

    Almost a waste of a Stamp; you could do the same thing with a cheap 339 comparator.
  • stamptrolstamptrol Posts: 1,731
    edited 2011-01-10 10:29
    I assume the photoresistor changes the oscillating frequency of the 555 and the Stamp should measure that frquency with COUNT.

    What frequency range are you getting from the 555 as the photoresistor changes? Is it even in the range the COUNT function can work with?

    Right now you are just randomly turning PIN 3 on and off regardless of what "cycles" is. In essence, change the line " IF (IN10 = 0) ....." to something like "IF cycles > 1200 then ....."

    Cheers,
  • Toby2Toby2 Posts: 3
    edited 2011-01-10 10:34
    In response to erco, this is the very beginning of a project involving salt water "fish tanks" where the BoE will control salinity. The 555 timer is used in order to have, as stamptrol understood, a picture of what the frequency is when the photoresistor is covered/uncovered.

    That was the missing link, stamptrol, I'll go run and see if I can get it work right.

    Thanks!
  • Toby2Toby2 Posts: 3
    edited 2011-01-10 10:40
    That was it!

    I needed the LED to turn on if I place my finger on the photoresistor, so I just played with it and determined with my finger over it, the frequency was always less than 500, so I typed the code as IF (cycles < 500) THEN.. and it works perfectly!

    Thanks so much!
  • MoskogMoskog Posts: 554
    edited 2011-01-10 23:28
    Hi Toby2
    I'm very curious.. are you going to use the BS2/555 setup to measure the salinity in the tank or is it just for sensing light level in the same project?
  • bsnutbsnut Posts: 521
    edited 2011-01-11 00:55
    You can measure salt in a fish tank wire probes then use the RCTIME instruction to do calculation.
Sign In or Register to comment.