How to Make an LED Glow with a Push Button Using Arduino (With Fewer Inputs)

Are you looking to learn how to make an LED glow using a push button and Arduino, but want to minimize the number of inputs? In this step-by-step guide, we’ll show you how to do it using fewer inputs for simplicity.

Whether you’re a beginner or an experienced tinkerer, this Arduino project is a great way to enhance your understanding of electronics and coding.

Components Required

To complete this project, you’ll need the following components:

  • Arduino UNO Board
  • LED
  • Resistor: 10k ohms and 100 ohms
  • Push button
  • Virtual Wirings

Step-by-Step Guide

  1. Set Up the Components:
    • Connect the LED to pin 4 of the Arduino.
    • Place a 10k ohm resistor between the push button and pin 3 of the Arduino.
    • Use a 100-ohm resistor for the LED to ensure it doesn’t burn out.
    • Ensure that the ground and power connections are properly wired.
  2. Source Code: Below is the simple and optimized code for this project. This code minimizes the inputs while making the LED glow when the button is pressed.
const byte LED = 4, button = 3; 
byte check;

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(button, INPUT);
}

void loop() {
  check = digitalRead(button); 
  if (check == 1) {
    digitalWrite(LED, 1); 
    delay(800); 
    digitalWrite(LED, 0);
  }
}
  1. Explanation of the Code:
    • The LED is connected to pin 4, and the push button is connected to pin 3.
    • In the loop, the Arduino reads the input from the button, and if the button is pressed, it turns on the LED for 800 milliseconds before turning it off again.

Results

Once you’ve set up your circuit and uploaded the code, pressing the button will cause the LED to glow. The simple use of fewer inputs keeps the project efficient and easy to understand for beginners. Below is the circuit diagram for better visualization:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *