Lab: blink the XL LED
The XL LED in the D2/D3 socket, and a sketch that holds D2 HIGH for a second, then D3. The LED lights only on D3, the socket's second printed pin, which is the shield's one rule seen working; the light that comes and goes is the blink.
The first module on the shield. The LED itself, its resistor and its first
blink are on the XL LED's own page;
pinMode and digitalWrite are in the ATmega328P book's
digital output. This lab is about the socket.
Where it plugs in
| Module | Socket | Pin |
|---|---|---|
| TK01 XL LED | D2/D3 | D3 |
Unplug the USB cable, plug the LED's cable into the socket printed D2/D3 and into the module, then plug the USB cable back in.
Two pins, one LED
The socket carries two UNO pins, D2 and D3, and the LED needs one. Which one it gets is fixed by the cable: the fourth wire is the LED's SIGNAL, and the socket's fourth pin is D3, the second of the two printed beside it. D2 goes to an NC pin that nothing on the LED is wired to.
Pick the pin the sketch holds HIGH. D3 puts 5 V on the LED's anode, and about 13 mA flows through it and its 150 Ω resistor. D2 puts 5 V on a pin that leads nowhere, and the LED stays dark with the sketch doing exactly what it says. Change the socket and the same holds: the second pin lights it.
The sketch
Rather than assume the rule, the sketch tests it. It makes both of the socket's pins outputs and holds each HIGH for a second in turn:
SOCKET_PINS[] = {2, 3}names the two pins printed beside the socket, in the order they are printed.- The loop prints
D2 is HIGH, holds D2 forSTEP_MS, lets it go, then does the same for D3.
Open the Serial Monitor at 115200 baud and watch it beside the LED. The LED
is dark through every D2 is HIGH and lit through every D3 is HIGH: on for
a second, off for a second, which is a blink.
Make it yours
- Try every digital socket. Move the LED, with the USB cable out, to
D4/D5, D6/D7, D8/D9 or D10/D11 and change
SOCKET_PINSto match. It always lights on the second. - Change the rhythm. Give D3 its own time:
delay(pin == 3 ? 200 : 800)in place ofdelay(STEP_MS)is a short flash every second. - Leave D2 out, and see where the dark went. With
{3}andCOUNTset to 1 the LED stays lit: D3 goes LOW and straight back HIGH, because the dark second was D2's turn. Adelay(STEP_MS)after thedigitalWrite(pin, LOW)brings it back, and that is the plain blink on D3 every later lab starts from.
The code
Both pins of the D2/D3 socket are outputs. The loop holds each one HIGH for a second in turn and prints its name, so the Serial Monitor says which pin is HIGH while the LED shows which one it is on.
/*
Which pin is the XL LED on? TinkerBlock UNO kit / tkbu
Holds each pin of one socket HIGH for a second in turn and says
which in the Serial Monitor. The LED lights on only one of them:
the second pin printed beside the socket. That is the blink.
Wiring: the TinkerBlock UNO shield on the UNO R3, and the TK01
XL LED in the D2/D3 socket, so it is on D3. D2 reaches one of
the LED's NC pins, which go nowhere on the board.
Arduino IDE
Tools > Board: Arduino Uno
Tools > Port: the CH340 port (it vanishes when you unplug)
Serial Monitor at 115200 baud. No library needed.
*/
const int SOCKET_PINS[] = {2, 3}; // printed beside the socket
const int COUNT = 2;
const unsigned long STEP_MS = 1000;
void setup() {
Serial.begin(115200);
for (int i = 0; i < COUNT; i++) {
pinMode(SOCKET_PINS[i], OUTPUT);
}
}
void loop() {
for (int i = 0; i < COUNT; i++) {
int pin = SOCKET_PINS[i];
Serial.print("D");
Serial.print(pin);
Serial.println(" is HIGH");
digitalWrite(pin, HIGH); // lights the LED only on D3
delay(STEP_MS);
digitalWrite(pin, LOW);
}
}SOCKET_PINS is the only line that knows the socket. Move the LED to the D4/D5 socket, change it to {4, 5}, and it lights on D5. STEP_MS sets the pace; under about 50 ms the blink blurs into a steady glow.
View on GitHub · kits/tkbu/blink-on-d3/Which_Pin/Which_Pin.ino @ v1.14When it does not work
Check the PWR lamp on the shield first. Lit, the sockets have 5 V and the fault is the cable or the socket: unplug the USB cable, push the cable fully home at both ends until it latches, and check the LED is in the socket printed D2/D3. Dark, read the shield article's power section.
The LED's off time is D2's turn in the loop. If SOCKET_PINS was cut down to {3}, D3 goes LOW and straight back HIGH, too fast to see. Put D2 back, or add a delay(STEP_MS) after the digitalWrite(pin, LOW). If the sketch is unchanged, it may not have uploaded: check the IDE's output for Done uploading.
Set the Serial Monitor's baud menu to 115200, the number in Serial.begin. The LED blinks whether or not the monitor is open; opening it restarts the sketch, which is the UNO's auto-reset and not a fault.
Yes. D2 reaches one of the XL LED's NC pins, which is connected to nothing on the module, so no current flows however long the pin is HIGH.
The push button joins the LED: every press counts, and steps the LED's brightness.
Lab: count the presses →Edit this page — content/books/tkbu/blink-on-d3.mdx
Questions about this product
See what other owners have asked, and read their solutions.
TinkerBlock UNO R3 Starter Kit, 12 Modules
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.