Maker Pro
Maker Pro

Random LED Colour Changer

Alex Scott

Jul 3, 2014
18
Joined
Jul 3, 2014
Messages
18
Hi all

Need some advice today, I need help in building a small circuit. I have a decent understand of the main types of electrical components, I've done a fair bit of repair work in my time but I've never had to build a whole circuit. (Except for when working straight off a diagram/guide). What I need is a circuit which, when a switch or button of some sort is pressed, a green or red LED shines. I only want one colour to show at once. I can use an LED which is both green and red, in which case I'd need a way to randomly change the polarity or 2 separate LEDs and only one of them to be activated.

What I want to create is a system for when employees leave a building, they active this circuit. Green = okay to go and red = they get searched & their belongings. (Checking for internal theft, each time the circuit is activated it needs to be randomised which colour comes on)

Has anyone built something similar to this and can offer some advice? I have searched around and cannot find a ready made product nor can I find some sort of guide to build something like this. Could anyone shed some light on this for me?
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
A simple solution but not really random one would be to have a counter running with alternate pins connected to the LEDs and when the user presses the switch only one pin would be able to drive the LEDs at any one time so it's pot luck. You could trigger a timed latch which made it easier to tell if it was green or Red.
Just an idea.
Adam
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
It depends on what you mean by random. In this type of case, it's probably enough to have an oscillator running constantly, kind of like a coin that is always flipping, and when the button is pressed, the state at that time is captured and used to control the indication. If the oscillator is running at say 100 kHz, it's impossible for a person to control the outcome by trying to carefully time their button press!

I can design a circuit for you if you answer some questions.
  • What is the power source? For example, 12V DC from a wall wart? Or battery?
  • What mean ratio of red to green indications do you want? Do you want a 50:50 ratio or something else?
  • Can you describe the step-by-step process? For example, LED is OFF; operator presses the button; LED immediately lights up either red or green; LED remains lit for five seconds then turns OFF.
  • What kind of LED do you want to use? Just a standard 5 mm type?
Edit: Adam - snap!
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Could we be long lost twins :) I doubt it, your better looking than me LOL
 

Alex Scott

Jul 3, 2014
18
Joined
Jul 3, 2014
Messages
18
That seems like a good solution and not something I thought of, what components would I need? I plan to do this using a small breadboard, mounting it inside a small plastic box and attaching it to a wall. I'd need a minimum of 2 LEDs. What would I need for the counter and timed latch?

Thanks
 

Alex Scott

Jul 3, 2014
18
Joined
Jul 3, 2014
Messages
18
It depends on what you mean by random. In this type of case, it's probably enough to have an oscillator running constantly, kind of like a coin that is always flipping, and when the button is pressed, the state at that time is captured and used to control the indication. If the oscillator is running at say 100 kHz, it's impossible for a person to control the outcome by trying to carefully time their button press!

I can design a circuit for you if you answer some questions.
  • What is the power source? For example, 12V DC from a wall wart? Or battery?
  • What mean ratio of red to green indications do you want? Do you want a 50:50 ratio or something else?
  • Can you describe the step-by-step process? For example, LED is OFF; operator presses the button; LED immediately lights up either red or green; LED remains lit for five seconds then turns OFF.
  • What kind of LED do you want to use? Just a standard 5 mm type?
Edit: Adam - snap!

Thank you for your help!

  • Power can be anything - whatever is most efficient. I'm in the UK so I can run it from 240, or from a wall wart of any voltage (I'll buy whatever is best and make it work). Battery would be good, but I want to it be running around 11 hours a day.
  • 50/50 is best. I want it to be fair.
  • Process would be press some form of switch/button or anyway of activating this circuit as long as a personally has to physically do it. A red or green LED activates and can hold for a few seconds. Anywhere from 3-20 seconds would be fine, whatever is easiest/works best.
  • 5mm would be fine, possibly even 8mm. I think brightness would be more important, so no one could say they didn't see the LED so they have to press the button again.
Edit: Ideally I want to mount this circuit inside a small project box and mount that on the wall. Don't know if that helps you in any way. Would prefer to use a breadboard, but wouldn't mind soldering the wires together. Don't want to have to use a stripboard as that isn't something I've used before

Regards
 
Last edited:

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Have you thought also about a group of people leaving at once. You would probably need quite a short period.
Adam
 

