The first light
Four wires, no library, and a sketch that shows the warm white, the cool white, the two together and then off, two seconds each. VCC goes to 5V (VBUS on a Pico); 3000K and 6500K to GPIO 4 and 5 on an ESP32-S3, 25 and 26 on an ESP32, D9 and D10 on an Uno, GP14 and GP15 on a Pico.
Four wires
GND to GND. VCC to 5V, or VBUS on a Pico: it only feeds the LEDs, so 5 V is safe on a 3.3 V board, and it comes from USB rather than from your board's 3.3 V regulator. The two colours to two PWM pins. On an ESP32 or a Pico every GPIO can do PWM; on an Uno only six can.
None of the pins is a strapping pin. That matters in an unusual direction here: each colour pin sits on 1 kΩ and a transistor's base, which holds the pin under a volt whenever something tries to pull it up.
The sketch
pinMode and digitalWrite(pin, LOW) for both pins first, because nothing
on the board holds the transistors off. After that the sketch only uses
analogWrite: on the ESP32's Arduino core 3.x a digitalWrite after an
analogWrite on the same pin is ignored, so mixing the two is a trap.
MAX_DUTY is 170 of 255, the cap for VCC on 5V from five volts is the
limit. With
VCC on 3V3 you can raise it to 255.
What you should see
At 115200 the serial monitor prints warm: 3000K, cool: 6500K, both, half each: about 4100 K and off, two seconds apart. The upper LED lights
yellowish white, then the lower one bluish white, then both, and the light
on the wall is a white between the two.
Do not look into them from close up. The back of the board says it in capitals, and it means it.
The code
No library. analogWrite sets each colour's duty: warm alone, cool alone, half of each, then off, two seconds apart, with a line to the serial monitor each time. Change WARM_PIN and COOL_PIN to the pins you wired.
/*
Dual Bright LEDs - the first light TK95 / /p/tk95
Wiring. Count from the square pad on the TinkerBlock board, parts
up, header at the bottom:
GND -> GND
VCC -> 5V (VBUS on a Pico). It only feeds the LEDs, so 5V is
safe on a 3.3 V board. Never the Uno's 3.3V pin.
3000K -> D9, GPIO 25, GPIO 4 or GP14 (a PWM pin)
6500K -> D10, GPIO 26, GPIO 5 or GP15 (a PWM pin)
Uno, ESP32, ESP32-S3, Pico, in that order.
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.
Serial Monitor 115200
Do not look into the LEDs from close up.
*/
// The pins 3000K and 6500K are wired to.
// Uno: 9. ESP32: 25. ESP32-S3: 4. Pico: 14.
const int WARM_PIN = 4;
// Uno: 10. ESP32: 26. ESP32-S3: 5. Pico: 15.
const int COOL_PIN = 5;
// With VCC on 5V an LED held fully on runs past its rating, so the
// sketch stops at two thirds. With VCC on 3V3, 255 is fine.
const int MAX_DUTY = 170;
void show(int warm, int cool, const char *what) {
analogWrite(WARM_PIN, warm);
analogWrite(COOL_PIN, cool);
Serial.println(what);
delay(2000);
}
void setup() {
// LOW first: nothing on the board holds the transistors off.
pinMode(WARM_PIN, OUTPUT);
digitalWrite(WARM_PIN, LOW);
pinMode(COOL_PIN, OUTPUT);
digitalWrite(COOL_PIN, LOW);
Serial.begin(115200);
}
void loop() {
show(MAX_DUTY, 0, "warm: 3000K");
show(0, MAX_DUTY, "cool: 6500K");
show(MAX_DUTY / 2, MAX_DUTY / 2, "both, half each: about 4100 K");
show(0, 0, "off");
}setup() drives both pins LOW before anything else, because nothing on the board holds the transistors off. MAX_DUTY is 170, the cap for VCC on 5V. The sketch compiles for an ESP32-S3, an ESP32 and an Uno.
View on GitHub · blocks/tk95-dual-bright-leds/arduino/dual_leds_first_light/dual_leds_first_light.ino @ v1.8The same in MicroPython: both pins LOW first, then a PWM at 1 kHz on each and duty_u16 from 0 to 65535. No library to install.
"""
Dual Bright LEDs - the first light, MicroPython TK95 / /p/tk95
Wiring. Count from the square pad on the TinkerBlock board, parts
up, header at the bottom:
GND -> GND
VCC -> 5V (VBUS on a Pico). It only feeds the LEDs.
3000K -> GPIO 25 on an ESP32, GPIO 4 on an ESP32-S3, GP14 on a Pico
6500K -> GPIO 26 on an ESP32, GPIO 5 on an ESP32-S3, GP15 on a Pico
Thonny
Run > Configure interpreter MicroPython (ESP32) or
MicroPython (Raspberry Pi Pico)
Do not look into the LEDs from close up.
"""
import time
from machine import Pin, PWM
# GPIO numbers. ESP32: 25 and 26. ESP32-S3: 4 and 5. Pico: 14 and 15.
WARM_PIN = 4
COOL_PIN = 5
# Two thirds of full: with VCC on 5V an LED held fully on runs past
# its rating. With VCC on 3V3, 65535 is fine.
MAX_DUTY = 43690
# LOW first: nothing on the board holds the transistors off.
Pin(WARM_PIN, Pin.OUT, value=0)
Pin(COOL_PIN, Pin.OUT, value=0)
warm = PWM(Pin(WARM_PIN))
cool = PWM(Pin(COOL_PIN))
for led in (warm, cool):
led.freq(1000)
led.duty_u16(0)
def show(w, c, what):
warm.duty_u16(w)
cool.duty_u16(c)
print(what)
time.sleep(2)
while True:
show(MAX_DUTY, 0, "warm: 3000K")
show(0, MAX_DUTY, "cool: 6500K")
show(MAX_DUTY // 2, MAX_DUTY // 2, "both, half each: about 4100 K")
show(0, 0, "off")The pin numbers are GPIO numbers: 4 and 5 on an ESP32-S3, 25 and 26 on an ESP32, 14 and 15 on a Pico. MAX_DUTY is 43690, two thirds of 65535. Stop it with Ctrl-C; the LEDs stay as they were.
View on GitHub · blocks/tk95-dual-bright-leds/micropython/dual_leds_first_light.py @ v1.8When it does not work
Check VCC first: the pins only switch the transistors, and with VCC unwired there is nothing to switch. Then GND, then that the sketch's WARM_PIN and COOL_PIN are the GPIO numbers you wired, counting from the square pad.
Set Tools > USB CDC On Boot to Enabled and upload again. Without it the S3's USB port brings up no serial port at boot, so the sketch runs, and lights the LEDs, with nowhere to print.
That is the block working. Point it at a wall or the desk and look at what it lights. For a dimmer first light, lower MAX_DUTY in the sketch; 20 is plenty to see it is alive.
That pin has no PWM. On an Uno only D3, D5, D6, D9, D10 and D11 can dim; the book uses D9 and D10. An older lesson put the warm LED on D2, which only ever switches fully on or off.
What a duty cycle does to the current, and a fade that looks even.
Dimming with PWM →Edit this page — content/books/dual-bright-leds/the-first-light.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Dual Bright LEDs
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.