Arduino Push Button With Multiple LEDs Tutorial
by Arduino Circuit in Circuits > Arduino
1298 Views, 2 Favorites, 0 Comments
Arduino Push Button With Multiple LEDs Tutorial
This tutorial demonstrates how to use an Arduino Push Button with Multiple LEDs. The push button will toggle the LEDs on and off in a specific sequence. This is a great introduction to basic programming concepts and can be easily modified to create more complex LED sequences.
For more Details Please visit our website Link https://www.arduinocircuit.com/arduino-push-button-with-multiple-leds-tutorial/
What You Will Need
Arduino UNO
Push Button
LEDs (Different Colors) 4
Resistors 220Ω -4
Resistors 10KΩ -1
Jumper Wires
Breadboard
Circuit Diagram
Circuit Construction
To set up the circuit, connect four LEDs to Arduino digital pins 8, 9, 10, and 11. Connect the anode (positive leg) of each LED to the respective digital pin, and connect the cathode (negative leg) of each LED to a 220 Ω resistor. Connect the other end of each resistor to the ground. Connect a push button to digital pin 13.
Code Upload
//For more Projects: www.arduinocircuit.com
int ledPin[4] = {8, 9, 10, 11};
const int buttonPin = 13;
int buttonState = HIGH;
int pushCounter = 0;
int numberOfLED = 4;
void setup() {
pinMode(buttonPin, INPUT);
for (int i = 0; i <= 4; i++) {
pinMode(ledPin[i], OUTPUT);
}
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
for (int i = 0; i < numberOfLED; i++) {
if (pushCounter % numberOfLED == i) {
digitalWrite(ledPin[i], HIGH);
}
else {
digitalWrite(ledPin[i], LOW);
}
}
pushCounter++;
delay(400);
}
}