Arduino Button With LED
Hey, Guys...
Our this Project is about Push Button, yes today we will learning how to control an LED with a PushButton using Arduino. Now, what is PushButton? A PushButton is a device or a simple Switch mechanism to control such aspects or Process. A PushButton is a device that connects 2 points of a circuit whenever it gets pressed. Here we are using this PushButton to turn ON and OFF the LED. Like when we Press the Button our LED is turns ON, and when leaving the Button LED again back to OFF state(or turn OFF).
For detailed information of PushButton visit https://en.wikipedia.org/wiki/Push_switch
Components Used:-
1. Arduino Uno
4. 5mm LED
5. Jumper wire
Software Used:-
Circuit:-
Steps:-
Step 1:- First of all, take the pushbutton and plug it at the centre of the Breadboard as shown in the circuit diagram above.
Note that in the 4 pin push button each two terminals are connected internally so whenever you conect the button just check out the pin configuration that which two pins are connected internally (use Multimeter for better result).
Step 2:- Now connect one pin of the button with the 5v VCC supply of Arduino.
Step 3:- Then connects another pin of the button with GND though 1k ohm resistor. The same pin of the button is connected with the signal pin of Arduino i.,e pin 4 of Arduino.
Step 4:- Now plug the LED on to the breadboard and connects the short leg (Cathode) of the LED with GND of Arduino.
Step 5.:- And connects another leg (Anode) of LED with Pin No. 12 of Arduino.
Step 6:- Now connect the Arduino board with the PC by using a USB cable and check for the Board type (Tools > Board > Arduino Uno). And also check for the Serial Port (Tools > SerialPort > COM).
Step 7:- Upload the Program.
Whenever the button is pushed(Pressed) the LED is Turn ON and when the button is un-pushed(not Pressed) the LEdis turn OFF.
The circuit is Ready...
Schematics:-
Code:-
Code Desciption:-
Here first we declare the value of Push Butoon that is 0, int ButtonValue=0; and define the integer int LED=12; that means the LED pin is connected to pin no 12 of arduino. And int BUTTON=4; that means Button pin is connected with the pin no 4 of arduino.void setup
in the void setup we declare the pinMode to provide the output to the LED we can write pinMode(LED,OUTPUT); and input to the Button we acn write pinMode(BUTTON,INPUT);
void loop
In the void loop we write ButtonValue = digitalRead(BUTTON); that means when the Button is pushed it would Read the digital value i.e., either 0 or 1.
Here we use the if - else condition that means if the button is pressed so the LED should ON and else it should be OFF we write the same statement in the form of code like if (ButtonValue == HIGH) (here == means Equals to) then digitalWrite(LED, HIGH); else digitalWrite(LED, LOW);
For more detail of if - else condition:- https://www.arduino.cc/reference/en/language/structure/control-structure/else/
No comments:
Post a Comment