View Full Version : Photoresistor circuit help
09-25-2008, 08:23 AM
Hi, I wanted to know if it is possible to controll an LED with a photoresistor with just 'one' pin on the basic stamp. I want to incorporate the BS2 into my n-scale model railroad to control LED signs. I want to have as many stamp pins available. So if anyone here knows if it's possible and what the circuit should look like, let me know. All I am doind is laying out photoresistors along the track and when the train passes over it, have the LED come on, with same output pin.
Thanx in advance..
09-25-2008, 08:46 AM
please explain a little better .. you want to control a LED and a Photoresistor with just one pin ? ( I mean .. both reading the value provided by the photoresistor and outputting current to the led ?? of course not at the same time )
09-25-2008, 08:52 AM
so·I would need 2 outputs then? one pin reading the photoresistor and the other pin for the LED?
09-25-2008, 09:00 AM
that's right !
you can take a look at RCTIME command for reading the value of the photoresistor .. and HIGH or LOW for the LED !
if you have too many leds and places for reading if the "train" is over .. you may need to expand your outputs.
but go little by little ..
Hope to help
09-25-2008, 09:30 AM
ok..how do i expand the outputs? I was thinking on putting the photoresistors in parallel in order to save pins...no? Lets say, I can put 3 or 5 photoresistors in parallel into one pin...that would work wouldnt it?
09-25-2008, 09:36 AM
Please explain why you need multiple photoresistors.
09-25-2008, 10:25 AM
For the many different sections of track
09-26-2008, 05:16 AM
No. that would not work !
one way of expanding your OUTPUTS is to use a Serial to Parallel converter like 74hc595, with that you can control your LEDs. the code gets a little bit loger but is no problem .. for reading the values of the photoresistors you may need a multiplexer ! I have not tryed this. but a CD4051 may work.. it has an article on nuts and volts that is about expanding outputs but I really don't remember witch is to point you.
hope to help
If all you want to do is switch on LEDs when the train casts a shadow on a photocell/phototransistor, you're wasting a stamp. Just use a simple isolated circuit with a comparator or transistor switch that turns on the LED at the right light level. See http://home.cogeco.ca/~rpaisley4/ATDetIR.html for a phototransistor solution that works in a wide variety of room light conditions. Otherwise, if your room lighting conditions are fairly constant and a photosensor/shadow system will work, you can use a simpler phcircuit, more like· http://www.aaroncake.net/circuits/lightdrk.asp with an LED and resistor in place of the relay. If you're presold on photocells, look at http://www.uoguelph.ca/~antoon/circ/actrelay.htm·.
·"If you build it, they will come."
09-26-2008, 07:45 AM
Well I rather waste the stamp on this than to let it sit in the box doing nothing. I already have built all those other circuits and they are not as simple as you think. When you're done building those isolated circuits, you've got a mess and they look terrible even when using a breadboard and all. I thought the stamp would be perfect for this since it's all in one package sorta speak, and also once can adjust the timing of the light also, not just turn them on....
OK, now you're talking! With a stamp, you can play with led timing, sequencing, flashing, etc. Perfect application.
I'm a Stamp fan, and I rarely suggest not to use a stamp. My suggestion was primarily aimed to say that if you only want a simple on/off, you can do it with individual, identical modules (easy to reproduce in quantity once you knew what worked for you) that would only require two wires each (power) that you might even multiplex and run off your track setup without any additional wires.
With a stamp, you'll probably run 3 wires (Vss or Vdd, photocell, and LED) to each station from the stamp.
·"If you build it, they will come."
09-26-2008, 08:49 AM
Yes, that's what I want the stamp to do instead of collecting dust. I want the stamp to trigger flashers, stoplights, warning tones, etc. I was kinda getting bummed out when you said I'd be wasting it. The only problem I forsee is that I will be running out of I/O pins in a hurry, and I dont know how to multiplex or even what it means. hope that clears all up!
09-26-2008, 08:56 AM
If only one photoresister will be shaded at a time you could use a 16 to 4 encoder to allow 4 stamp inputs to see 16 resistors. Or you could tie all of one side of the photoresistors to one input an use 4 outputs to energize the other side of each of the resistors in sequence by using a flash decoder.
you could use the same 4 outputs to step through the 16 leds and use a 5th output as a data bit to set the selected led on or off. The LEDs would flash on and off on a 1/16 duty cycle 1 time for each program loop. This might cause an annoying flicker, but I believe overvoltage to the led and a smoothing capacitor might solve that problem.
It seems like it might just be easier to use 1 input for each photoresistor and one output for each LED.
09-26-2008, 09:41 AM
The cool thing is that I think I can maximize the number of LEDs by using bipolar ones. They light up one color (red) with the 'LOW' command and another color (green) with the 'HIGH' command on the same I/O pin.
So I know that one I/O pin can control two LEDs, correct me if I'm wrong
09-26-2008, 10:06 AM
Sorry, M_39, not so.
A LO/0 is Ground, not a negative voltage.
You could connect a bipolar/bicolor with a resistor in series between two outputs, with one HI and the other LO and toggle them and work it that way.
Post Edit -- see "What's a Microcontroller", pp. 61-65
Post Edited (PJ Allen) : 9/26/2008 2:22:04 AM GMT