0% found this document useful (0 votes)
3 views14 pages

Arduino Week 3 Push Button

The document outlines a lesson on using a push button in Arduino projects, detailing its function as an input device to control an LED. It explains the wiring setup, sample code for reading the button state, and the corresponding actions for pressing and releasing the button. Additionally, it provides an activity for students to assemble a circuit and program the Arduino to light an LED when the button is pressed.

Uploaded by

hs220069
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views14 pages

Arduino Week 3 Push Button

The document outlines a lesson on using a push button in Arduino projects, detailing its function as an input device to control an LED. It explains the wiring setup, sample code for reading the button state, and the corresponding actions for pressing and releasing the button. Additionally, it provides an activity for students to assemble a circuit and program the Arduino to light an LED when the button is pressed.

Uploaded by

hs220069
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Arduino and Its

Daily
Application
Objectives:
At the end of the lesson, the students
will be able to:
• Explain how Push Button works.
• Demonstrate the proper wiring in
connecting the circuit to LED and Push
Button.
💡 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 the 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 (LOW) or not pressed (HIGH).
Conditional Statement (Checking Button State)

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


- digitalWrite(LED1, HIGH); → Turns LED ON.
- Serial.println("Button Pressed"); → Prints "Button Pressed" in the
Serial Monitor.
Conditional Statement (Checking Button State)

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


- digitalWrite(LED1, LOW); → Turns LED OFF.
- Serial.println("Button Released"); → Prints "Button Released" 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 (LOW) → The LED
turns ON, and "Button Pressed" is printed.
3. If the button is released (HIGH) → 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