Alex Scott

Jul 3, 2014
18
Joined
Jul 3, 2014
Messages
18
Have you thought also about a group of people leaving at once. You would probably need quite a short period.
Adam

Aye, I don't think that's really an issue. It's only ever for staff. At max there'd only be 2 people leaving at once.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
So I am thinking CD4017 and using the clock inhibit to freeze the count. Lets see what Kris comes up with.
Adam
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
OK, here's my suggestion. It uses two ICs from the CMOS CD4000 series: one CD4093B quad NAND gate with Schmitt trigger inputs, which is shown as four D-shaped elements on the diagram, and one CD4013B dual D flip-flop.

272552.001.GIF

The circuit can be powered from 9~12V DC from a battery (its current consumption will be fairly low with the LED OFF but I don't recommend using a PP3-type 9V miniature battery; six or eight AA or C cells would be better) or a DC power supply.

Here's a circuit description. I haven't gone into detail because I've covered some of these subjects in great detail in previous posts, and some are explained on Wikipedia and via a Google search. Places where you should search for the relevant keywords in my other posts on Electronics Point are marked with "(epoint)"; for Wikipedia, "(wikip)"; and for Google, "(google)".

The first gate in U1, U1A (on pins 1~3) forms a Schmitt trigger oscillator (epoint) with CT and RT, oscillating at some fairly high frequency - over 10 kHz, at least. This frequency clocks the first half of U2 (U2A), which is a dual D-type flip-flop.

U2A is connected as a T flip-flop (wikip, google) which toggles from one state to the other on each clock pulse. This is done by connecting the Q-bar output (pin 2) to the D input (pin 5). The set and reset inputs are not used. So U2A toggles between one state and the other constantly at high speed while the circuit is powered up.

U2A's output is fed into the D (data) input of U2B on pin 9. Every time U2B's clock input (pin 11) changes from low to high (google rising edge), U2B will sample and latch (wikip, google) the state of this signal, and present it in true and complemented forms on its outputs on pins 13 and 12.

U1D debounces SW1, the TOSS pushbutton. This is required because the mechanical contacts inside pushbuttons do not close cleanly and create contact bounce (epoint, wikip, google). When SW1 is pressed, CB is discharged through RB until it reaches pin 12's input threshold (see Schmitt trigger, epoint) when pin 11 goes high. When the pushbutton is released, pin 11 returns low.

Pin 11 is connected to the clock input of U2B so each time the button is pressed, a new state is loaded into U2B for display on the LED. Also, when the button is pressed, and while it is held down, RC and DC charge CD, creating a high level on U1 pins 6 and 9 and enabling the LED.

When the button has been released for a period of time determined by the time constant (wikip, google) of CD and RD, these pins will be considered low by U1B and U1C and the LED will turn OFF.

The LED enable gating is done by U1B and U1C. While pins 6 and 9 are low (button not pressed), the NAND gate (wikip, google) behaviour of the gates forces their outputs (pins 4 and 10) both high. When pins 6 and 9 are high (button pressed or CD still discharging from a button press), the states from the true and complement outputs of U2B appear at their outputs.

Q1~4 form a crude H-bridge driver (wikip, google) that provides up to 200 mA current to drive the LED. The circuit produces a bipolar output voltage and is suitable for driving a two-pin bi-colour LED or two normal LEDs in reverse parallel. RL limits the LED current and can be calculated using Ohm's Law (wikip) with the voltage equal to the supply voltage minus about 1.4V for the transistors, minus the forward voltage of the LED (in each direction, not added together).

For example if the power supply voltage is 12V, the LED's forward voltage is 2.5V in each direction, and you want to drive the LED at 50 mA, the calculation would be:
V = 12 - 1.4 - 2.5
= 8.1V
R = V / I
= 8.1 / 0.05 (50 mA is 0.05 amps)
= 162Ω
Use a 160Ω or 180Ω resistor.

CD1 and CD2 (100 nF capacitors) must be ceramic type and connected as closely and directly as possible between the VDD and VSS pins (14 and 7) of their respective ICs. They are decoupling capacitors (epoint, wikip) and are needed for reliable operation of those ICs. CD can be the same type (use an X7R dielectric).
 
Last edited:

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
There are human factor considerations too. Presumably there will be a "guard" or someone of appropriate authority stationed near the exit to stop and search any employee who happens, by chance, to get a "red light" instead of a "green light". That probably means you want the "red light" indication to be persistent until the search is completed and the "exit keeper" resets the "coin toss" device. I would also consider making the "odds" more in favor of the individual employee, say one in four or five gets a "red light:" instead of every other one (on average). Perhaps the "exit keeper" needs a way to force a "red light" on a suspicious employee who attempts to exit while towing a tool cart!

Of course the only "fair" way to do this is to stop and search everyone. That is essentially what the TSA does at airports with expensive scanning technology. It is pretty much standard operating procedure for some highly secure military areas, such as military bases on high alert.

I have heard that some folks actually "profile" people to determine who gets searched or more closely inspected. This reminds me of the one and only trip I made to Mexico, on business. At the customs portal we placed our bags on a table while several armed, stone-faced, Federales scrutinized everyone trying to enter while a customs officer asked questions as to what we were doing in Mexico and did we have anything to declare. A bunch of us (five or six) entered this "staging area" abreast and then waited to either be waved through or to have our belongings more closely inspected. The line moved pretty fast, but there was a big red light that came on for those unfortunate enough to require further inspection. To me, waiting to approach the "staging area," It appeared to light up at random, but I suspected that it was manually triggered whenever a Federale thought someone needed closer inspection. Anyway, I guess I looked pretty innocent because after a few questions I was allowed to officially enter Mexico without the red light coming on or anyone pawing through my shirts, socks, and underwear.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
There are human factor considerations too. Presumably there will be a "guard" or someone of appropriate authority stationed near the exit to stop and search any employee who happens, by chance, to get a "red light" instead of a "green light". That probably means you want the "red light" indication to be persistent until the search is completed and the "exit keeper" resets the "coin toss" device.
Depends on the circumstances I suppose.
I would also consider making the "odds" more in favor of the individual employee, say one in four or five gets a "red light:" instead of every other one (on average).
Yes, I would have thought so too. That circuit is pretty simple; a change to the odds would require more ICs.
Perhaps the "exit keeper" needs a way to force a "red light" on a suspicious employee who attempts to exit while towing a tool cart!
Could be done with a minor change.
I have heard that some folks actually "profile" people to determine who gets searched or more closely inspected.
Surely this is more than just a rumour? It seems obvious that they would do that, even if (for reasons of political correctness) they deny doing so.
This reminds me of the one and only trip I made to Mexico, on business. At the customs portal we placed our bags on a table while several armed, stone-faced, Federales scrutinized everyone trying to enter while a customs officer asked questions as to what we were doing in Mexico and did we have anything to declare.
Why would anyone worry about contraband getting in to Mexico? I thought they already had it all, and for a lower price! The problem is contraband getting out of Mexico, isn't it ;-)
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
... Why would anyone worry about contraband getting in to Mexico? I thought they already had it all, and for a lower price! The problem is contraband getting out of Mexico, isn't it ;-)
I think they do watch closely for cash money being brought into Mexico illegally. And with the porous border going from Mexico to the States, it is apparently not much of problem getting contraband out of Mexico. Heck, with NAFTA, they probably ship in tractor-trailer trucks now.
 

Alex Scott

Jul 3, 2014
18
Joined
Jul 3, 2014
Messages
18
OK, here's my suggestion. It uses two ICs from the CMOS CD4000 series: one CD4093B quad NAND gate with Schmitt trigger inputs, which is shown as four D-shaped elements on the diagram, and one CD4013B dual D flip-flop.

View attachment 18477

The circuit can be powered from 9~12V DC from a battery (its current consumption will be fairly low with the LED OFF but I don't recommend using a PP3-type 9V miniature battery; six or eight AA or C cells would be better) or a DC power supply.

Here's a circuit description. I haven't gone into detail because I've covered some of these subjects in great detail in previous posts, and some are explained on Wikipedia and via a Google search. Places where you should search for the relevant keywords in my other posts on Electronics Point are marked with "(epoint)"; for Wikipedia, "(wikip)"; and for Google, "(google)".

The first gate in U1, U1A (on pins 1~3) forms a schmitt trigger oscillator (epoint) with CT and RT, oscillating at some fairly high frequency - over 100 kHz, at least. This frequency clocks the first half of U2 (U2A), which is a dual D-type flip-flop.

U2A is connected as a T flip-flop (wikip, google) which toggles from one state to the other on each clock pulse. This is done by connecting the Q-bar output (pin 2) to the D input (pin 5). The set and reset inputs are not used. So U2A toggles between one state and the other constantly at high speed while the circuit is powered up.

U2A's output is fed into the D (data) input of U2B on pin 9. Every time U2B's clock input (pin 11) changes from low to high (google rising edge), U2B will sample and latch (wikip, google) the state of this signal, and present it in true and complemented forms on its outputs on pins 13 and 12.

U1D debounces SW1, the TOSS pushbutton. This is required because the mechanical contacts inside pushbuttons do not close cleanly and create contact bounce (epoint, wikip, google). When SW1 is pressed, CB is discharged through RB until it reaches pin 12's input threshold (see Schmitt trigger, epoint) when pin 11 goes high. When the pushbutton is released, pin 11 returns low.

Pin 11 is connected to the clock input of U2B so each time the button is pressed, a new state is loaded into U2B for display on the LED. Also, when the button is pressed, and while it is held down, RC and DC charge CD, creating a high level on U1 pins 6 and 9 and enabling the LED.

When the button has been released for a period of time determined by the time constant (wikip, google) of CD and RD, these pins will be considered low by U1B and U1C and the LED will turn OFF.

The LED enable gating is done by U1B and U1C. While pins 6 and 9 are low (button not pressed), the NAND gate (wikip, google) behaviour of the gates forces their outputs (pins 4 and 10) both high. When pins 6 and 9 are high (button pressed or CD still discharging from a button press), the states from the true and complement outputs of U2B appear at their outputs.

Q1~4 form a crude H-bridge driver (wikip, google) that provides up to 200 mA current to drive the LED. The circuit produces a bipolar output voltage and is suitable for driving a two-pin bi-colour LED or two normal LEDs in reverse parallel. RL limits the LED current and can be calculated using Ohm's Law (wikip) with the voltage equal to the supply voltage minus about 1.4V for the transistors, minus the forward voltage of the LED (in each direction, not added together).

For example if the power supply voltage is 12V, the LED's forward voltage is 2.5V in each direction, and you want to drive the LED at 50 mA, the calculation would be:
V = 12 - 1.4 - 2.5
= 8.1V
R = V / I
= 8.1 / 0.05 (50 mA is 0.05 amps)
= 162Ω
Use a 160Ω or 180Ω resistor.

CD1 and CD2 (100 nF capacitors) must be ceramic type and connected as closely and directly as possible between the VDD and VSS pins (14 and 7) of their respective ICs. They are decoupling capacitors (epoint, wikip) and are needed for reliable operation of those ICs. CD can be the same type (use an X7R dielectric).


Kris, thank you so much. This is exactly what I needed, you've been a great help. I should be able to source all these parts and build a prototype on a breadboard, if all goes well I'll do my best to condense it down and find a way of mounting it. I'm going to save your image and your instructions and get to work, I was simply asking to see if anyone knew a guide that was already out there and I certainly didn't expect someone to build the whole thing for me, thank you!

Thanks for everyones input, this is an excellent forum and I'll definitely come here again!
 

JWHassler

Dec 22, 2014
86
Joined
Dec 22, 2014
Messages
86
Mexico has a VAT. It seems to make more-expensive consumer goods worth smuggling.
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Yes, I would have thought so too. That circuit is pretty simple; a change to the odds would require more ICs.
Perhaps adding a decade counter with jumpers would be ideal to allow the user to adjust the odds after the device has been built. Odds could be anywhere from 1:10 to 9:10. (or dip switch)
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Perhaps adding a decade counter with jumpers would be ideal to allow the user to adjust the odds after the device has been built. Odds could be anywhere from 1:10 to 9:10. (or dip switch)

Yes hence my original suggestion of the CD4017. Kris's circuit is one way to do it, my version would possibly use less components. But hey there is more than one way to skin a banana. I won't say cat as I have two of my own :)

Adam
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Yes hence my original suggestion of the CD4017. Kris's circuit is one way to do it, my version would possibly use less components
I'd be interested to see your version!
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Ok Here's mine. With the ability to change the odds quite easily.
Cheers
Adam
Edit: +2 caps for decoupling.
Random LEDs.PNG
 
Last edited:
Top