# 2-Wire Interface Schematic Circuit Diagram

Klaus Jürgen Thiesler’s ‘2-Wire Interface’ was published in Elektor magazine in the form of both basic [1] and low-current [2] versions. Each variant used two transistors and a handful of other components to hook up an LED and a pushbutton to a microcontroller. The author still felt driven to simplify this arrangement further and can now provide a solution that, with only two resistors and a single I/O pin, could hardly be minimalized anymore. Unless you know better! Reducing the number of components means the microcontroller has to work somewhat harder. This solution makes the assumption that an I/O pin can be toggled between input and output, which is virtually always the situation. The circuit is able to light the LED as output in ‘High’ state and assess the status of the switch when the LED is not alight. If you take a look at the state table, the first two lines (numbered 1 and 2) should make things clear. The I/O pin is switched as an input and the voltage Uin applied to it, according to the status of the switch, is interpreted as ‘low’ or ‘high’ so long as resistors R1 and R2 have been selected correctly to match the supply voltage UB (most microcontrollers have an upper switching threshold in the region of 0.5 UB).

So far, so good. But how can the switch be polled in states 3 and 4, when the I/O pin is functioning as an output? Quite simply in fact. Several times a second the pin is turned into an input for an extremely short period. In this way, for less than a blink of the eye, we have state 1 or 2, which thanks to the sluggishness of the human eye (persistence of vision, as it is called) is not even noticeable. If it is established then that the pushbutton switch is depressed, the pin remains in state 2 until it is released again, as state 4 would not make any difference (the LED remaining unlit), other than unnecessary current flows. Following this the controller switches back immediately into state 3, making the LED illuminate again. In the firmware of the microcontroller, we can implement not just basic debouncing but also ‘deluxe’ functions such as variable brightness for the LED, achieved very simply by toggling rapidly between states 1 and 3. Imagination knows no boundaries here! The author developed his solution around the PIC16F883 [3]. This type operates with internal pull-up resistors that can be activated exactly as on the well-known AVR controllers. In principle, particularly if you reduced UB, you could replace R2 with this internal resistor. Unfortunately, these pull-ups have values exclusively in the range from 10 to 50 kΩ, which could lead to the LED lighting dimly (but definitely visibly) in state 1. The firmware, therefore, enables the pull-up only as long as necessary for polling the pushbutton switch, to ensure this effect is not bothersome.

In any event, R2 must be selected so that the switching threshold of the input is definitely exceeded since the forward voltage Uf drops with small currents. This very effect can become a problem when using a red LED and 5 V operating voltage. In this situation, an ordinary silicon diode in series with the LED will help. Dimensioning the resistors relative to the supply voltage and according to LED color is set out in another table. With differing currents, you will need to do some calculation.

[1] 2-Wire Interface for Illuminated Pushbuttons, Elektor April 2012, www.elektor.com/110572

[2] 2-Wire Interface version 2.0, Elektor January & February 2013, www.elektor.com/120071

[3] Firmware: www.elektor.com/130115

Tags

Check Also
Close

Close
Close