Help with Photo resistor as a digital input / Darlington driver

jproehl

New Member
In a project I've been doing I've up against the limit on the number of pins on a PICAXE08M2. So I would like to use the input only pin C.3 to read the state of a photo resistor. This pin is incapable of doing ADC, so I'd need it to do a digital read.

I've looked at chapter 3, page 29 on the light dependent resistor, which implements a comparison circuit between the two resistances. If I put in a 50k resistor instead of the 10k and have a photo resistor that has 5k light resistance and 2M dark resistance, will the pin switch from High to Low as the lights are turned off and then switch back from Low to High when they come back on? If not, could I modify the resistances to achieve this? If so, how? I want to use the state change of the photo resistor to control the behavior of devices connected to the other output pins.

The second question I have is: I've read that when you use a Darlington driver the outputs do not drop to 0v when the attached PICAXE pin is dropped Low, but to some fraction of the driving voltage. I think I see this behavior as the LEDs (with 330ohm current limiting resistors) attached to 12v turn off and on, but also have a 3rd state where they dim dramatically but do not go off. How can I eliminate this dimmed state? Could adding resistance to each LED line achieve this or do I need to do something more elaborate?

I'd appreciate any help as I'm still new to all this. Thanks!
 

AllyCat

Senior Member
Hi,

Yes, in principle you can certainly arrange the digital input to be "High" when the LDR is 5k (light) and "Low" when it is 2M (dark). The LDR needs to go between the supply rail (Vdd) and c.3 and the resistor between c.3 and ground (0v). 50k could be "about right".

But it would be better if you can specify the actual LDR resistance when you want the switching to occur. Do you have a multimeter to measure that? Typically the switching will occur when the LDR resistance is about twice the value of the resistor.

There are also some more advanced "tricks" that might be used to change the light sensitivity, e.g. using the "weak Pullup" resistor (about 30k) inside the PICaxe on each pin (see the PULLUP command). Or if you're not using the Serial Out pin (c.0) that can be used as another ADC input!

Yes, Darlington transistors (drivers) do have a voltage drop when "on" but it is always about 0.6 volt (like a forward diode) not dependent on the supply voltage. So if you were using the darlingtom to "short out" a LED to switch it off, then it might still glow dimly. However, the darlington normally would switch off well enough to completely extinguish the LED. But with 330 ohms from 12 volts the current (~30mA) should be high enough to make a normal LED very bright, so a slight "leakage" current might make the LED illuminate dimly.

We really need more detail about the exact "Darlington" and LED being used, how they are wired and what brightness levels you are working at (daylight, room lighting, etc.).

Cheers, Alan.
 

hippy

Ex-Staff (retired)
Or if you're not using the Serial Out pin (c.0) that can be used as another ADC input!
That's novel. I don't recall that having been suggested before but it looks like it could work from glancing at the datasheet.
 

AllyCat

Senior Member
Hi,

Yes, but I don't want to take the thread too far off-topic. Basically, setting up the DAC to output "Level 16" will bias the pin at Vdd/2 with an input impedance of about 40k (or there are ways to partially disconnect the DAC resistor chain for higher impedances). Then use a READDAC{10} to measure the voltage on the pin. Or it can be done with a few POKE/PEEKSFRs. ;)

Cheers, Alan.
 

PhilHornby

Senior Member
Use a preset/variable resistor...

In a project I've been doing I've up against the limit on the number of pins on a PICAXE08M2. So I would like to use the input only pin C.3 to read the state of a photo resistor. This pin is incapable of doing ADC, so I'd need it to do a digital read.

I've looked at chapter 3, page 29 on the light dependent resistor, which implements a comparison circuit between the two resistances. If I put in a 50k resistor instead of the 10k and have a photo resistor that has 5k light resistance and 2M dark resistance, will the pin switch from High to Low as the lights are turned off and then switch back from Low to High when they come back on? If not, could I modify the resistances to achieve this? If so, how? I want to use the state change of the photo resistor to control the behavior of devices connected to the other output pins.
I've recently made the exact same mod to an existing project - and for the same reason.

