LED, photoresistor, transistor, and 555 timer help
Toby2
Posts: 3
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:
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.
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 LOOPSo, 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
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.
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,
That was the missing link, stamptrol, I'll go run and see if I can get it work right.
Thanks!
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!
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?