PUSH BUTTON:
- The push button is a component and connects the two points.
- The first pin the push button is connected to a 5 volt supply.
- The second pin the push button is connected to gnd.
Figure1: PushButton
Required Materials
- Arduino Uno board
- Push-button
- Led
- Breadboard
- Hook up wires
- USB cable
Step 1: Push-button connection,
- The first pin the push button is connected to a 5 volt supply.
- The second pin the push button is connected to gnd and to digital pin 03.
- The LED has a positive and a negative point.
- The positive point of LED is connected to a digital pin 13.
- The negative points connected to a gnd
Step 2:
Connect the Arduino board to your computer with the USB cable and start sketching the following program,
Step 3: Programming
- int led = 13;
- int PinButton = 4;
- void setup()
- {
- pinMode(PinButton, INPUT);
- pinMode(led, OUTPUT);
- }
- void loop()
- {
- int stateButton = digitalRead(PinButton);
- if (stateButton == 1)
- {
- digitalWrite(led, HIGH);
- }
- else
- {
- digitalWrite(led, LOW);
- }
- delay(20);
- }
Explanation
Declare the variables: led, PinButtons and assign the value to that and in the setup() function set the button as the INPUT and led as the OUTPUT
and in the loop() function stateButton=digitalRead(PinButton). It reads the state of the push button value and if (stateButton==1) it means to check if the push button is pressed and if the button state will be HIGH, then the led will glow and if it is not that means led will not glow.