Quick jumps: Debounced circuit – with fixed start state – a 555 version – a discrete version – latching a relay

Flip Flop Fans

A common question on modding forums is "How do I switch my fans on and off with a single push-button switch?" and the usual answer is "Use a flip flop!". That's a logic IC such as the CMOS 4013B where the output changes state every time it gets a positive pulse on the input (from a square-wave clock signal or by you pushing the button), so the first push can be used to turn something on, a second push will turn it off.

Basic flipflop circuit

The basic circuit is very simple, but has a major drawback. All mechanical switches suffer from "bounce", where, on switching, the contacts make and break several times before settling down to being on or off. And logic chips are so fast they can react to every bounce. An even number of bounces and the output will end up changed, but if an odd number occur it ends up the same as it was. And by Sod's Law, you get odd bounces every time you're showing your mates your new switch.

A "switch debounce" addition is needed, and many cures involve adding another logic chip to ensure a single clean pulse gets through.


Debounced circuit

However, I came across this circuit on Terry Pinnell's site, based on an idea by Spehro Pefhany in a sci.electronics.design thread. With a few cheap passive components added to the basic circuit, much more reliable results can be expected – I've certainly had no problems with mine.

4013 pin-out

What follows is a guide to building the switch on stripboard. The chip contains two separate D-type flip flops and the layout, being by a Yorkshireman, uses both halves.

The 4013 pin connections are shown left (note the power supply pins 7 (0V) and 14 (+V) are not shown on the schematics but must be connected).



flip flop switch stripboard layout

Construction Guide – Component side view

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1 Fan1+   R1                               j5 R5   Fan2+
2         (br) Q1(g)   R4 (br)         (br) R8   Q2(g) (br)        
3 Fan1–         Q1(d) (br)                 (br) Q2(d)         Fan2–
4           Q1(s)     j3         C3     Q2(s)         0V
5             (br) R4   U1#1 (br)   U1#14 C3         j5     12V
6             R3     U1#2 (br)   U1#13   R8 (br)            
7 Sw1a       R2         U1#3 (br)   U1#12     R7            
8 Sw1b   R1 C1 (br)     j2   U1#4 (br)   U1#11         R6       Sw2a
9           C2 R3     U1#5 (br)   U1#10 j4       (br) C4 R5   Sw2b
10       C1     j1     U1#6 (br)   U1#9     R7 C5          
11         R2 C2 j1 j2 j3 U1#7     U1#8 j4     C5 R6 C4      
12                                            


The board is 12 strips x 22 holes long, with breaks as shown on the construction chart below. Note there's no break between the bottom IC legs, pins 7 & 8 are connected.

I added several extra breaks around the sensitive MOSFET gate pins, can't do any harm. Start by making the track cuts, then fit components in order of height, the jumpers, the flat-mounting resistors, IC socket if used, the capacitors, upright resistors over the shorter mounting hole pitches, finishing up with the IC, transistors and various leads.


Parts List
U1 4013B dual D-type Flip Flop,
14-pin DIL socket (optional)
Q1, Q2 IRF530 n-channel mosfet
(see below)
R1, R5 1M 0.25W
R2, R4, R6, R8 1k 0.25W
R3, R7 100k 0.25W
C1-C5 100n ceramic disc or mylar film
Sw1, Sw2 Normally-open push-button switches to suit.
2N2222A pin-out

If you really only want a single switch, fit all the components to the right of the IC and all the jumpers, and jumper the other unused IC inputs (pins 3 & 5) to a grounded row.

The IRF530 has a low on-resistance (0.11 ohms), will carry 14A if heat-sinked, and at around 50p doesn't leave much room for alternatives, though on a 12v supply any low RDS(on) N-channel MOSFET should work. These are static-sensitive devices, so take care handling.

The prototype shown below uses a common bipolar NPN transistor in one channel, the 2N2222A. This will carry over 600mA, more than adequate for most case fans. The pin-out is wrong for a straight swap, but the leads are easily adjusted (base to gate, collector to drain, emitter to source positions). With other NPN types look for a gain of 100 or more and adequate Ic for your load. For power users with cats, the TIP122 (5A) or TIP132 (12A) darlington transistors are a swap-in alternative to the MOSFET.

finished switcher

With the capacitors, check the lead pitch is suitable, 0.2" (5mm-6mm) apart from C3 & C5 which only span 0.1". The wire-ended ceramic disc or green mylar film types are easier to adapt to stripboard than the more rigid-leaded layer or box types.

If you're wanting to switch a relay or other reactive load, a diode (eg, an ultrafast 1A 400v UF4004) should be connected across each pair of output terminals on rows 1 & 3, banded cathode end to +12v on row 1. With "brushless" computer fan motors it's not necessary to fit this diode across the load, as they have any needed protection already in-fan.

