State change with switch

This is technically not an arduino problem beause I want to do it without an arduino but it is for an arduino project.

I need to change the colour of a common cathode led dual(tri) colour LED using just a monentary switch.

When the switch is not pressed then it needs to be red and when it is pressed it needs to change to green. I also need to do this without arduino processing.

I know it can be done with a PNP (or is it NPN) transistor for lighting up the LED when it's off and then just the switch for the other state...
Would that work? Is it the easiest way to do it?

Many thanks,

Mowcius

You want to use a transistor to drive the LED like you would conventionally, with your switch connecting the base through a resistor to +ve. Put the first side of the LED in that transistor.
Then from the collector of that transistor you need to connect (through a resistor) to the base of a second transistor that controls the other side of the LED. Then you always have one on and the other off.

Forgive the crude drawing, but this is for a common cathode using PNP transistors.

Ok, thanks a lot...
That's almost what I thought but I had thought that you could do it with a single transistor...
Can't you just have the first LED connected normally with the switch and have a PNP transistor base connected to the +ve line of that circuit. Then when the +ve line drops (the button is not pressed), the second LED circuit is activated...

The drawing is strangely amusing... I presume you don't have a graphics tablet...

Regards,

Mowcius

Ok, I got it working with that circuit and found that I didn't seem to have the correct value resistors to get one of the LEDs to turn off completely when the other was on. I also didn't quite understand your circuit...

I then thought a bit more about using just one transistor and connected up a circuit...

I had +9v > button > LED > resistor > -9v

I then connected the base of my transistor into the circuit after the button (with a resistor) so that it is low when the first LED circuit is off (hence turning in the second LED circuit).

I would post a picture but I because I am not on my computer with the graphics tablet, I realise how difficult it is to draw with a mouse in paint. My drawing looked worse than yours!

Thanks for the help anyway,

Mowcius

Yes it's not easy drawing with a mouse. Thinking about it you could just use a single pole changeover switch and not bother with any transistors at all. Or as you say simply remove the first transistor. Problem was I was still thinking digital output which is why I had the two.

Anyway glad you got it working. :slight_smile:

Yes, unfortunately I need to use a reed switch so I need to use a transistor...

I see what you were doing in your drawing now.

Thanks for your help as you jogged my memory as to how to do it :smiley:

Mowcius