Microcontroller GPIO: LED and push button
To control an LED from a microcontroller output and read a push button on an input with a pull-up.
Theory
A GPIO pin set as output drives the LED through a current-limiting resistor: R = (Vpin − Vf) / I. A pin set as input with the internal pull-up reads HIGH when the button is open and LOW when it connects the pin to ground. Mechanical buttons bounce for a few milliseconds, so the code must debounce them.
Apparatus
- Arduino Uno (or any microcontroller board)
- LED and 220 Ω resistor
- Push button
- Breadboard
Circuit connections
- D9 → 220 Ω → LED long leg; LED short leg → GND
- D2 → button → GND (INPUT_PULLUP)
Procedure
Pre-lab check
4 questions · 75% to be readyTry the readings before the lab
| LED colour | Vf (V) | R needed (Ω) | Nearest standard (Ω) |
|---|---|---|---|
| Red | 2 | 300 | 330 |
| Yellow | 2.1 | 290 | 330 |
| Green | 2.2 | 280 | 330 |
| Blue | 3 | 200 | 220 |
| White | 3.1 | 190 | 220 |
Precautions
- Never connect an LED to a pin without a resistor.
- Keep each pin's current below 20 mA.
My readings
Type what you measured. It goes into your record book, and to My Garage when you are signed in.
| S. No. | LED colour | Vf (V) | R needed (Ω) | Nearest standard (Ω) |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 |
Check my readings
Put the value you set in the first column, then compare. Real parts have tolerance.
Your lab record
Everything above is free. The print-ready write-up comes with Maker.
Printed pages leave the observation table empty for your own readings.
Viva practice
Say your answer out loud first, then check. The first 2 answers are free; Maker opens all 4.
Quick answers for your record and viva
What is the aim of the microcontroller gpio: led and push button experiment?
To control an LED from a microcontroller output and read a push button on an input with a pull-up.
What apparatus is needed for microcontroller gpio: led and push button?
Arduino Uno (or any microcontroller board), LED and 220 Ω resistor, Push button, Breadboard.
What is the theory behind microcontroller gpio: led and push button?
A GPIO pin set as output drives the LED through a current-limiting resistor: R = (Vpin − Vf) / I. A pin set as input with the internal pull-up reads HIGH when the button is open and LOW when it connects the pin to ground. Mechanical buttons bounce for a few milliseconds, so the code must debounce them.
What result should I get in microcontroller gpio: led and push button?
The LED is controlled from D9 and the button on D2 toggles it once per press. LED current = ___ mA.
What precautions should I take in microcontroller gpio: led and push button?
Never connect an LED to a pin without a resistor. Keep each pin's current below 20 mA.
