A backlit wall switch flip-flop led driver circuit

My question is of course, does this circuit make sense? My high school electronics class was a quarter century ago :wink:
(Lighting System wall switch excerpt.png)

I plan on replacing my X10 lighting control system in my house, the place is way overdue for rewiring anyway.

The idea is to replace the backlit wall switch in the bathroom (or wherever). While I’m at it, slap an “on” indicator in it (so I know if I have a blown bulb, or controller problem if it doesn’t register the button press and switch the relay on).

What I was trying to accomplish with this circuit is:

Backlight LED(s) is illuminated when (RJ45 Pin 4 in the schematic) is high (+5v), while the “On” LED is not illuminated.
Backlight LED(s) is not illuminated when (RJ45 Pin 4 in the schematic) is low (0v), while the “On” LED is illuminated.

Essentially, this could be replaced by an 7404 if it had higher current capacity. The backlight LED will probably be replaced by multiple bright led’s (and it’s current limiting resister value changed of course) which would exceed the output of an 7404.

The transistors listed are what I have on hand, nothing special.

Of note: the optoisolator is active during the “On” state. Which, to my knowledge would allow current to flow from the base of the PNP transistor, through the optoisolator to ground, this illuminating the LED on it’s collector.
The reverse occouring with the NPN, when it’s base has no current flowing into it, no curent flows from it’s collector to its emitter.

In addition:
I’ll attach the whole schematic for those who are curious, or maybe want a laugh. It’s pretty ambitious for my first arduino project, and drawn up in paintbrush. I’ve tested the code for the CD4021 button reading, debouncing, and 74HC575 outputs via breadboard. Optoisolation and beyond are just theoretical at this point, I need more breadboard!

This is a 24 channel system (24 buttons, 24 outputs), and uses no shift libraries.

Yes, 3 CD4021’s in series, and they work stably!

Some would wonder why I chose the CD4021, I have them lying around in abundance. My dad bought 50 of them back when I was in diapers. They have the old old OLD "F"airchild semiconductor logo on them! :o Talk about “new old stock”, they’re probably as old as Ridley Scotts “Alien”. They’re actually label’d “34021PC”, and yes, they were acting weird until I put the decoupling caps on each one, possibly excessive caps. Feel free to have a look and critique, or even try it out.

InputSR_Debounce_OutputSR_and_DHT.ino (8.82 KB)

I tried it out on the breadboard, of course there was a glitch in the old schematic I didn’t foresee. It works now, but it’s probably not in “good practice” in some way.

Here’s what I found and did:
First I swapped out the MPS4355 with a 2N2907.

Then I had to swap around the resistor values for the pullup and base resistors. Turns out current was flowing from the base of the 2N2907 into the base of the 2N2222, or gnd, leaving the 2N2907 saturated? either way. Seperately, they worked as expected. Combined, the “on” LED was always on.

So I made the pullup resistor the path of least resistance for the 2N2222, rather than the 2N2907 it was pulling current from.

I ended up with the circuit in the attached updated schematic, kind of flopped where the LED on the 2N2222 is connected. Both of the LEDs illuminate the same brightness as far as I can tell.

Does it really matter whether its connected in series to the collector or emitter?

Does it really matter whether its connected in series to the collector or emitter?

Sort of.
As you have it you have an emitter follower, for the NPN transistor and a common emitter circuit for the PNP transistor.

For the NPN transistor the voltage on the emitter can only ever be 0.7V lower than the voltage on the base. Note also that you do not need base resistors for this configuration so the 10K resistors on the 2N2222 can be removed. This is a sort of analogue circuit as it is not switched.

However as you want them switched with the same logic signal I suppose it is fine as it is in this schematic.

Thanks Mike! Your saying that this circuit is functioning more as an analog threshold than a logic switch right? If so, it’ll probably be an issue for me later depending on wire run length (I’m expecting 50m max length). I might end up having to slap an 7404 into my design as an input inverter/buffer in the end. I noticed inside each inverter gate, there are at least 4 transistors doing the job, and that doesn’t include the “driver” I’d need.
Transistors were never my forte, even back in the day.

FYI, I’m testing this by simply grounding the “RJ45 pin 4” locally.

What I did:
I put the LED back on the collector of the 2N2222, so they’re both common emitters. When I removed the 10K from the 2N2222 though, the 2N2907 went back to always being “on”.

I’m theorizing that the 2N2222 has a very low base-emitter resistance, alowing more current to flow through it than the 1K “pullup” is providing, then pulling from the 2N2907. With both 10K base resistors in there, the 2N2907 stays off when it “should”.

The schematic is back to the original, with the 10K/1K values inverted as they are in the 2nd one.

For fun:
Out of curiosity (and my better judgement), I removed both base resistors for a test; and that effectively (nearly) shorted the whole thing, dragging the arduino’s “on” led to nearly off after a second or two of being powered on. Heh.
Curious as to why it took that long to drag down. There must not be enough current left over for the microcontroller to operate after the transistors pass most of it through to gound.

I forgot how much I loved tinkering with these things! It’s like detective work but with ohm’s law and math, or taking a best guess and hope smoke doesn’t come out. It’s still fun either way :slight_smile:

Your saying that this circuit is functioning more as an analog threshold than a logic switch right?

Well an emitter follower is not a threshold at all, it is a continuum, the voltage on the emitter is always the voltage on the base minus 0.7V. So if that changes then so does the value on the emitter.

The thing about a common emitter on a NPN is that the voltage on the base with the transistor on is always 0.7V. The base is just like a diode to ground, so no matter what voltage you put on the base it will always be dragged down to 0.7V. That is why you have a series resistor, so there is something to drop the excess voltage across.

When you have a PNP transistor, it is just the opposite. To turn the transistor off you take the base up to the voltage on the emitter. It only turns on when the voltage drops 0.7V below the emitter. Again you need a resistor to drop any excess voltage across / limit the current.

That is why you can't connect the base of a PNP and NPN in a common emitter configuration together. They both want to be very close to their emitters.

Hopes that helps.

Hopes that helps.

It sure does, and well described! I got an "Ah!" moment with your description, and I'm saving it. You've got my wheels turning on how I can improve the efficency of this and save some mA.

Also the analog-ness of it now makes sense to me, and why it bled so much current when I connected those bases directly together. If I was dealing with a stronger power supply I would have fried them, lucky for them I wasn't.

Thanks Mike :slight_smile:

Hello cbaker391,
This looks much more complicated than it should be!
Have you considered using a pair of 74C150 1 of 16
data selector or 4067 1 of 16 analog switch? Your
MCU could poll each location for input and act
accordingly. I think using the opto-couplers is
a good idea. You could use set-reset flip-flops
to control the LEDs, so one is lit and the other
is not: that would fit well with the polling

Have you considered using a pair of 74C150 1 of 16
data selector or 4067 1 of 16 analog switch?

I didn't know of those chips. I looked into them and found the 74C150 doable, especially scaling with many inputs (like 32+). The price of those are a little high for my tastes though (ebay $10 and up per chip). I'd definately pick some up to play with if they were cheaper (I might anyway :slight_smile: , especially if I get 5).

The CD74HC4067 got my wheels turning for dimming applications since it's analog. I'm thinking 4067>A/D converter>optoisolator>arduino. Of course I'd want to isolate the 4067 (select/control) from the arduino too since it sits on the front end. It's good and cheap too ($.75-$3).

As for S-R flip-flops.... I have some of those (74279), tinkering time!

Thanks Herb!

The CD74HC4067 got my wheels turning for dimming applications since it's analog.

Remember this chip only connects the data input to one output. Other paths that are not being addressed at any time will float.