Klausj
Published © GPL3+

Multiple Buttons & LEDs with just 1 Wire

Driving lots of LEDs using just 1 wire has become easy since WS2812. Reading multiple buttons with only 1 wire needs some voltage dividers.

BeginnerFull instructions provided1 hour257
Multiple Buttons & LEDs with just 1 Wire

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
WS2812B Digital RGB LED Flexi-Strip 144 LED - 1 Meter
Seeed Studio WS2812B Digital RGB LED Flexi-Strip 144 LED - 1 Meter
cut just 7 elements or use a strip with only a few leds
×1
Big Red Dome Button
SparkFun Big Red Dome Button
any other pushbutton will do
×1
Resistor 10k ohm
Resistor 10k ohm
see text
×1
Jumper wires (generic)
Jumper wires (generic)
×4

Story

Read more

Schematics

two-wire_Sd2urHZzJk.png

two-wire-ladder_CZvfYEH8S0.png

two-wire-select_A0712ONuxf.png

Code

two-wire-1.ino

Arduino
Arduino code for schematis-1
/*
  external pullup-resistor = 15 kOhms
  Res  ADC btn
  0    000 1
  2.7k 153 2
  6.8k 314 3
  12k  452 4
  22k  605 5
  39k  737 6
  100k 890 7
  inf  1023 8
*/

int len = 7;
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip(len, 2, NEO_GRB + NEO_KHZ800);
const float ref = 7 / 1023.0;

void setup() {
  Serial.begin(9600);
  Serial.println(__FILE__);
  strip.begin();
}

void loop() {
  int voltage = analogRead(A0);
  int btn = voltage * ref;
  Serial.print(voltage);
  Serial.print("\t");
  Serial.println((btn + 1) * 100);
  strip.fill(0x010101, 0, len);
  strip.setPixelColor(btn, 255);
  strip.show();
  delay(100);
}

Credits

Klausj
89 projects • 8 followers

Comments