Check carefully for correct component and connection lead placement, any solder bridging tracks, apply 12v and test.

One point – very rapid switching on & off won't work – the de-bounce circuit puts in a fraction-of-a-second delay while C1 recharges through R1. Not a problem in real life usage.



Setting the starting state

One feature of a flipflop chip is that in a basic circuit it will start on power-up with the output in either state — pin Q can be 'high' or 'low' (ie, at 12V or 0V) totally at random. In some situations you may want it to start in a definite state, say 'low', so Q1 and its load are off when you start up.

Setting a start state

Applying a brief logic 'high' signal (classed as anything over about 9V in this case) to the 'Reset' pin R causes Q to go 'low'. Applying the same signal to the 'Set' pin S sends Q 'high', so you can take your pick.

The 'high' pulse is generated by the delay components C4 and R5; on switch-on C4 is empty and starts to charge through R5, keeping the 'Reset' pin (in this example circuit, shown right) 'high' (ie, over 9V) for a few milliseconds after the 'Set' pin has been grounded 'low'. Potential at the C4-R5 junction gradually falls to zero as the capacitor fills and current flow into it stops. Output pin Q will stay 'low' keeping transistor Q1 off until switch S1 is pressed.

Swapping the connection from C4-R5 junction in the middle of the delay chain over to the 'Set' pin S and grounding the 'Reset' pin R instead would have the opposite effect, start-up would be pin Q high and Q1 switched on.

R6 has been added across the supply so the capacitor can discharge on shut-down ready for the next power-up. It may not be necessary if there is another discharge path somewhere in the supply circuit.

Values of C4, R5 & R6 are not critical; C4 can be anything handy 0.1uF-1uF. For R6, any high value resistor 47k-1M will discharge the capacitor in an adequate time.

Construction Guide – Component side view

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1 Fan1+   R1                               j5 R5   Fan2+
2         (br) Q1(g)   R4 (br)         (br) R8   Q2(g) (br)        
3 Fan1–         Q1(d) (br)                 (br) Q2(d)         Fan2–
4   Rb       Q1(s)     j3         C3     Q2(s)         0V
5             (br) R4   U1#1 (br)   U1#14 C3         j5   j12 12V
6             R3     U1#2 (br)   U1#13   R8 (br)            
7 Sw1a       R2         U1#3 (br)   U1#12     R7            
8 Sw1b   R1 C1 (br)     j2   U1#4 (br)   U1#11         R6       Sw2a
9           C2 R3     U1#5 (br)   U1#10 Rd2 Cd2     (br) C4 R5   Sw2b
10     Cd1       Rd1     U1#6 (br)   U1#9     R7 C5          
11       C1 R2 C2 Rd1 j2 j3 U1#7     U1#8 Rd2     C5 R6 C4      
12   Rb Cd1                       Cd2           j12  

The original board layout shown above can modified to start with the right-hand channel 'Off' and left channel 'On' quite easily. (Other variations will need a more drastic re-design.)

Changes are shown in red.


4013 switch
  1. links j1 and j4 are replaced with the delay resistors Rd1 & Rd2;
  2. capacitor C1 was grounded via the removed jumper j1 so needs its ground leg moving to the 0V row 11;
  3. a link is added to column 21 to bring a 12V supply to the unused bottom row 12;
  4. the delay capacitors Cd1 & Cd2 are fitted, on the left between 'Set' pin and 12V in column 3, on the right between 'Reset' pin and 12V in column 15 (in the photo left, C1 and the delay capacitor Cd1, plus C5 and Cd2, have swapped columns; makes no difference);
  5. the bleed resistor Rb is fitted between 12V and 0V in column 2.


A 555 flip flop

555 flipflop circuit

This is based on a circuit from Elektor magazine and seems quite reliable.

A common 555 timer chip is used, which contains a flip flop along with a couple of comparators.

When the output at pin#3 is 'high', C1 slowly charges through R1 up to 12V; when it's 'low' C1 discharges through R1 down to 0V. Pressing switch S1 upsets the 6V balance between R2 and R3 on pins #2 & #6 for a split second, triggering the flip flop and changing the state of the output from 'high' to 'low' or vice-versa. The wide hysteresis band of the 555 (between 1/3 supply voltage and 2/3 supply voltage) limits false switching from switch bounce.

555 toggle board
Parts List
IC1 555 Timer,
8-pin DIL socket (optional)
Q1TIP31 NPN power transistor
(see below)
R1 220k 0.25W
R2, R3 10k 0.25W
R4 220R 0.6W or 1W
(see below)
C1 220nF ceramic disc or mylar film
C2 10nF ceramic disc or mylar film
C3 220uF 16V electrolytic
C4 100nF ceramic disc or mylar film
SW1 Normally-open push-button switch to suit.

