Shop OBEX P1 Docs P2 Docs Learn Events
Photoresistor circuit help — Parallax Forums

Photoresistor circuit help

Martin39Martin39 Posts: 7
edited 2008-09-26 02:06 in BASIC Stamp
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..

Comments

  • AmaralAmaral Posts: 176
    edited 2008-09-25 00:46
    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 )

    Amaral
  • Martin39Martin39 Posts: 7
    edited 2008-09-25 00:52
    so·I would need 2 outputs then? one pin reading the photoresistor and the other pin for the LED?
  • AmaralAmaral Posts: 176
    edited 2008-09-25 01:00
    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

    Amaral
  • Martin39Martin39 Posts: 7
    edited 2008-09-25 01:30
    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?
  • FranklinFranklin Posts: 4,747
    edited 2008-09-25 01:36
    Please explain why you need multiple photoresistors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Martin39Martin39 Posts: 7
    edited 2008-09-25 02:25
    For the many different sections of track
  • AmaralAmaral Posts: 176
    edited 2008-09-25 21:16
    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

    Amaral
  • ercoerco Posts: 20,256
    edited 2008-09-25 22:43
    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."
  • Martin39Martin39 Posts: 7
    edited 2008-09-25 23:45
    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....
  • ercoerco Posts: 20,256
    edited 2008-09-25 23:59
    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."
  • Martin39Martin39 Posts: 7
    edited 2008-09-26 00:49
    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!

    thanx
  • Jesse HastyJesse Hasty Posts: 29
    edited 2008-09-26 00:56
    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.
  • Martin39Martin39 Posts: 7
    edited 2008-09-26 01:41
    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
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-09-26 02:06
    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
Sign In or Register to comment.