Charles van't Westeinde
Published

Control two loads with a single pin

Do you want to extend an existing project to control additional devices, but you've run out of digital pins? Here's the workaround!

BeginnerProtip1 hour80
Control two loads with a single pin

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
I used a NodeMCU for testing. The design should work with any 3.3V MCU.
×1
General Purpose Transistor PNP
General Purpose Transistor PNP
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Through Hole Resistor, 470 ohm
Through Hole Resistor, 470 ohm
×2
Through Hole Resistor, 180 ohm
Through Hole Resistor, 180 ohm
×1

Story

Read more

Schematics

Dual load on single pin

Circuit used in conjunction with Blink2 to test controlling 2 loads with a single pin. The test used 2 LEDs with 120 ohm resistors as loads.

Code

Blink2

Arduino
Uses a single pin to step through 3 states for two leds: either both off, or one on.
Assumes the circuit as per diagram.
/*
  Blink2

  Turns a LED on for one second, then off for one second, same for a second LED on the same pin repeatedly.
  Switches PIN to INPUT to turn leds off, OUTPUT TRUE or FALSE to turn one of the LEDs on.

*/

// the setup function runs once when you press reset or power the board
void setup() {
}

#define SHARED_PIN    5
// the loop function runs over and over again forever
void loop() {
  pinMode(SHARED_PIN, OUTPUT);
  digitalWrite(SHARED_PIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);   
                     // wait for a second
  pinMode(SHARED_PIN, INPUT);
  delay(1000);                      // wait for a second

  pinMode(SHARED_PIN, OUTPUT);
  digitalWrite(SHARED_PIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second

  pinMode(SHARED_PIN, INPUT);
  delay(1000);                      // wait for a second

}

Credits

Charles van't Westeinde
4 projects • 1 follower
Electronics engineer by education, software engineer by trade. Combining the two is my idea of fun.

Comments