Construction Guide – Component side view

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1                                      
2 12V   j1     C3(+)     C1             R2 j5    
3               R1 C1                   Sw1a
4 0V     j2   C3(–)       C4 U1#1 (br)   U1#8     j5    
5                     U1#2     U1#7     j6   Sw1b
6               R1 R4   U1#3 (br)   U1#6 R3 R2 j6    
7 Load+   j1             C4 U1#4 (br)   U1#5   C2      
8       j2 j4                     C2      
9 Load–     j3 (br) (br) Q1(b)   R4 (br) (br)                
10       j3     Q1(c)                        
11         j4   Q1(e)               R3        
12                                      
13                                      


I've shown the stripboard 13 strips x 19 holes long, but the top row and bottom two rows aren't used, so it can be reduced a bit. I used some 2-way 0.2" connector blocks for the various wires as shown on the photo, these covered up the adjacent "spare" columns. Remember this is the view from the plain 'top' side, not the copper strip side.

Do a dry run with the components first to check everything fits. Make the track breaks as shown, if you don't have the special tool a few turns with a hand-held 6mm or so drill bit works well. Check carefully the track is completedly broken.

Start soldering up with the lowest components first – jumpers, resistors, 555 (or socket), capacitors, the transistor and wires or blocks, check for faults and test.


A few comments,

555 flip-flop switch
  1. Pin #7 on the 555 isn't used, pin #2 opposite it is connected to pin #6, so to make things a bit tidier I straightened out pin #7 and snipped it off. Now the copper track between #2 and #7 can be left intact and linked to the pin #6 track.
  2. The TIP31 comes as TIP31A, TIP31B, etc; the only difference is the maximum voltage rating. All are well over 12V.
  3. With R4 at 220R and the TIP31 shown, the switch will operate loads up to at least 1A. The 220R resistor will be dissipating 0.58W (V2/R = 11.32/220) so will get hot! Use at least a 0.6W resistor, 1W better.
  4. A good 1A alternative for Q1 is the BD139 with R4 = 330R 0.5W. Pins on the TO-126 cased BD139 go E-C-B compared to the TIP32's B-C-E so it needs spinning so the label side faces the right, towards the 555. For higher currents I'd suggest swapping Q1 to an IRF530 MOSFET with R4 any 0.25W resistor between 47R and 470R, or use R4 = 1k 0.25W with a TIP120 or TIP122 5A power darlington transistor. Pins are compatible with all the TO-220 cases. If you don't need to switch above 600mA the transistor can be swapped for a smaller, cheaper 2N2222A with a 1k 0.25W base resistor R4. There's a picture of the 2N2222A pinout further up the page.
  5. Capacitor C4 should be close to the 555 supply pins to prevent noise on the power lines causing false triggering.
  6. C3 value is not critical, 100uF-470uF should be OK, but watch the polarity!
  7. Capacitors C1 and/or C2 can be twisted to locate in any convenient holes in the correct rows to suit their lead pitch as shown in the photo.
  8. If you're planning to switch inductive loads such as brushed electric motors you'll need to connect a diode (eg, 1N4001) across the load output points, banded-end (cathode) to the load positive side, to protect the transistor against back-emf. It's not needed with lighting or case fans &ndas; "brushless" computer fan motors have any needed protection already in-fan.


Doing it discretely.