The main issue I encountered, was in setting the exact value of the resistor required. I used a 1M preset, and 'tapped-off' it; ending up with the control about 25% of the way round (no idea from which end!). My project is an interface between a plug-in timer and a set of RF-controlled lights. The modification was to make them come on when it's "dark", but still go off at a fixed time. In other words, I only needed to detect the onset of dusk. There's virtually no hysteresis between ON and OFF, so if you're detecting both you'll have to handle that - maybe with a delay before taking action?

1.jpg
 

jproehl

New Member
Hi,

Yes, in principle you can certainly arrange the digital input to be "High" when the LDR is 5k (light) and "Low" when it is 2M (dark). The LDR needs to go between the supply rail (Vdd) and c.3 and the resistor between c.3 and ground (0v). 50k could be "about right".

But it would be better if you can specify the actual LDR resistance when you want the switching to occur. Do you have a multimeter to measure that? Typically the switching will occur when the LDR resistance is about twice the value of the resistor.

There are also some more advanced "tricks" that might be used to change the light sensitivity, e.g. using the "weak Pullup" resistor (about 30k) inside the PICaxe on each pin (see the PULLUP command). Or if you're not using the Serial Out pin (c.0) that can be used as another ADC input!

Yes, Darlington transistors (drivers) do have a voltage drop when "on" but it is always about 0.6 volt (like a forward diode) not dependent on the supply voltage. So if you were using the darlingtom to "short out" a LED to switch it off, then it might still glow dimly. However, the darlington normally would switch off well enough to completely extinguish the LED. But with 330 ohms from 12 volts the current (~30mA) should be high enough to make a normal LED very bright, so a slight "leakage" current might make the LED illuminate dimly.

We really need more detail about the exact "Darlington" and LED being used, how they are wired and what brightness levels you are working at (daylight, room lighting, etc.).

Cheers, Alan.

Hi Alan:

Thanks for the input. I'm attaching a diagram showing my circuit wiring (the notes explain the wire color conventions, but they mainly are for me later when I forget what I did) and my code for the PICAXE08M2. The Darlington I'm using is a ULN3803A. As for using C.0 as an ADC pin, you'll see from my ciruit diagram that I am already using pins C.0, C.1, C.2 and C.4 for output to the 4 cars. Since C.3 cannot be used for output, I dedicated it to the photoresistor, hoping I can get around the lack of ADC on this pin. Could I do something with C.5? According to the PICAXE manual it can't be used for ADC either.

I'm not entirely clear on your photoresistor comments. They suggest that I can set the resistance level that I want the constant LED ON state to occur. How would I do this? I'm still a novice, so I'll would need a specific set of instructions or a reference I can read about how it would be done. Since I'm using pin C.3, I figured I couldn't set it to ADC input to read the analog value of the voltage. At present, my code just checks to see if the pin is Low (i.e. dark) and if so it sets all the output pins for the LEDs to high. However, this doesn't seem to work as when I put my thumb on the photoresistor (to make it dark) the lights do NOT come on. I assumed that when the resistance of the photoresistor goes up to high values (>>50k), pin C.3 would effectively be pulled low through the 50k resistor. Is this true or am I misunderstanding how the comparative circuit works. Just for grins, I did try changing my code to have a pinC.3 being High as the criterion for switching on the lights (thinking that maybe I misunderstood how the comparator circuit worked), but this didn't turn them onView attachment Car Lighting Circuit - Darlington.pdfView attachment Random car lights - One Processor, 4 cars.basView attachment Car Lighting Circuit - Darlington.pdfView attachment Random car lights - One Processor, 4 cars.bas either.

I'm trying to operate this circuit under fluorescent lights (2-4' bulbs) that are about 5 feet from the photo resistor. The cars that I'm illuminating were bought from China and the specs said to operate them at 12v (but I did see that 9v worked as well). I could consider dropping the voltage on the LEDs to 9v to see if that would get rid of the dim state, but I'd have to add a voltage regulator because my train transformer puts out a constant 12v that I'm tapping into. I had to open one up to see that there is a 330 ohm resistor in them and they have a very small pair of white LEDs up front and a small pair of red LEDs in the rear (these must be about 1-1.5mm in diameter - real small). I didn't look at the details of how they were wired, but I can tear one open again if I need to (I have a few spares).

