Driving a pair of "status" LEDs from 1 pin

When I posted a simple receiver sketch for an RF link back in March, there was no shortage of spare pins available.  I used one for driving a green LED for "transmission OK" , another for a red LED for "transmission failed", and a third pin for a yellow LED to indicate when the remote load was enabled (as well providing a dedicated control line for the load).

When pins start to get tight, you have to economise.  The red and green LEDs can easily be toggled on/off using a single driver pin as per the attached sketch.  You can also get both LEDs to (almost) go off together in software.

The yellow "load on" indicator can share the same line as for controlling the remote load.  In my case, the remote load is controlled via an MOC3041 opto-isolator, its connections being 3.3V (via a series resistor) and a driver pin.  The indicator LED can connect between the same two points via its own series resistor.   Providing that it only draws a few mA, the operation of the trigger/triac combination won't be affected.


calypso_rae's picture

Re: Driving a pair of "status" LEDs from 1 pin

As noted previously, to achieve three-state selection (LED 1, LED 2 or neither) requires the use of two control constructs(), pinMode and digitalWrite().  The latter provides the ability to select between the two LEDs; the former provides the enable/disable function.

The attached sketch pulses two LEDs in turn with periods of inactivity between.  There is a video of its operation at


This demo is running on an emonTx V3.4.  Please note that when driving two LEDs in this manner, the emonTx must be powered from an external DC supply such as a USB programmer.  The AC adapter does not provide sufficient DC power for this application.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.