ESP32-S3 Lab · Day 4 of 30

Make input
control output

Today the board starts listening. You wire a push button to one pin and a LED to another, then upload a sketch that watches the button and lights the LED whenever it's pressed — the smallest complete loop of sense, decide, and act. The wiring hides the real lesson: a resistor whose only job is to give the input pin a steady reading to start from.

About 25 minutesArduino firstMicroPython optionalNo electronics assumed
Agent assist code TSK-DAY04-BUTTON

Hand this to an agent so it can pull the lesson packet and coach you step by step.

01 First, know the pieces

What you need

Eight things, most of them tiny. Tap Define on any part you haven't met — the answer opens as a field note you can read and dismiss without losing your place.

Official manual photo of the ESP32-S3 development board.
Manual photo

ESP32-S3 board

The brain that runs your uploaded sketch.

Official manual image of the ESP32-S3 GPIO extension board.
Manual photo

GPIO extension board

Spreads the pins into rows you can reach and label.

Official manual photo of a red LED with its longer positive leg and shorter negative leg labelled.
Manual photo

LED

The light you'll switch — it only works one way round.

Official manual photo of a resistor with coloured value bands.
Manual photo

220 Ω resistor

Sits in series with the LED to keep the current gentle.

Official manual photo of a resistor with coloured value bands.
Manual photo

2 × 10 kΩ resistors

Hold the button's pin at a steady level until you press.

Official manual photo of a four-pin push button switch with its pin pairs labelled 1 and 2.
Manual photo

Push button

A four-pin switch that closes the circuit when pressed.

Official manual image of a jumper wire.
Manual photo

Jumper wires

Temporary, solder-free connections.

Official manual screenshot of the Arduino IDE interface.
Manual screenshot

Arduino IDE

Uploads the sketch to the board.

02 Make the physical circuit

Chart the circuit

The official Freenove diagram is your chart — schematic on top, the same circuit built on a breadboard below. Click it to enlarge. Each connection tells you where the wire goes and why.

Official Freenove circuit — C Tutorial, Chapter 2 (Button & LED), page 48.
LED long leg (+) GPIO 2 via 220 Ω This pin switches the LED on and off.
LED short leg (−) GND Completes the LED's path back to zero volts.
Push button GPIO 13 The board reads this pin to feel each press.
10 kΩ resistor 3.3V Holds GPIO 13 HIGH until a press pulls it LOW.

Mind the LED's legs. The LED only lights one way round — long leg toward GPIO 2 through the 220 Ω resistor, short leg to ground. Unplug USB before you move any wire.

03 One action at a time

Build it

This is the main path — you can finish the day without opening a single field note. Tap each step as you go to keep your place.

0 / 8 done
  1. Seat the ESP32-S3 on the GPIO extension board and keep USB unplugged while you wire.

  2. Place the LED so its long leg (+) is on the GPIO 2 side and its short leg (−) heads toward ground.

  3. Put the 220 Ω resistor in series between GPIO 2 and the LED's long leg.

  4. Wire the push button so one side reaches GPIO 13 and the other reaches ground.

  5. Add the 10 kΩ resistor that holds GPIO 13 steady until the button is pressed.

  6. Compare every wire to the chart before you plug in USB.

  7. Open Sketch_02.1_ButtonAndLed.ino in Arduino IDE and upload it.

  8. Press the button and watch the LED.

Input meets output.

The board is now reacting to you, not to a timer. Head to Test & debug to confirm the press-and-light behaviour.

04 Read just enough code

Read the code

The whole sketch is short. Two lines set the pins up; the loop just asks the button and answers with the LED. Switch to MicroPython if you'd rather see the same idea in Python — the wiring never changes.

Sketch_02.1_ButtonAndLed.ino
#define PIN_LED    2
#define PIN_BUTTON 13

void setup() {
  pinMode(PIN_LED, OUTPUT);
  pinMode(PIN_BUTTON, INPUT);
}

