0% found this document useful (0 votes)
3 views

Arduino Week 3 Push Button 2

The document outlines the objectives and functionality of using a push button in Arduino projects, emphasizing its role as a simple input device for user interaction. It explains how the push button works, including its wiring configuration and provides sample code for controlling an LED based on the button's state. Additionally, it includes an activity for students to assemble a circuit and program the Arduino to light an LED when the button is pressed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Arduino Week 3 Push Button 2

The document outlines the objectives and functionality of using a push button in Arduino projects, emphasizing its role as a simple input device for user interaction. It explains how the push button works, including its wiring configuration and provides sample code for controlling an LED based on the button's state. Additionally, it includes an activity for students to assemble a circuit and program the Arduino to light an LED when the button is pressed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Arduino and Its

Daily Application
Using Push Button
Objectives:
At the end of the lesson, the students
will be able to:
• explain how Push Button works;
• Identify the correct connection of a
switch.
• Demonstrate the proper wiring in
connecting the circuit to switch.
💡 Questions:

1.Where have you seen or used


a push button in daily life?

2. What happens when you


press and release a button?

3. Why do you think push


buttons are important in
electronics and technology?
A Push Button in
Arduino projects is a
simple input device used
to detect user actions,
such as pressing or
releasing the button. It
allows you to control and
interact with the Arduino
program.
How a Push Button Works:
•A push button is a momentary switch that establishes or
breaks a connection in a circuit when pressed.

•It typically has four pins, where pairs of pins are


internally connected. Pressing the button connects the two
sets of pins.

•The button is connected in a pull-up or pull-down


configuration to ensure it has a stable voltage (HIGH or
LOW) when not pressed.
Sample Code:
Variable Declarations:

•LED1 = 2; → Assigns digital pin 2 to control an LED.


•pb = 6; → Assigns digital pin 6 to read the push button state.
•buttonState = 0; → Initializes a variable to store the push button’s
state (pressed or not)
Setup() Function (Runs Once at Startup)

•pinMode(LED1, OUTPUT); → Configures pin 2 as an output (to


turn the LED on/off).
•pinMode(pb, INPUT); → Configures pin 6 as an input (to read
the push button state).
•Serial.begin(9600); → Starts serial communication to display
messages in the Serial Monitor.
loop() Function (Runs Repeatedly)

digitalRead(pb); → Checks if the push button is


pressed or not pressed.
Conditional Statement (Checking Button State)

•If buttonState == LOW (button is pressed):


- digitalWrite(LED1, LOW); → Turns LED OFF.
- Serial.println("Button Released"); → Prints "Button Released" in the
Serial Monitor.
Conditional Statement (Checking Button State)

•If buttonState == HIGH (button is pressed):


- digitalWrite(LED1, HIGH); → Turns LED ON.
- Serial.println("Button Pressed"); → Prints "Button Pressed " in the
Serial Monitor.
Summary of How It Works
1. The Arduino reads the button state from pin 6.
2. If the button is pressed (HIGH) → The LED
turns ON, and "Button Pressed" is printed.
3. If the button is released (LOW) → The LED
turns OFF, and "Button Released" is printed.
4. The process repeats indefinitely in the loop()
function.
Activity: Push-Button Switch with LED
Materials:
• Microcontroller • LED
• Jumper wire • Resistor
• USB Cable • Breadboard
• Push Button

Directions:
1. You will be given a set of materials.
2. Assemble the circuit.
3. Create an Arduino program that will let the LED light when the push
button is pressed.
4. Test and troubleshoot.
5. Clean up. (Disassemble and return the materials)
ONE LED WITH PUSH BUTTON

You might also like