Controlling 3 relays using a single pin

The 10F200-206 PIC's are cheap (I have paid less than 30p each for 10F208 in a SSOP package) but have only 4 user pins (3 i/o's and one input only). Of course the 3 i/o's could be used with a 'port expander', which would allow you to select one of 8 relays, however this is likely to cost (a lot) more than choosing a PIC with an extra 8 i/o pins in the first place ! Further, with only 4 pins in total, chances are you will need to use most of them as inputs anyway. SO = how can we select (activate) one of 3 relay's using only a single i/o pin ? 1) We start by noting that a PIC pin has 3 'states' = 'off' (input mode), 'Hi' (4v3) and 'Lo' (0v7). Assuming a 5v0 Vdd supply voltage, we add a pair of resistors to form a 'voltage divider' at the pin. So, when the pin is 'off' (set to 'input' mode), it will be 'pulled' to the 'mid point' voltage (2v5). To avoid problems with the input 'sense' circuits oscillating, the mid-point voltage must avoid the 'input threshold'. This is typically 2v0. Choosing 2v5 thus ensures the input always "sees" a '1' 2) We now have 3 discrete voltages, so it is now possible to construct relay drive circuit that will 'activate' one of 3 relays. However there is one restriction. At power on, the PIC sets all it's pins to input mode. So, by default, the 'mid point' relay will be 'activated'. 3) The relay control 'swtiches' now have to 'detect' the specific voltages. It's worth noting that relays take time to 'switch'. So, if your application requires that no two relays ever be 'on' at the same time (an example would be a motor 'forward' and 'reverse' drive) you will have to modify the circuits below to ensure 'off' times are significantly faster than 'on' times Basic operation:- The 'Hi relay' activates when 4v0 (or more) is seen The 'Lo relay' activates when 1v0 (or less) is seen The 'Mid relay' activates when a voltage between 2v0 and 3v0 is seen Simple P and N channel MOSFETS will get you the Hi and Lo circuit. The 'hard' one is the 'Mid' circuit. MOSFET's - which are effectivly voltage controlled drvoces - are suggested to minimise current flows and thus minimise the eccect on the PIC pin when the curcuit 'switches'. Even so, if is suggested that all curcuits are simulated using LTSPICE before being constructed
The 2 LEDs are driven 'as usual' (driving the PIC i/o pin Lo illuminates Red 20mA, driving Hi illuminates Green 10mA)

When no LED is lit (PIC i/o = input), the internal 'weak pull up' (or R3) of 22k will hold the pin Hi (there should be insufficient current to light G LED, but even is so, Green LED Vf will hold the pin to 3v min (and a '1' will be seen so long as the pin is 2v or above)

When the user presses the button, this will pull the PIC pin to 0v6 max. and a '0' will be seen. It will also pass approx 10mA through the Red LED (so approx 50% lit)

The danger is that the user may press the LED when the PIC is driving Hi (Green LED lit) - if this happens, the i/o pin will have to source 20mA via R4 + 10mA via G LED & R2 = 30mA total which is outside the PIC spec. (25mA) and risks burning the pin. So, to 'protect' against this, the PIC s/w code has to check for the button (switch the i/o pin between Green Hi drive and input sense) at regular intervals = the human eye won't spot anything over 30Hz. Note, if 'feedback' is required (so the user knows their button press has been 'seen'), the PIC should respond by pulling the i/o pin Lo (so Red LED now 100%) and not Hi (Green) (unless 'strobing' is used to stay within the 25mA current limit)