XL LED/Making it light/03. The first blink
Making it light · 03 of 9

The first blink

Two wires, no library and a five-line sketch. On a 5 V board it is bright; on a 3.3 V board it is dimmer but plainly lit, and both are right.

Two wires

Two wires
Your board
Wires
2
SIGNAL to
GPIO 4
Logic
3.3 V
GND to GND, SIGNAL to GPIO 4. There is no supply pin to connect: the pin you drive powers the LED. On a 3.3 V board it will be clearly lit but noticeably dimmer than on an Uno, and chapter 3 says exactly why.

GND to GND. SIGNAL to a digital pin. The two NC pins stay unconnected, because nothing on the board is attached to them.

The pin in the sketch is a PWM pin on every board listed: D9 on an Uno, GPIO 4 on an ESP32 or ESP32-S3, GP15 on a Pico. Any digital pin will blink the LED. Starting on a PWM pin means the same wiring also works for the brightness sketches in chapter 3.

If your block came with a TinkerBlock cable, it carries all four pins, and the two NC wires simply end at pins that go nowhere.

The sketch

Three calls do all the work. pinMode(LED_PIN, OUTPUT) makes the pin an output. digitalWrite(LED_PIN, HIGH) puts the board's logic voltage on it, and the LED lights. digitalWrite(LED_PIN, LOW) puts 0 V on it, and the LED goes out.

delay(500) waits half a second each time, so the LED is on for half a second and off for half a second: one blink per second. delay stops the whole sketch while it waits, which is fine here and a problem later. Blinking without stopping is about that.

What you should see

The LED blinks once a second and the serial monitor at 115200 prints:

on
off
on
off

On an Uno it is bright, about 13 mA. On an ESP32, an ESP32-S3 or a Pico it is clearly dimmer, about 2 mA, and nothing is wrong. The LED needs about 3 V before it conducts, and a 3.3 V pin leaves very little on top of that for the resistor. Why it is dimmer on 3.3 V works that out.

If it does not light at all, go to when it stays dark.

The code

No library. pinMode makes the pin an output, and digitalWrite sets it HIGH or LOW. Change LED_PIN to the pin you wired SIGNAL to.

xl_led_first_blink.ino
/*
  XL LED - first blink                                   TK01 / /p/tk01

  Wiring. Count from the square pad on the TinkerBlock board, LED side
  up, header at the bottom:

    GND    -> GND
    NC     -> nothing   (both NC pins are unconnected on the board)
    SIGNAL -> D9 on an Uno, GPIO 4 on an ESP32 or ESP32-S3,
              GP15 on a Raspberry Pi Pico

  Arduino IDE
    Tools > Board                 your board, e.g. ESP32S3 Dev Module
    Tools > Port                  the one that appears when you plug in
    Tools > USB CDC On Boot       Enabled   (ESP32-S3 only)
    No library needed.
*/

// The GPIO number SIGNAL is wired to. Uno: 9. ESP32, ESP32-S3: 4. Pico: 15.
const int LED_PIN = 4;

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);     // without this, HIGH is only a weak pull-up
}

void loop() {
  digitalWrite(LED_PIN, HIGH);  // the pin supplies the LED's current
  Serial.println("on");
  delay(500);

  digitalWrite(LED_PIN, LOW);   // 0 V on the anode, nothing flows
  Serial.println("off");
  delay(500);
}

LED_PIN is the number your board prints beside the pin: 9 is D9 on an Uno, 4 is GPIO 4 on an ESP32. pinMode is not optional. Leave it out and, on an Uno, digitalWrite(HIGH) only switches on the pin's weak internal pull-up, which lights the LED so faintly you may not see it.

When it does not work

It compiled and uploaded, and the LED does nothing.

Check that SIGNAL is on the pin named in LED_PIN. The number is the board's own GPIO number as printed beside the pin, not the pin's position counted along the header. Then check GND is connected: without it there is no loop and no current.

The serial monitor stays empty on my ESP32-S3.

Set Tools > USB CDC On Boot to Enabled and upload again. Without it the S3's USB port does not bring up a serial port at boot, so the sketch runs with nowhere to print. The LED blinking tells you the sketch itself is fine.

Can I use pin 13 on the Uno?

Yes, and the Uno's own L LED will blink with it. The sketch uses pin 9 because it is a PWM pin, so the same wiring works for the brightness sketches in chapter 3. Pin 13 is not a PWM pin on an Uno.

It blinks, but faster or slower than once a second.

Check both delay values. Each one is in milliseconds, so delay(500) is half a second on and half a second off, one full blink per second. If it blinks at the right speed but looks uneven, that is the board: an ESP32 prints over USB while it waits, the Uno does not.

Where this goes next

What HIGH actually does to the loop, and why the board says ACTIVE HIGH.

Where the current goes

Edit this page — content/books/xl-led/the-first-blink.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

XL LED

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum