Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

activate 4 led in series with switch

Status
Not open for further replies.

yassin.kraouch

Advanced Member level 2
Advanced Member level 2
Joined
Jul 5, 2009
Messages
631
Helped
40
Reputation
80
Reaction score
40
Trophy points
1,308
Activity points
5,094
Hi,
i have 4 LEDs in series, and a push button,i want when i push the button one times it activate 1 LEDs, and when i push the button two times it activate 4 LEDs, and when i press the push button for 3 sec it turns off the LEDs,
many thanks,
 

It's much easier if the LEDs are not in series. Your easiest solution is a small microcontroller (PIC10 series perhaps) and some transistors to bypass the unwanted LEDs. You will also need something to debounce the switch which the MCU can also do for you.

Brian.
 

It's much easier if the LEDs are not in series. Your easiest solution is a small microcontroller (PIC10 series perhaps) and some transistors to bypass the unwanted LEDs. You will also need something to debounce the switch which the MCU can also do for you.

Brian.
no problem i can put the LEDs in parallel, what do you suggest if LEDs are not in series ?
 

Still use a small MCU, connect one LED to one pin and three LEDs to another. The signal from the switch can be debounced and used to drive none, one or all four LEDs quite easily. The MCU can also do the timing to check if the button was pressed for three seconds.

Brian.
 

Great, you think that with only one push button we can dod three function :
-press the first time : 1 LEDs is ON
-press the second time : 4 LEDs are ON,
press for 3 sec : all LEDs are off ,
i found example on arduino,
https://arduino.cc/en/Tutorial/Debounce#.UzAbHfldVu4
you think that this is a good strat ?
many thanks,
 

Check this 12F509,
12f509.png
This is a popular PIC you can find many examples by goggling, i can also help you with the code if you like,
the arduino example you have there is just the debounce for the switch, its only a piece of stoftware you will need or you can also put a 10nf capacitor on the switch, or even both :).
 

Ricardo, he is looking for 4 LEDs and 1 switch. Your cicruit is amost what he needs, but remove a switch and put the fourth LED on GP4, since GP3 is an input only.

For software, you're going to want to use the counter to check for the button press, so that your program will know how long you are pressing the button. Since you have a 3 second for clearing the LEDs, it's a pretty simply compare function, simply set up a timer interupt, and if the switch is closed, start incrementing a variable. If the switch is closed, and the variable has a value higher than 0, turn on the next LED sequence, and clear the variable. If the variable hits the number associated with 3 seconds, clear the LED sequence.

Hope this helps.
 

Ricardo, he is looking for 4 LEDs and 1 switch. Your cicruit is amost what he needs, but remove a switch and put the fourth LED on GP4, since GP3 is an input only.

For software, you're going to want to use the counter to check for the button press, so that your program will know how long you are pressing the button. Since you have a 3 second for clearing the LEDs, it's a pretty simply compare function, simply set up a timer interupt, and if the switch is closed, start incrementing a variable. If the switch is closed, and the variable has a value higher than 0, turn on the next LED sequence, and clear the variable. If the variable hits the number associated with 3 seconds, clear the LED sequence.

Hope this helps.
That is exactely right tinkerer73, but about the software im not so familiar with using timer interrupts to check switchs, i would just use an interrupt switch to increment the variable, and let the output be accordingly to the variable, almost a kind of a FSM.
 

Ricardo_Electropepper, your suggestion is good and will switch to the next state properly but doesn't allow for the 3 seconds timing to take place. Tinkerer73 has the right idea, assuming the LEDs are small ones. If high curent LEDs are to be used and power drivers are necessary, it would be easier to use two outputs for the LEDs, one for the single LED and one for the remaining three.

Brian.
 

betwixt, you're correct. I am assuming low current LEDs. Otherwise, transistors to sink the current would be necessary, and yes, you can drive #s 2, 3, and 4 off one pin. I prefer connecting each separately in case the user would like to change the sequence, then it is simply a software change.

I did want to correct my statement, though, as I realized a typo:
set up a timer interupt, and if the switch is closed, start incrementing a variable. If the switch is open, and the variable is greater than 0, but less than needed for 3 seconds, turn on the next LED sequence, and clear the variable. If the variable hits the number associated with 3 seconds, clear the LED sequence.

You do not want the LED sequence changing during a 3 second hold.
 

Ricardo, he is looking for 4 LEDs and 1 switch. Your cicruit is amost what he needs, but remove a switch and put the fourth LED on GP4, since GP3 is an input only.

For software, you're going to want to use the counter to check for the button press, so that your program will know how long you are pressing the button. Since you have a 3 second for clearing the LEDs, it's a pretty simply compare function, simply set up a timer interupt, and if the switch is closed, start incrementing a variable. If the switch is closed, and the variable has a value higher than 0, turn on the next LED sequence, and clear the variable. If the variable hits the number associated with 3 seconds, clear the LED sequence.

Hope this helps.
you are correct, one push button ,and 4 LEDS :
-push the button first time --> one LED will go ON
-push button second time--> all LED will go ON
-push the buton for 3 second--> turn off all LED,
many thanks,
 

Even simpler than that:

1. if button is held down start a counter.
2. when button is released if the count is < 3 seconds and no LEDs are on, light the first one. Otherwise light them all.
3. if count is > 3 seconds turn the LEDs off.

In order to time the button press it is necessary to change the LED pattern when it is released, not when it is pressed but this inherently debounces the switch as well. You should set a minimum time of say 0.1 Seconds before the button does anything at all. The time is short enough that a normal press will be recognized but contact bounce will be ignored.

Brian.
 

Even simpler than that:

1. if button is held down start a counter.
2. when button is released if the count is < 3 seconds and no LEDs are on, light the first one. Otherwise light them all.
3. if count is > 3 seconds turn the LEDs off.

In order to time the button press it is necessary to change the LED pattern when it is released, not when it is pressed but this inherently debounces the switch as well. You should set a minimum time of say 0.1 Seconds before the button does anything at all. The time is short enough that a normal press will be recognized but contact bounce will be ignored.

Brian.

I like your solution Brian, also you should consider a hardware debounce with a 10nF capacitor like this :
dbounce1.gif
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top