TinySkiff ESP32-S3 Lab · Day 7 of 30

Make a light
learn to breathe

Today the LED stops snapping. You keep yesterday's single-LED circuit, upload a sketch that sweeps the pin's brightness up and then down, and the light fades in and out like a slow breath — the board's first move beyond plain on and off.

About 20 minutesArduino firstMicroPython optionalSame LED circuit as Blink
Agent assist code TSK-DAY07-BREATHE

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

Five things, all of them familiar from Blink. 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 fade — 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 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. This is the same single-LED circuit you built for Blink, so if it's still wired you're ready.

Official Freenove circuit — C Tutorial, Chapter 4 (Analog & PWM), page 62.
LED long leg (+) GPIO 2 via 220 Ω This pin fades the LED with PWM.
LED short leg (−) GND Completes the LED's path back to zero volts.

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 / 6 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. Compare every wire to the chart before you plug in USB.

  5. Open Sketch_04.1_BreathingLight.ino in Arduino IDE and upload it.

  6. Watch the LED fade up and down, over and over.

The pin can fade now.

The LED is sliding through every brightness in between. Head to Test & debug to confirm the breathing.

04 Read just enough code

Read the code

The whole sketch is short. A few lines set up a hardware PWM channel on the pin; two loops sweep its brightness up and then back down. Switch to MicroPython if you'd rather see the same idea in Python — the wiring never changes.

Sketch_04.1_BreathingLight.ino
#define PIN_LED  2
#define CHN      0        // PWM channel
#define FRQ      1000     // switching frequency, Hz
#define PWM_BIT  8        // resolution: 0-255

void setup() {
  ledcAttachChannel(PIN_LED, FRQ, PWM_BIT, CHN);
}

void loop() {
  for (int i = 0; i < 255; i++) {   // fade in
    ledcWrite(PIN_LED, i);
    delay(10);
  }
  for (int i = 255; i > -1; i--) {  // fade out
    ledcWrite(PIN_LED, i);
    delay(10);
  }
}
ledcAttachChannel(PIN_LED, FRQ, PWM_BIT, CHN)Attaches GPIO 2 to a hardware PWM channel so the board can switch it fast on its own.
ledcWrite(PIN_LED, i)Sets the brightness from 0 (dark) to 255 (full) by changing how much of each instant the pin is on.
for (int i = 0; i < 255; i++)The first loop sweeps brightness up and the second sweeps it back down; delay(10) sets how fast each step passes.

05 Understand, don't memorise

Dimming by switching fast

There's no half-voltage trick here — just a pin flipping faster than you can see, held on for a bigger or smaller share of each moment.

Only two states

On or off

The pin itself can only be fully on or fully off.

Switch fast

1000 times a second

PWM flips it far quicker than your eye can follow.

Hold longer

More on-time

The more of each instant the pin stays on the brighter it looks.

Sweep it

Up then down

Sliding that share from none to all and back is the breath.

The model brightness = duty cycle = the share of each instant the pin is on

What PWM actually does

Pulse-width modulation switches the pin on and off so fast that your eye blends the flicker into a steady, dimmable glow.

Why a channel

The ESP32-S3 has dedicated PWM hardware that keeps switching the pin on its own, so the sketch only has to set a brightness and move on.

06 Know it worked

Test & debug

Nothing prints to the screen today — the proof is the LED fading in front of you.

What you should see
LED
  • The LED brightens smoothly from dark up to full.
  • Then it dims smoothly back down to dark.
  • It repeats, over and over, like slow breathing.

The change should be a smooth slide, never a hard on/off snap. If it snaps, you're likely still running the Blink sketch.

If it doesn't
  • LED just blinks hard on and off? You may be on the Blink sketch — re-upload Sketch_04.1_BreathingLight.
  • LED stays dim or dark? Check the 220 Ω resistor and the GPIO 2 wire, then the LED's direction.
  • Upload fails? Swap in a data-capable USB cable.

07 Make the idea yours

Try this: find a calm breath

Same working circuit, one number to play with: the fade speed. It fits inside today's 20 minutes.

Slow the breath

Change both delay(10) lines together — try 5 for a quick breath, 20 for a slow one — and upload until the fade feels like a resting breath.

Hold at the top

Add a short delay(300) between the fade-in and fade-out loops so the light pauses at full brightness before it sinks again.

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-DAY07-BREATHE

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