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 UNO | 1 | Buy Link |
LED 5mm | 1 | Buy Link |
Button | 1 | Buy Link |
Resistor 220Ω | 1 | Buy Link |
Jumper Wires | 5 | Buy Link |
Breadboard | 1 | Buy Link |
Pinout of Push Button Switch
Features:
- Compact design: Push button switches to have a small and compact design that makes them easy to install and use.
- Versatile: Push button switches are available in a variety of configurations, including momentary and latching types, and with different switch functions.
- Easy to operate: Push-button switches easily operate with a single finger or hand.
- Durable: Push button switches are typically designed to withstand repeated use, making them a reliable option for controlling electrical circuits.
- Color-coded: Push button switches are often color-coded to indicate their function or status, making them easy to identify.
- Affordable: Push button switches are generally affordable and cost-effective compared to other types of switches.
Specifications:
- Contact rating: The contact rating of a push button switch specifies the maximum current and voltage that it can handle.
- 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.
- Actuation force: The actuation force of a push button switch specifies the amount of force required to press the button and activate the switch.
- 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).
- 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.
- Environmental rating: The environmental rating of a push button switch specifies its resistance to factors such as temperature, moisture, and dust.
Circuit Diagram
Circuit Connection
Arduino | Button | LED |
---|---|---|
13 Pin | +Ve | |
7 Pin | 2nd Pin | |
5v | 1st Pin | |
GND | 2nd 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:
- Industrial equipment: Push button switches commonly uses in industrial equipment such as machinery, conveyor systems, and control panels.
- Automotive: Push button switches often use in automotive applications, such as in dashboard controls and door locks.
- Medical devices: Push button switches to use in medical devices such as infusion pumps and patient monitors.
- Appliances: Push button switches uses in various home appliances such as washing machines, refrigerators, and microwaves.
- Consumer electronics: Push button switches to use in various electronic devices such as remote controls, audio equipment, and gaming consoles.
- Lighting: Push button switches are often used in lighting systems, such as in switches for turning lights on and off or changing their brightness.