The next method is one devised by Winfield Hill, co-author of the classic Art of Electronics textbook, and posted by him in this sci.electronics.design thread (post#20).

As simple as it gets, and it works well.

circuit

When powered up, Q1 base is connected to 12V through the load and R4; Q2 gate is connected to about 10V (the potential at the R1-R2 junction). The significant gate capacitance of the MOSFET coupled with the high R1 value delays Q2 turn-on, Q1 switches on first and pulls Q2 gate low keeping it off.

With Q1 on, any charge in C1 leaks away through R2; if the momentary-on button SW1 is pressed, Q1 base voltage is pulled low, turning Q1 off and allowing Q2 to turn on, switching the load to full power instead of the few microamps it's been limited to by the path through R4 and Q1.

With Q1 off, capacitor C1 charges up to 12V through R1 & R2, so when the button is pressed again, it applies its voltage to Q1 base through R3 turning Q1 back on and so turning Q2 and the load off.

Some components shown are optional – the LED and its resistor R5 just indicate when the switch is on, diode D1 is to prevent damage from back-EMF pulses with inductive loads such as brushed motors or relays. Capacitor C2 reduces any HF noise on the supply.


Transistor Q1 can be any low-power NPN type, for ease of fitting with the leads in the right order, ie, 'base' lead in the middle. A BC337 or BC547 fit as shown below, a 2N3904 will need spinning 180° so check the pin-out for whatever type you use.

The n-channel power MOSFET Q2 also has plenty of alternatives such as the IRF630 or BUZ71; look for gate capacitance CISS around 500pF or more and a low on-resistance.

Construction


board layout

Circuit was built on a piece of stripboard 9 strips by 19 columns; the 0.2" pitch connector blocks I used took up 3 colums each so it could be smaller with soldered wire connections. Make the 4 track breaks as shown by the red blobs, soldering up from lowest to highest components as usual. The IRF530 MOSFET shown will switch anything up to 14A – if you're likely to want to switch over about 2.5A use thickish wire links for the pair on the RHS, and stiffen up the copper track between the Load(–) connector and MOSFET drain, and that between the 0V connector and MOSFET source, with extra solder or linkwire soldered along the track, or if you're over 10A take those connection points right up to the MOSFET pins (and it may need a small heat-sink).


Construction Guide – Component side view

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1       j1       Q1(e)       (br)              
2           R3 Q1(b)   R4   (br)         j3   Load+  
3       (br) R2   R1 Q1(c)       Q2(g) (br) R5 LED(a)        
4                 R4 D1(a)   Q2(d)     LED(c)     Load–  
5                       Q2(s)     j2        
6       j1       C1 C2           j2     0V  
7   Sw1a       R3                          
8             R1   C2 D1(c)       R5   j3   12V  
9   Sw1b     R2     C1                      
Parts List
Q1 BC337 or similar small-signal NPN
Q2 IRF530 n-channel MOSFET
D1 1N4001 silicon diode
LED1 LED to suit
R1 1M 0.25W
R2 4.7M 0.25W
R3 10k 0.25W
R4 330k 0.25W
R5 1k 0.25W
C1 220nF ceramic disc, polyester or mylar film
C2 100nF ceramic disc, polyester or mylar film
SW1 Normally-open push-button switch to suit.

With LEDs, the cathode (–) lead is usually the shorter of the two and next to a flat on the body skirt. It can, of course, be mounted remotely. The 1k LED resistor R5 will suit any colour.

With the high-value resistors used in this circuit it's important to reduce any chance of leakage so clean any flux residue from between the tracks. Also note the load forms part of the circuit, and must conduct electricity even when "off". If the load wires come loose even for an instant the circuit will switch off and stay off until the button is re-pressed (unless the LED indicator is used, which acts as a small permanent load).

There's also a wait of about 2 seconds after switching off before you can switch back on again, the time it takes C1 to charge/discharge; it shouldn't be a problem in real use.



Using a latching relay

If you don't fancy the flip flop method, you can still use push-buttons to switch your fans or lighting using relays. With the simplest system two buttons are needed, one to turn things on, a second to turn them off. The diode shown across the relay coil prevents a surge of back-emf when the relay is turned off.

latching relay

The relay is a double-pole type, with two switches which can be change-over (double-throw) or single-throw types. Pick one to suit the current you're switching and with a 12V DC coil.

The "On" switch S2 is a push-to-make (momentary on) type, and allows power through to the relay coil when pressed. This pulls the two relay switches over to the 'no' (normally-open) position.

Relay switch Sw2 now keeps power running to the relay coil after the "On" button has been released, latching the relay into the 'on' position.

Relay switch Sw2 is used to switch power to whatever load you have attached.

Pressing the "Off" button S1, a push-to-break (momentary off) type, breaks the power circuit, deactivating the relay and sending its switches back to the 'nc' (normally-closed) position.


(With any relay switch, "normally" means with no power applied to the coil.)

To use a single push-to-make push-button, things get more complicated. This solution posted by roger-k at diyAudio forums uses three relays, two with (at least) 3-pole change-over switches and the third with 4-pole c/o switches. Only the third needs to have switch contacts rated to the load current, switches on the others are only carrying the relay coil currents.

The relay coil voltage should match the supply voltage, and with DC supplies a diode (eg, 1N4001) should be fitted across each coil as shown in the previous diagram.

Start-up is with everything off. When the button S1 is first pressed, relay#1 coil is activated through the normally-closed positions of relay#3's switch R3a and relay#2's switch R2a. This closes relay#1's normally-open switch R1c on the third leg, activating relay#3.

In the meantime, looking at the relay#1 leg, R3a has opened but R1a in parallel has closed taking over from it, on the second leg R3b has closed for future use but R1b opened preventing relay#2 from activating, and on the third leg relay#3's 'no' switch R3c has closed, taking over from R1c and latching the relay#3 coil on, so providing a path to the load through the 'no' switch R3d.

Releasing the button, relay#1 coil is deactivated, its switches return to the 'normal' state, but relay#3 remains on.

With a second press, current can now flow to relay#2 coil through R3b and R1b, the relay activates breaking switch R2c and releasing the latch on relay#3.

All very complicated, but he's using the system to power his amplifier.