TinySkiff 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.

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

Sense, decide, act

There's no trick here — just three moves the board makes over and over, faster than you can see.

Sense

Button in

digitalRead checks GPIO 13 many times a second.

Decide

if / else

LOW means pressed so the board chooses to light up.

Act

LED out

digitalWrite pushes the pin HIGH and the LED turns on.

Repeat

loop()

The whole check runs again at once and forever.

The model input (button) → decision (code) → output (LED)

Why a press reads LOW

In this wiring a press pulls GPIO 13 toward ground, so the sketch checks for LOW on purpose.

What the 10 kΩ resistor is for

Without it the input pin would float and read at random. The resistor gives it a steady resting value.

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: predict before you press

Same working circuit, one new habit: predicting a result before you test it. It fits inside today's 30 minutes.

Predict first

Before each press, say out loud whether the LED is on or off. Then press and check whether you were right.

Reason about the resistor

Picture removing the 10 kΩ resistor. Predict what GPIO 13 would read with nothing holding it, and why that would be a problem.

Logbook

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.

Field note

Shortcut

Prompt copied