Lab / Microcontrollers and sensors

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.

Microcontrollers and sensorsVirtual readings4 viva questions
I = 13 mA

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 ready
1Why INPUT_PULLUP?
2What is switch bounce?
3What is the maximum current per Uno pin?
4Difference between a microprocessor and a microcontroller?

Try the readings before the lab

Calculated, not measured. In the lab, write down your own readings.
LED colourVf (V)R needed (Ω)Nearest standard (Ω)
Red2300330
Yellow2.1290330
Green2.2280330
Blue3200220
White3.1190220

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 colourVf (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.

Open my record book

Your lab record

Result formatThe LED is controlled from D9 and the button on D2 toggles it once per press. LED current = ___ mA.

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.

1. Why INPUT_PULLUP?
2. What is switch bounce?
3. What is the maximum current per Uno pin?
4. Difference between a microprocessor and a microcontroller?

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.

Microcontroller GPIO: LED and push button: lab experiment