I do need to point out that when I'm testing this circuit, the photo-resistor I used has a narrower range of resistance (~1k under a bright LED flashlight, ~20k under room lights, and 500k when dark) than the one installed on my train layout that I listed in my original post. I haven't measured the current (mainly because I'm not too sure how to do so). When they are on they are very bright, so I could add more resistance if you think that might stop the dimming behavior. The somewhat strange thing is that sometimes they go off entirely and other times they just dim significantly. So the Darlington seems to have at least 3 states - full on, dim and full off (there might also be more than one dim level). I was expecting only two.

Thanks! Jeff
 

AllyCat

Senior Member
Hi Jeff,

Yes, you could make the "threshold" light level adjustable by using a Pot as Phil suggests (and maybe replace by a fixed resistor later when the value is identified).

If these are "signal" lights, as opposed to internal "car illumination", then probably a much higher value than 330 ohms seems appropriate. You may need to inspect the car circuit in more detail to see if there are any "unexpected" components or connections which may explain the slightly unpredictable behaviour. Also, connecting 12 v to the Darlington package may not be necessary; it only connects to (protection) "overswing diodes" (associated with inductive loads like relays and motors), which might be "leaking" a small current into the LEDs (making them illuminate dimly).

No, neither c.3 nor c.5 can be used as ADC inputs because the "hardware" doesn't exist inside the PIC(axe) chip for those pins. However, to a limited extent, they both can be used as OUTPUTS, by using the "Weak Pullup Resistors" which can feed about 100uA out of the pin from Vdd. This is "easy" for c.3 (using a PULLUP 8 command) but there are several complications with c.5 (SerIn), better not discussed here (yet).

Unfortunately 100 uA is probably not quite enough current to turn on a 3803A, because of its internal resistors (but maybe worth a try). However, you may not even need the Darlington package. For the few mA of LED current which is probably all that's needed, a simple low power transistor (e.g. BC548) may be sufficient: Emitter to ground, collector to the LED(s) via perhaps 3k3 and the base to a PICaxe pin via (say) 10k. Actually the base resistor is not needed for WPU-driven outputs, but it is for "normal" outputs, so better to be safe than sorry.

Cheers, Alan.
 

PhilHornby

Senior Member
More thoughts

@jproehl: You're going to have to experiment to find the 'correct' value of the resistor. Even when I got mine working on the test bench, it needed quite a bit of tweaking when deployed into the 'field'. My bits box didn't have much variety available in the way of presets - but 1M ended up being in the right ballpark. (I'm using Rev. Ed's LDR - I've no idea of its actual electric characteristics). BTW - your thumb is not as good a test as you would think: they're actually quite transparent!.

What's the story with the fluorescent lights?

At the very least, I would think a smoothing capacitor (100nF with the 1M pot. ?) would be a good idea. Or, without the cap. you might be able to 'detect' the fluorescents as the means of detecting 'darkness'. (I'm assuming here, that the fluorescents are only in use at night). Maybe you could use a 'COUNT' statement and detect the mains induced pulses from them?

Incidentally, in your current program, all your delays last half as long as you think, because of the SETFREQ M8 statement. What's the rationale for that?

@Allycat: I like the idea of using the Pullup on C.3 to make it an 'output'. I'll definitely steal that idea :)
 

jproehl

New Member
Hi Phil:

I'm adding in two pots to the circuit I posted - A 1k one between 12v and the 4 cars lights and a second 1M one from GND to pin C.3 for adjusting the photoresistor sensitivity. I've noticed that same behavior between breadboard and "field" - once I get something working on a bread board I wire it up and it usually doesn't work the same way. I think I'm making the same circuit, but I guess I just have to learn the difference between to two implementations.

As for the thumb, I see the photoresistors resistance go from 5k-20k without it up to 500k-1M when I use my thumb. So at least I know the photoresistor has at least that range. BTW is it the photoresistor or your thumb that is transparent?

As for the fluorescent lights, I have my train set mounted on a 4'x8' sheet of plywood mounted in a frame. The frame is hinged out from the wall on one of the long sides so I can "fold" it up against the wall to store it or drop it down to use. It has a chain to the two opposite sides from the hinges so that it looks like a draw bridge when down. At the top of the enclosure that the train set closes into when stored, there is a 4' fluorescent fixture to light the whole area when using the train set (I think my original post said there were two lights, but there is only one). In addition, there is an LED light bulb in the ceiling right above the set that adds light.

Would the 100nF smoothing cap already installed for the PICAXE suffice, or do you think I need another across the line associated with the photoresistor?

As for the SetFreq M8, I don't really have a reason for it other than to execute the IF tests and CASE code faster. But now that you mention it, it probably would be a good idea to drop this back to the default M4, since I'm now limited to time periods of 65,535ms/2 or about 32.767s. Could this higher frequency cause other problems for me with the pin reads/writes?

Thanks!
 

PhilHornby

Senior Member
Transparent thumbs ;-)

I've noticed that same behavior between breadboard and "field" - once I get something working on a bread board I wire it up and it usually doesn't work the same way.
Well the definition of "dark" is going to take some pinning down; coupled with the non-linear nature of the LDR, you can probably expect to go through a few iterations of the trigger point...

BTW is it the photoresistor or your thumb that is transparent?
My thumb - see attached photo of my thumb blocking out the light from a tiny LED torch :D

...there is a 4' fluorescent fixture to light the whole area when using the train set ...
OK - so the presence of that extra light is something you're going to have to allow for. Can you mount the LDR looking (downwards) through the board at the floor? ... so that the fluorescent doesn't influence it.

Would the 100nF smoothing cap already installed for the PICAXE suffice, or do you think I need another across the line associated with the photoresistor?
I was thinking of an extra one - from C.3 to GND to help smooth out any pulsing light from the fluorescents. I'm not actually that familiar with LDRs and just did a quick google of their response times. They may not actually be fast enough to be influenced by the fluorescents anyway - but the addition of a capacitor might help stop your circuit chattering between Day/Night.

As for the SetFreq M8, I don't really have a reason for it other than to execute the IF tests and CASE code faster.
It doesn't currently strike me as a project where speed of operation is an issue :p and altering the speed from default means that you have to remember to allow for it. One thing you can do to get more speed transparently, is to enable the M2's multi-tasking support. This bumps the frequency to 16MHz, but takes care of having to alter all your PAUSE statements. (Just change your label MAIN: to START0: to enable it)

Something else in your code I noticed: your initialisation of the RANDOM seeds using TIME probably doesn't work - because TIME starts when the power is applied and undoubtedly always = 0, when "let w0=41*time" is executed. Maybe you could use the internal chip temperature instead? Not only is the temperature random, but the READINTERNALTEMP command returns random nonsense :p
 

Attachments

Last edited:

jproehl

New Member
Alan, Phil:

I've added the two pots (see attached revised circuit to see if I did it right) and the photoresistor sub-circuit seems to be working (thanks!).
Unfortunately, I'm still having problems with the car's LEDs. When I installed this circuit in the "field" I started getting all 4 lights operating together!
I have the 1k pot cranked to ~750 ohm, so I can go a bit higher, but if I need to go further I'll have to swap out the pot. Do either of you see a reason why the cars would be doing this? The code clearly is switching the 4 pins semi-randomly and semi-independently, so they shouldn't switch in lock step.

When I tested the code in the simulator and on the bread board it worked fine. However, I only used two cars for bread board testing and never connected 4 cars (I did move the two cars around on the pins to see that there was a semi-independent behavior). Would the resistance level on the LED line cause this? Would doubling up the Darlington drivers (as described in the PICAXE manual for dealing with heavy current loads) make any difference? You'll see in the circuit drawing that I have used every other Darlington pin, so making them operate in pairs would just mean putting in 8 jumpers and would be easy. I doubt that the LEDs are overloading it, but I don't know why the field circuit behaves differently than the breadboard. The only difference that I know of is that the LEDs on the breadboard circuit are driven from a 12v wal-wart and the PICAXE is driven by a ~4.5v battery pack (3 -AA batteries), while the field circuit is driven from the constant 12v output from the train transformer (which tests at ~13v) and a 5v-2Amp wal-wart (which tests ~5.2v). Could these differences cause this change?

Thoughts?

Thanks!
Jeff
 

Attachments

PhilHornby

Senior Member
Shouldn't there be a connection from the 0V on the ULN3803A to the 0V on the Picaxe 08M2?

I can't find a datasheet for the ULN3803A - is that the right name? ... ULN2803A maybe?

Out of interest, how does all this lot hang together? Is it going to be built-in to the actual train/loco, or is it trackside?
 

AllyCat

Senior Member
Hi,

As Phil said earlier, the time variable is not a good seed for the random generator because it always starts from zero (after a reset).

I would be looking to see if the PICaxe is spontaneously resetting. That's normally tested by putting a #TERMINAL 4800 : SERTXD("STARTING") or similar at the top of the program and checking the terminal display via the programming socket (which is why I always fit a programming interface on my project boards). However, that's not ideal when the SerOut pin is being used for another purpose.

So I suggest you try a two-pronged attack - 1: Improve the filtering on the 5 volt rail and 2: include a temporary indicator of when/if a reset/restart occurs.

For 1: I'd increase the decoupling capicitor (or add another) to at least 10uF and/or put a resistor of perhaps a few hundred ohms in series with the external 5 volt feed.

For 2: Temorarily change the code so that one Car LED flashes only for a second or two when the PICaxe first starts up. If it comes on again then a reset has occurred (e.g due to inadequate supply decoupling).

Cheers, Alan.
 

jproehl

New Member
Phil, Alan:

Yes, Phil, you are correct it is a ULN2803A - I copied it down wrong ... sorry.

I also have wondered about the GND connection. I had one in on an earlier version of my circuit (with dual processors and 4 - 2n3904 transistors) that connected the two grounds for the 5v and 12v lines, but pulled it out thinking it was causing my weirdness.

The way I have this configured is all the electronics is on the underside of the train set and that side is covered by a white board which is hinged on the opposite edge from the big strap hinges holding up the train set. So, when the set is in the storage position all you see is the white board whose hinge is at the top. To work on the electronics, I have the train set in storage position, unscrew some retaining thumb screws, swing the white board up and connect some hooks on chains to it to hold it up against the ceiling. The obvious complication is that its tedious to make a series of small changes and test them, because I have to make the change, drop the white board, screw it down, take out some pins holding the train set in the stored position, drop the train set, turn it on and see what happens due to the change and then reverse all this to make the next change!

I've posted a couple of pictures so you can see it.

BTW, the 5v wal-wart line is being used by other circuits that (I had assumed) are independent of this one. Perhaps there is some interaction with those circuits? Therefore, I'll increase the 100nF capacitor on the 5v line to the 10uF that Alan suggests. Can I just swap them or should I add it to another part of the circuit?

I'll also try to modify the code so there is a recognizable sequence that occurs on start up - actually the best thing might be to flash the cars as you suggest and then disable the random selection sequence so the cars remain ON or OFF thereafter but continue to loop within the MAIN: ... GOTO Main loop. Then repeated flashes means that the code is restarting.

Any idea on why the cars are all turning on and off together? As written, the only way I can see the code doing this is for it to be bouncing between Case 7 (all OFF) and Case 8 (all ON) or between satisfying the Photosensor OFF test and then failing it but only selecting case 7 or 8 thereafter.

Thanks!
Jeff
 

Attachments

jproehl

New Member
Alan:

Somethings not right - after swapping out the 100nF capacitor for a 10uF electrolytic one and changing the code to flash 2 of the 4 cars 10 times and then loop forever with them off - the lights are on all the time .... even before I plug in the 5v line! I'm testing it off the train set (ie, with the 12v wal-wart and the 3-AA battery pack) and I followed my normal procedure of plugging in the cars, plugging in the 12v line and then plugging in the 5v line to the PICAXE. As I said, the lights come on and stay on as soon as the 12v line is connected and they stay on after the 5v line is connected. They never flash or anything. Does this suggest that the 10uF capacitor is too strong OR that maybe I messed up the wiring? The wiring looks good to me, but I'll check it carefully with my tester to see if I have any shorts or any mis-connections.

BTW - what do you suggest about the GND question that Phil asked?

I do see that I can adjust the pot on the 12v line to high enough resistance so that the lights go out. So it appears to be able to cover the range of resistances I'll need with it. But I'm at a loss as to what is going on ... help!!

Thanks, Jeff
 

hippy

Ex-Staff (retired)
It's not that clear to me what you actually have, what a complete circuit diagram would look like. Perhaps one of those would help.

It could be that there is a missing 0V, the 0V-5V and 0V-12V parts separate.
 

AllyCat

Senior Member
Hi,

Yes, an "overview" diagram of how the "modules" connect together could be very helpful. One of the most common "mistakes" with multi-supply PICaxe systems is to "forget" to link the Earths together. So yes, a missing Earth connection could explain the behaviour you've described.

It's worth noting that many/most commercial microprocessor systems do a "self test" when powered up (or perhaps "Hard Reset"). Switching on all the LEDs (perhaps in a sequence to check for shorted pins, etc.) and generally "exercising" every component.

To expand on my post above: The "programming" interface is so useful for updating the program and/or debugging (using DEBUG, or SERTXD commands, etc.) that I always try to fit an "interface" onto every board. It doesn't need to be a complete 3.5mm jack, but maybe just three pins, or even PCB pads. Also, if you don't want to use the 10k + 22k resistors, a single SerIn pulldown resistor can be 100k (maybe much more) but will accept programming signals from the normal programming adapter (connected externally).

For your general pin allocations, SerIn can be used as a digital input or output, but is best reserved for a real "emergency" fix. However, particularly as you were using 2N3904 transisitors previously, one of those (with base connected directly to c.3) may well give adequate LED drive current. If not, use it as an "emitter follower" to feed a ULN input pin, or just use two in a "Darlington" configuration (collectors linked, one emitter to the other's base).

Personally, I would always try to use an ADC input for a "light sensor" because the "dynamic range" (bright to dark) can be so large (and it saves having to mess around with a Pot.). For your application, the LDR could be connected onto the SerOut pin, read as I hinted in #4 and (except with really bright ambient light) the Serial Comms should still work fine. But easier, would be to use either c.1 or c.4 as both an output and an input. Probably just wire the LDR between a ULN input pin (or a resistor to earth) and the 5v supply rail. In use, the READADC automatically switches the pin as an input, so you just need to switch it back to an output (DIRS or High / Low command) after reading the ADC value.

Note that I didn't mention c.2 (to use as an ADC input) because it's (also) the PWM output, which might come in handy later. ;)

Cheers, Alan.
 
Last edited:

jproehl

New Member
Okay, thanks.

I'm not sure I could draw a master diagram. But what I have are several sub-systems all of which are hooked in parallel to the 0-5v wal-wart at its base. That is the 5v plug from the wal-wart plugs into a barrel jack on a simple board that has ~10 pairs of pins (0v and +5v) that each subsystem plugs into. Once I get this circuit working by itself again, what I can do very easily is to unplug all subsystems and see if this circuit works in the "field" and then plug the subsystems back in one at a time to see if any of them cause this circuit to fail. Then I would have to look at the design of that subsystem in concert with this circuit to see if the combination has a flaw.

I'll look carefully at this circuit with respect to a missing ground connection and see if I can identify any. One thing that confused me a bit is the diagram in the PICAXE manual describing how to use the Darlington driver. The only connection I see to the PICAXE is through Pins 1 and 2. I assume that the +V in that diagram is my 12v line since that goes through the lights (or in the case shown, the motors). This line also goes to the Darlington and the ground seems to be the one associated with the 12v line. They do not show the PICAXE, so that suggested to me that its power loop (0v-5v) is separate. I wasn't sure if you would have to (or even could) tie the two grounds together. Should I do that or could it cause more troubles?

Alan: I hear you on the programming interface and I will move in that direction in all future projects, but I'm somewhat committed to what I have right now for this circuit. At least until I decide to abandon what I'm doing and start over. I also think I understand how I could piggyback the LDR and one of the outputs to the Darlington to get an ADC input, but I think it would add a complication that I might not be able to debug if (when) my circuit doesn't work. But I'll think about it.

Thanks a bunch!
Jeff
 

hippy

Ex-Staff (retired)
You need the 0V of your Darlington / lamp circuit joined with the 0V of the PICAXE supply.

Code:
12V O--------------.
                   |
 5V O-----.       (O)
          |        |
       .--^--.     |
       |     |___|/ 
       |     |   |\
       `--.--'     |
          |        |
 0V O-----^--------'
 

jproehl

New Member
Phil, Alan:

I have finally solved it!! ... well you guys did most of the work.

What I finally noticed when I took a hard look at comparing the test case and the "field" installation (and I still don't know why this caused the problem) is that I had tied all the grounds for the lights in the "field" installation into one line. That is, when I brought all the wire pairs together into my terminal block I had 5 connections (the 4 positive leads from the lights and one combined negative lead). Then I brought these out into 4 wire pairs to plug into my circuit all of the negative wire leads to the lights emanated from one connection on the terminal block. This was enough (apparently) to tie all the cars together. I did this thinking that I would save 4 wire connections in my terminal block and since they were ground it would be okay. Well, when I separated them the cars started working independently.

I really want to thank you guys for putting up with my blockheadedness on this. However, I did make nearly all of the changes you two suggested and I know I have improved the robustness of the final circuit. The grounds for the 5v and 12v power lines are tied together and I have 2uF capacitors on both the 5v and 12v lines to help smooth out voltage fluctuations. I haven't looked again at the photoresistor behavior, but that was working once, so I 'm confident that if it isn't working now, I can adjust the pot. connected to that part of the circuit to get it operating (it's actually a small part of the circuit, so even if it doesn't work too well it won't be a problem). I also have several types of photoresistors with different light and dark resistances, so I can swap those around as well until I find a good combination. Another thought occurred to me with respect to the photoresistor ... do either of you think it would make more sense to use a phototransistor instead? Wouldn't that have a better high/low signal behavior?

Thanks again!
Jeff
 

hippy

Ex-Staff (retired)
That is, when I brought all the wire pairs together into my terminal block I had 5 connections (the 4 positive leads from the lights and one combined negative lead).
That would explain it if you treated the assembly as being low-side, with four positives, one common negative, when they are high-side, have one common positive and four separate negatives.
 

AllyCat

Senior Member
Hi Jeff,

... would it make more sense to use a phototransistor instead? Wouldn't that have a better high/low signal behavior?
No, probably not. The variation of transistor current gain (between different samples) is probably larger than LDR resistance, and photodiodes are normally sensitive also to Infra Red light, which can confuse "subjective" assessments (because the human eye cannot see it). But the main issue is that photodiodes have a linear current/illumination characteristic, whilst the resistance of a LDR varies more logarithmically (as does the sensitivity of the human eye).

Particularly when using a LDR with an ADC input, you should get "useful" changes in the ADC value, even if the light level changes up or down by a factor of 10 (and probably 100 with readadc10), whilst a photodiode/transistor may hit an "endstop" at only about twice the "mid point" brightness level.

Yes, I was aware that I was going rather "off topic" for your immediate aims, but several other posters had expressed an interest in the more "advanced" techniques. You probably should avoid "sharing" the SerIn and SerOut pins with another function (for now), but might be surprised how easy is the switching between Input and Output on a pin, and how time-saving can be the debugging facilities via the PE Terminal Emulator.

Cheers, Alan.
 
Top