Simple flip flop or not?

Hi all,
It's probably a while since a question this basic got asked and my apologies for that but I haven't dabbled in electronics for nearly 30 years and the brain just doesn't work the way it used to so..............

I'm now into model trains. Going to use a Nano to control 4 point motors by reading 4 switches (pulled either high or low, who cares) and then controlling 4 servos.
OK, nothing hard there.

I am ALSO trying (for each switch) to to change one pair of LEDs to on, another pair to off.
And yes, I could simply use 8 pins instead of 4 on the Nano. But I have a use for them already.
It's a simple logic thing, if one is ON the other HAS to be OFF. Yes, a flip flop.
And yes, I already use old BC558s to drive each pair of LEDs. And that's what is driving me nuts!!!

Because I just absolutely KNOW there is a better way with just those old BC448 or 558 that I have in my bin to combine each twin pair into an OR situation.
I just can't get my head around a stupid little circuit (using transistors) that takes care of that with just 1 on/off signal. I have looked in all kinds of places (tutorials, hobby kit circuits etc) and just can't quite get what I want. . And yes, I know a quad logic gate would do the trick but a) I'm having trouble even sourcing one that requires only one input per out and b) where I live it is all mail order stuff.

So can someone stoop down to my level, please??

Aussiewill

You want to use

  • a single output
  • to drive two leds?
  • of which on must be on
  • while the other is off?
  • and vice versa

Correct?

If so, you don't even need external parts :wink: Simply connect one led between that pin and GND (cathode to GND). Connect the other led between that same pin and Vcc (cathode to the pin). Done!

Trick is, a pin can source current but it can also sink current :smiley:

aussiewill:
It's a simple logic thing, if one is ON the other HAS to be OFF. Yes, a flip flop.

That's not a flipflop :wink: It's an inverter.

septillion:
If so, you don't even need external parts :wink: Simply connect one led between that pin and GND (cathode to GND). Connect the other led between that same pin and Vcc (cathode to the pin). Done!

Trick is, a pin can source current but it can also sink current :smiley:

Just don't forget the current limiting resistor :wink:

Yeah, always use a resistor. So basic I forgot to mention.

.....
If so, you don't even need external parts :wink: Simply connect one led between that pin and GND (cathode to GND). Connect the other led between that same pin and Vcc (cathode to the pin). Done!

Trick is, a pin can source current but it can also sink current :smiley:

The OP said he was driving the LEDs using BC558 transistors.
Does that not mean the LEDs require a higher voltage or current than can be fed direct from the pins?

I found this page which has a nice automated diagram of a BC558 being used as a switch;

Do you not take the Arduino output and feed it to one BC558 and also through an invertor to a second BC558 ?
Would that not end up with the LEDs attached to one BC558 being on when those on the other were off?

I am just new to electronics so sorry if I am confusing things.

ardly:
Does that not mean the LEDs require a higher voltage or current than can be fed direct from the pins?

Although it's possible to drive a higher voltage with a transistor, it does not automatically mean that. From the post I got the impression he simply used it as an inverter.

And throw the site away. This:

does indeed work. But the comment in it is worthless and misleading. If you would connect the base resistor to 0V the bulb would just turn on. You need 12V connected at the base resistor to turn it off. OR, as they do, not create a path at all aka letting it float.

ardly:
Do you not take the Arduino output and feed it to one BC558 and also through an inverter to a second BC558 ?
Would that not end up with the LEDs attached to one BC558 being on when those on the other were off?

Oops!

A BC558 is a PNP transistor - the wrong sort for this application as per septillion's comment.

What are needed are NPN transistors - whatever general purpose ones are rated at least 25 V and a few hundred mA.

Note that each transistor must have a series base resistor, and each LED must have a series current controlling resistor. For a 12 V supply, you can have at least two LEDs in series, 3 is fine for any colour.

It's not a "flip-flop" and it's not an "OR". It is unclear whether the OP wants to control the LEDs by Arduino or just by a switch. To drive some LEDs from an Arduino output, you have a 2k2 resistor feeding the base of the resistor from the Arduino output. the emitter is always connected to ground. The collector goes to the resistor, LEDs and thence the 12 V supply.

Now, the alternate set of LEDs are connected with the same components, but the base resistor to this transistor comes from the collector of the first transistor. The first transistor is the inverter.

Actually, this circuit is more correct:

Ignore the ammeters (comes from a simulation).

Are you using (SPDT) switches or momentary push buttons? If switches are used you can connect the LEDs to the switch output. OTOH if it is only a push button it is more interesting problem...

The OP said he was driving the LEDs using BC558 transistors.

No he didn't the OP said:-

I just absolutely KNOW there is a better way with just those old BC448 or 558 that I have in my bin to combine each twin pair into an OR situation.

