Turn LED ON and OFF with Button Arduino Code

Introduction

Hi, today in this tutorial we will Turn LED ON and OFF with Button Arduino Code, advantage of the digitalRead function, and learn how to read a digital pin. In our case, the digital sensor that will be read will be a common button which, when pressed, will turn on our LED.

What is Push Button Switch?

A push button switch is an electrical switch that is actuated by a button or plunger that is pressed or released. It is used to control the flow of current in an electrical circuit. Here are six features, specifications, and applications of a push button switch:

Hardware Required

Components#Buy From Amazon
Arduino UNO1Buy Link
LED 5mm1Buy Link
Button1Buy Link
Resistor 220​Ω1Buy Link
Jumper Wires5Buy Link
Breadboard1Buy Link

Pinout of Push Button Switch

Push-Button-Switch-Pinout

Features:

  1. Compact design: Push button switches to have a small and compact design that makes them easy to install and use.
  2. Versatile: Push button switches are available in a variety of configurations, including momentary and latching types, and with different switch functions.
  3. Easy to operate: Push-button switches easily operate with a single finger or hand.
  4. Durable: Push button switches are typically designed to withstand repeated use, making them a reliable option for controlling electrical circuits.
  5. Color-coded: Push button switches are often color-coded to indicate their function or status, making them easy to identify.
  6. Affordable: Push button switches are generally affordable and cost-effective compared to other types of switches.

Specifications:

  1. Contact rating: The contact rating of a push button switch specifies the maximum current and voltage that it can handle.
  2. Switch function: The switch function of a push button switch determines how it behaves when the button is pressed or released. Common functions include on/off, momentary, and latching.
  3. Actuation force: The actuation force of a push button switch specifies the amount of force required to press the button and activate the switch.
  4. Contact configuration: The contact configuration of a push button switch determines how the contacts connect in the switch, such as normally open (NO), normally closed (NC), or changeover (CO).
  5. Termination style: The termination style of a push button switch specifies how it connects to a circuit, such as through soldering, wiring, or a PCB mount.
  6. Environmental rating: The environmental rating of a push button switch specifies its resistance to factors such as temperature, moisture, and dust.

Circuit Diagram

Push-Button-Switch-and-LED-Interfacing-with-Arduino-Circuit

Circuit Connection

ArduinoButtonLED
13 Pin+Ve
7 Pin2nd Pin
5v1st Pin
GND2nd Pin By R1-Ve

Installing Arduino IDE Software

First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow

Code

//For more info Visits: www.arduinocircuit.com

int ledPin = 13; //The LED is connected to pin 13
int button = 7; //The button is connected to pin 7
int val = 0;
void setup() {
  pinMode(ledPin, OUTPUT); //The pin of the led is an output
  pinMode(button, INPUT); //The pin of the button is an input
  }
void loop() {
 
  val = digitalRead(button); //Read the button

  if (val == 1){ //If the button's value is 1
    digitalWrite(ledPin, HIGH); //Turn on the led
  }
  else { // Else:
    digitalWrite(ledPin, LOW); //Turn off the led
  }
}

Applications:

  1. Industrial equipment: Push button switches commonly uses in industrial equipment such as machinery, conveyor systems, and control panels.
  2. Automotive: Push button switches often use in automotive applications, such as in dashboard controls and door locks.
  3. Medical devices: Push button switches to use in medical devices such as infusion pumps and patient monitors.
  4. Appliances: Push button switches uses in various home appliances such as washing machines, refrigerators, and microwaves.
  5. Consumer electronics: Push button switches to use in various electronic devices such as remote controls, audio equipment, and gaming consoles.
  6. Lighting: Push button switches are often used in lighting systems, such as in switches for turning lights on and off or changing their brightness.

Leave a Comment


error: