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
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
offOn 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 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.
The same blink in MicroPython, for an ESP32, an ESP32-S3 or a Pico. Pin.OUT makes the pin an output, and value(1) and value(0) set it HIGH and LOW.
"""
XL LED - first blink, MicroPython 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 -> GPIO 4 on an ESP32 or ESP32-S3, GP15 on a Raspberry Pi Pico
Thonny
Run > Configure interpreter MicroPython (ESP32) or
MicroPython (Raspberry Pi Pico)
Save it to the board as main.py to run it on every power-up.
Nothing to install: machine and time are built in.
"""
from machine import Pin
import time
# The GPIO number SIGNAL is wired to. ESP32, ESP32-S3: 4. Pico: 15.
LED_PIN = 4
led = Pin(LED_PIN, Pin.OUT) # an output, like pinMode(OUTPUT)
while True:
led.value(1) # the pin supplies the LED's current
print("on")
time.sleep_ms(500)
led.value(0) # 0 V on the anode, nothing flows
print("off")
time.sleep_ms(500)There is no Uno here: an Uno cannot run MicroPython. The pin number is the GPIO number, as in the Arduino sketch. Stop it with Ctrl-C in Thonny's shell, and the LED stays in whatever state it was in.
When it does not work
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.
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.
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.
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.
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
Questions about this product
See what other owners have asked, and read their solutions.
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.