Where as in fact he was wrong, you do not need a transistor just a single resistor and two LEDs as septillion pointed out in reply#1.

Knickers and twist comes to mind here.

The OP did in fact say

And yes, I already use old BC558s to drive each pair of LEDs.

It is not clear why he is doing that because, as pointed out, @septillion gave a neat solution in reply#1.

Fair comment I missed that bit, sorry.

Just theorising as this is bugging me since I mentioned resistor. One should actually use two resistors in septillion's setup, one for each led.

Reasoning is that the pin is in tristate while boot loader us active and both leds will be in series at that time.

sterretje:
Just theorising as this is bugging me since I mentioned resistor. One should actually use two resistors in septillion's setup, one for each led.

Reasoning is that the pin is in tristate while boot loader us active and both leds will be in series at that time.

Depends on the supply voltage and Vf of LEDs. Common red LEDs have Vf around 2V and will burn with 5V supply. But nothing bad will happen with 3V supply. Also 2 white LEDs (or white+blue) are safe even at 5V.

It is likely the LEDs have different color - in that case two resistors will be needed anyway to get similar brightness.

Indeed, Smajdalf is right. As a bonus, if the combined Vf of the LEDs < Vcc, you can use the tri-state to turn off both leds :smiley:

Hi again,
Sorry to have created such excitement. Mostly due to my incomplete explanation.
And thanks to all those involved.

I want to use ONE single pin on the Arduino to switch one PAIR of LEDs on while simultaneously switchen ANOTHER pair OFF. They are 25mA red and green LEDs, off the shelf.

Septillion has come up with VERY useful suggestions, but Paul__B,s little circuit is ALMOST exactly what I have been playing with in my mind.
Quick question:why the 100Volt 14Amp Mosfet at M13???

And back to my dilemma: what if I used exactly that schematic but with 2 x BC558.
Then, in the line from collector of Q15 to the base of M13 put a resistor of LOWER value than R42!

Am I correct in thinking that when the arduino pin goes HIGH, transistor 1 will suck number 2 low, and when the arduino goes LOW number 1 base goes back high and number 2 will promptly trigger again.

I just keep coming up with that and thinking it SHOULD work but that it seems too simple!!!!.
And when I try to breadboard it, I don't seem to get correct value resistors, it seems to stick one way or the other. Admittedly my value range is very basic.

And just in case you think it will work too, does someone have the nouse to work out the values.
Yes, I know Ohm's law, it's basic, but these days whenever it is milliamps and low voltage I tend to disbelieve the figures I come up with. Going STUPID with age.(76)

To recap, Arduino output pin voltage (5Volt??) supplies the trigger.

LED supply is 12Volt.

Only BC558 and BC448 available, plus a range of 1/4 watt resistors.

One PAIR of LEDs has to go on, another PAIR has to go off.

Aussiewill

OOOOOoooops!

STILL stuffed up.
Transistor number 2 feed should come from BEFORE LED1, NOT after as in schematic.
Otherwise LED 1 will still be powered, however low the current.

Aussiewill

If you have enough voltage you can use the transistors in "Darlington single" configuration:

Crappy crappy crappy forum! Wrote a nice reply, press post and I'm simply singed out :confused:

Alright, let's try it again. First, all the magic with transistors is nice and all but note you don't need any for this application. Theory is great to learn a thing or two but if I would need 2 transistors and 2 resistors or nothing I would know what I would use. :smiley:

The schematic of Paul__B will not quite work with a BJT as second transistor. That's because a BJT need current where as a MOSFET just needs a voltage.

@Smajdalf, that schematic is a bit "weird". Normally you would use a NPN for low side switching and a PNP for high side. This way you always have a VCE of 0,6V - 0,7V. But, you can probably get away with not using base resistors. :smiley:

If you want to drive both leds high side (for example if you have a bicolor common cathode led) I would jut use a single PNP. First anode goes directly to the pin. Anode of second led connects to the collector. Emitter to Vcc, cathodes to GND and the base goes to the Arduino pin as well. Of course with resistors for the leds and base.

BTW, 25mA is A LOT for a led. Most leds have 20mA max. And modern leds will work just fine with <5mA as indicator. For 3V leds I tend to use a 1k which is plenty in most cases to be visible as an indicator.

septillion:
Crappy crappy crappy forum! Wrote a nice reply, press post and I'm simply singed out :confused:

The forum software saves drafts; you can find them under your profile. Has saved me once when I remembered that.

sterretje:
The forum software saves drafts; you can find them under your profile. Has saved me once when I remembered that.

It often does not save a draft when this happens. Sometimes pressing back button in browser helps. I always save post to a clipboard by ctrl+a and ctrl+c when on a computer before I press Post button.