void loop() {
  if (digitalRead(PIN_BUTTON) == LOW) {
    digitalWrite(PIN_LED, HIGH);   // pressed -> on
  } else {
    digitalWrite(PIN_LED, LOW);    // released -> off
  }
}
pinMode(PIN_BUTTON, INPUT)Sets GPIO 13 as an input so the board can read the button.
digitalRead(PIN_BUTTON) == LOWTrue only while the button is held — a press pulls the pin LOW.
digitalWrite(PIN_LED, HIGH)Lights the LED; the else branch turns it off again.

05 Understand, don't memorise

How the board reads a button

Driving the LED is the easy half — the board pushes voltage out of a pin. Reading the button is the subtle half, because an input pin is a listener, and a listener with nothing wired to it invents noise. One resistor fixes that, and understanding why is the real lesson of your first wiring day.

1 · Listen

An input pin

pinMode INPUT turns GPIO 13 into a high-impedance listener. It senses the pin's voltage — near 3.3V reads HIGH, near 0V reads LOW — while drawing almost no current itself, which is exactly what makes it easy to sway.

2 · The catch

A floating pin

With nothing holding it, that sensitive input picks up ambient electrical noise from the wiring and even your body, and its reading drifts between HIGH and LOW at random. A pin left floating cannot be trusted.

3 · The anchor

A pull resistor

The 10 kΩ resistor ties GPIO 13 up to 3.3V, giving it a steady resting HIGH. The resistor is weak enough that a solid connection elsewhere can still overrule it, which is the whole trick.

4 · The press

Override to LOW

Pressing connects the pin straight to ground through a near-zero-resistance path. That solid path wins over the gentle pull-up, so the pin snaps to LOW — and the sketch reads the change on its very next pass.

The loop sense (digitalRead) → decide (if) → act (digitalWrite) → repeat

Why a press reads LOW

The pull-up holds GPIO 13 at 3.3V, so at rest it reads HIGH. A press connects the pin to ground and it reads LOW, which is why the sketch checks for LOW. This backwards-feeling wiring is common in real circuits, so it's worth meeting early.

The pull-up the chip already has

This circuit wires its own 10 kΩ pull-up and reads the pin with plain INPUT. Every ESP32-S3 input pin also carries a pull-up resistor built into the chip; INPUT_PULLUP switches that one on so you can skip the external part. The MicroPython version does precisely this with Pin.PULL_UP.

06 Know it worked

Test & debug

Nothing prints to the screen today — the proof is the LED under your finger.

What you should see
LED
  • Press and hold the button — the LED lights immediately.
  • Let go — the LED goes dark.
  • It follows your finger with no delay for as long as the board has power.

This press is momentary — the LED only stays on while you hold it. Tomorrow's lamp will make it latch.

If it doesn't
  • LED never lights? Check the LED's direction and the 220 Ω resistor, then the GPIO 2 wire.
  • LED always on? The button or its 10 kΩ resistor is likely miswired on GPIO 13.
  • Nothing responds? Re-check the shared ground, then that the sketch uploaded.
  • Upload fails? Swap in a data-capable USB cable.

07 Make the idea yours

Try this: make the pin float

The pull resistor is invisible while it works. The way to see what it does is to take it out for a minute and watch the input pin lose its footing, then put it back and watch the reading settle. It fits inside today's session.

Take the anchor away

With USB unplugged, remove the 10 kΩ resistor that ties GPIO 13 to 3.3V, so nothing holds the pin. Reconnect USB and run the same sketch. The LED loses its footing — it flickers, drifts, or reacts when your hand comes near the wire — because the floating pin is reading ambient noise with no resting level to hold.

Put it back

Unplug USB, wire the 10 kΩ resistor back to 3.3V, then reconnect. The LED goes rock steady — dark at rest, lit only while you press. That steadiness is the resistor's whole job, and INPUT_PULLUP would earn the same result from inside the chip.

08 Learn it with a hand on the tiller

Coach me through it

Every lesson ships with a code and a machine-readable packet, so an agent can guide you with full context.

Lesson code

TSK-DAY04-BUTTON

How the agent should behave: guide one physical connection at a time, wait for you to confirm, explain terms on request, and always check wiring, board, port, and USB before changing code. Once the circuit works, use the floating-pin experiment to make the pull resistor's job real.

Keep your place

Finished Day 4?

Mark it complete — it shows on your course map, and your place is saved on this device.

Field note

Shortcut

Prompt copied