← Back

This preview is the content that will print. Choose “Save as PDF” in your browser’s print dialog to make a PDF.

Metatransformer report

Microcontrollers and GPIO boundaries

Practice · 60 minutes · Configure digital pins deliberately and choose pull resistors and interface circuitry that prevent floating inputs or overloaded outputs.

Text report: images and diagrams are omitted, and links to project files are inactive. Keep the exported project alongside this PDF for wiring diagrams, models, and linked files.

Learning outcomes

  • Wire and configure a low-voltage digital input/output, calculate its load current, and diagnose floating, inverted, and overcurrent-prone designs.

Prerequisites

  • programming-state
  • voltage-current-resistance
  • digital-interfaces

Concepts

A microcontroller is a small computer surrounded by pins that meet the physical world. A GPIO pin can often be configured as a digital input, push-pull output, or alternate peripheral function. Configuration matters: an output actively drives voltage, while an input mostly observes it. Treating a pin number as if it were only a software variable ignores current limits, voltage limits, and startup behavior.

Digital does not mean infinitely sharp. Input circuitry classifies a voltage below a specified low threshold as 0 and above a high threshold as 1; the middle region is not guaranteed. An unconnected input can drift through that region and change with a nearby hand. A pull-up resistor gives it a weak default high level, while a button to ground creates a strong low. With a 3.3 V supply and 10 kΩ pull-up, a pressed button draws I = V/R = 3.3/10,000 = 0.33 mA. Active-low logic then means pressed is read as 0, a convention the firmware should name rather than “fix” mysteriously.

Outputs source or sink only limited current. An LED needs a series resistor; motors, relays, and vacuum-blower motors require a driver stage and usually suppression, not a GPIO connection. For a status LED with about 2.0 V forward drop and a desired 4 mA from 3.3 V, R = (3.3 - 2.0)/0.004 = 325 Ω, so choosing the next common value 330 Ω is a conservative build decision.

A common misconception is that internal pull-ups are precise power resistors. They are weak bias elements with broad tolerance, useful for buttons but not for powering devices or defining fast signal edges. Other failures include configuring two connected push-pull outputs against each other, exceeding absolute voltage limits, or assuming boot-time pin state. Read the board and MCU pin documentation before attaching a load. The associated simulator models logic transitions only; it cannot validate pin current, thresholds, or protection.

Worked example

Problem

A 3.3 V GPIO drives a red LED with 2.0 V nominal drop. The target current is 5 mA, but available resistors are 220 Ω, 330 Ω, and 1 kΩ. Choose one and compute current.

Steps

  1. Ideal R = (3.3 V - 2.0 V) / 0.005 A = 260 Ω.
  2. With 220 Ω, estimated current is 1.3 V / 220 Ω = 5.9 mA; with 330 Ω it is 3.9 mA.
  3. Choose 330 Ω to stay below the 5 mA target. Separately check this controller's per-pin and bank current limits and guaranteed output voltage; there is no universal GPIO current rating.

Result

Use 330 Ω; the first-order LED current estimate is about 3.9 mA.

Sanity check

The resistor drops about 1.3 V, and 1.3 V / 330 Ω ≈ 0.0039 A. Actual current varies with LED forward voltage and output resistance.

Check your understanding

A button input reads HIGH when untouched and LOW when pressed using an internal pull-up. Why is the untouched reading stable?

A. The input pin generates a random HIGH whenever open B. The pull-up weakly connects the input to the logic supply while the button provides a lower-resistance path to ground when pressed C. The button stores charge like a battery D. The software delay forces the electrical voltage HIGH

Your answer: ______________________________

Reasoning:



Answer key

ANSWER KEY — check only after attempting the question.

B. The pull-up weakly connects the input to the logic supply while the button provides a lower-resistance path to ground when pressed

The pull-up establishes a defined electrical default; pressing the button overrides it with a ground path. An open input without bias is not guaranteed HIGH. A mechanical button does not store the logic level, and a delay can filter time behavior but cannot create a missing voltage bias.

Hands-on lab

Goal

Wire an active-low button and resistor-limited LED, then distinguish wiring, configuration, and logic faults.

Equipment

  • 3.3 V microcontroller board
  • momentary button
  • 330 Ω resistor
  • LED
  • breadboard and jumpers
  • multimeter

Procedure

  1. With USB disconnected, wire the LED and 330 Ω resistor in series from a GPIO to ground; verify no short with continuity mode.
  2. Wire the button from a second GPIO to ground and enable that pin’s internal pull-up.
  3. Print the raw button level and set the LED on only when the input is LOW.
  4. Measure LED resistor voltage while on and calculate current rather than claiming the target value was achieved.
  5. Introduce a deliberate safe fault by disabling the pull-up while leaving the input otherwise open; observe instability, then restore the pull-up.

What to observe

  • Expected: untouched input is HIGH, pressed input is LOW, and the LED follows the named pressed condition.
  • Record actual resistor voltage and calculated current; expected current from nominal values is about 3.9 mA.
  • Expected fault signature: the unbiased input may change unpredictably or respond to touch; exact behavior is an actual observation, not guaranteed.

Transfer challenge

Design the logic and interface boundary for a toy-car bumper switch that must read safely at startup and stop a driver without powering the motor from GPIO.

Cautions

  • Disconnect power before rewiring; use only logic-level voltage and never attach a motor, appliance, or mains conductor directly to a GPIO.

Evidence record

Learner: ____________________ Date: ____________________

Evidence artifact or file: ____________________________________________

ItemRecord
Prediction or expected result
Actual observation or measurement
Conditions and tools used
Difference from expectation
Next decision or follow-up

Notes:




Sources and references

  1. MicroPython RP2 quick reference (opens in a new tab)
  2. MIT OpenCourseWare 6.002 Circuits and Electronics (opens in a new tab)