5 Push-Buttons Using Only 1 Arduino Input Pin

Description: Five Push-Buttons are connected to only one Analog Input Pin on the Arduino Nano and each Push-Button when pressed lights up a different color LED. This method frees up additional input pins that may be required for other tasks.

Notes: It’s important that the five resistors connected to the five push-buttons each have a different resistance value (between 0 and 1023) in order for us to see and recognize in the serial monitor which button has been pressed.

Supplies:

1 – Breadboard 830 Points
1 – Arduino Nano
5 – Push-Buttons
5 – LEDs
1 – 10 Ohm Resistor
1 – 33 Ohm Resistor
1 – 56 Ohm Resistor
1 – 82 Ohm Resistor
1 – 120 Ohm Resistor
1 – 1k Ohm Resistor

Arduino Code:

int ledPinred = 3;
int ledPinwhite = 5;
int ledPinblue = 7;
int ledPingreen = 9;
int ledPinyellow = 12;
int buttonValue = 0;

void setup() {
  
  Serial.begin(9600);
  pinMode(ledPinred, OUTPUT);
  pinMode(ledPinwhite, OUTPUT);
  pinMode(ledPinblue, OUTPUT);
  pinMode(ledPingreen, OUTPUT);
  pinMode(ledPinyellow, OUTPUT);
  
}

void loop() {

  int sensorValue = analogRead(A0);

  Serial.println(sensorValue);

  buttonValue = analogRead(A0);

  if (buttonValue>=690 && buttonValue<=740)
  digitalWrite(ledPinyellow, HIGH);
  else
  digitalWrite(ledPinyellow, LOW);

  if (buttonValue>=500 && buttonValue<=570)
  digitalWrite(ledPingreen, HIGH);
  else
  digitalWrite(ledPingreen, LOW);

  if (buttonValue>=210 && buttonValue<=230)
  digitalWrite(ledPinblue, HIGH);
  else
  digitalWrite(ledPinblue, LOW);

  if (buttonValue>=110 && buttonValue<=125)
  digitalWrite(ledPinwhite, HIGH);
  else
  digitalWrite(ledPinwhite, LOW);

  if (buttonValue>=15 && buttonValue<=25)
  digitalWrite(ledPinred, HIGH);
  else
  digitalWrite(ledPinred, LOW);

}

Leave a Comment

4 + 2 =