Skip to content

Project 2.5.8:LED Control with Arduino and Push Button

| Description | You will learn how to create a simple circuit using a Push button and 4 LEDs. | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Use case |The use case for using a push button to control the blinking of LEDs is to provide customizable visual feedback, signaling/alerting functionality, interactive lighting, educational demonstrations, or prototyping/testing capabilities.|

Components (Things You will need)

LED Arduino Uno Arduino USB Cable Breadboard Jumper Wires Push Button

Building the circuit

Things Needed:

  • Arduino Uno = 1
  • Arduino USB cable = 1
  • Resistor = 1
  • Push button = 1
  • Red LED = 1
  • Yellow LED = 1
  • Green LED = 1
  • Blue jumper wire= 1
  • Yellow jumper wire= 1
  • Black jumper wire= 1
  • Red jumper wire= 1

Mounting the component on the breadboard

Step 1: Connect the push-button on the breadboard but make sure the two pair of the pins are connected on each side of the bridge. inseting the buzzer.

step 2 Inset four (4) LEDs on the breadboard as shown in the picture below. inseting the buzzer.

WIRING THE CIRCUIT

Things Needed:

  • Red male-male-to-male jumper wires = 2
  • White male-to-male jumper wires = 5
  • Green male-to-male jumper wires = 1
  • Yellow male-to-male jumper wires = 1
  • Black male-to-male jumper wires = 1
  • Blue male-to-male jumper wires = 2

step 1: Connect male-to-male jumper wire from one Pin of the Push Button as a negative to power GND (Ground) on the Arduino UNO. inseting the buzzer.

step 2: Connect male-to-male jumper wire from the other Pin of the push button (not connected to GND) to a digital pin 13 on the Arduino UNO. inseting the buzzer.

step 3: Connect three male-to-male jumper wires from the each of the LEDs negative pin to the negative holes on the breadboard. inseting the buzzer.

step 4: Connect male-to-male jumper wire from the longer pin of the first LED as a positive to digital pin 12 on the Arduino UNO. inseting the buzzer.

step 5: Connect male-to-male jumper wire from the longer pin of the second LED as a positive to digital pin 9 on the Arduino UNO. inseting the buzzer.

step 6: Connect male-to-male jumper wire from the longer pin of the third LED as a positive to digital pin 4 on the Arduino UNO. inseting the buzzer.

step 7: Connect male-to-male jumper wire from the longer pin of the third LED as a positive to digital pin 2 on the Arduino UNO. inseting the buzzer.

step 8: Connect male-to-male jumper wire from the Arduino GND to the one of the negative holes on the breadboard. inseting the buzzer.

PROGRAMMING

Step 1: Open your Arduino IDE. See how to set up here: Getting Started.

Step 2: Type the following codes before the void setup function.

const int ledPin1 = 12;
const int ledPin2 = 9;
const int ledPin3 = 4;
const int ledPin4 = 2;
const int buttonPin = 13;
bool isBlinking = false;

code 1.

Step 3: After the void setup ()within the curly brackets type the following codes.

pinMode (ledPin1, OUTPUT);
pinMode (ledPin2, OUTPUT);
pinMode (ledPin3, OUTPUT);
pinMode (ledPin4, OUTPUT);
pinMode (buttonPin, INPUT_PULLUP);

code 2.

Step 4: : After the (void loop ()) within the curly brackets type

if (digitalRead(buttonPin) == LOW && !isBlinking) {
    isBlinking = true;
    while(digitalRead(buttonPin) == LOW) {
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
      digitalWrite(ledPin3, HIGH);
      digitalWrite(ledPin4, HIGH);
      delay(500);
      digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delay(500);
 isBlinking = false;
  }
}

code 3.

Uploading the code

Step 1: Save your code. See the Getting Started section

Step 2: Select the arduino board and port See the Getting Started section:Selecting Arduino Board Type and Uploading your code.

Step 3: Upload your code. See the Getting Started section:Selecting Arduino Board Type and Uploading your code

CONCLUSION

If you encounter any problems when trying to upload your code to the board, run through your code again to check for any errors or missing lines of code. If you did not encounter any problems and the program ran as expected, Congratulations on a job well done.