Blink on Arduino Uno
Steps done: 0 of 5
Guess the answer and press Run
D8, on0 %time, s0.0
Lesson steps
How many flashes per second?
Read the sketch and pick an answer before you run it.
Sketch
// D8 -> 220 Ω resistor -> LED -> GND
const int led = 8;
int onMs = 500; // on, ms
int offMs = 500; // off, ms
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("Мигалка на D8");
}
void loop() {
digitalWrite(led, HIGH);
delay(onMs);
digitalWrite(led, LOW);
delay(offMs);
}
Tap a line or an orange number
Serial monitor
Serial, 9600 baudboard time 0.0 s
About the lesson
The first breadboard circuit: pin D8, a 220 Ω resistor and an LED. The sketch runs in an ATmega328P emulator on this page, the flash and pause times change on the fly. About 10 minutes, no sign-up. Five steps: guess, run, read the code, change the numbers and do a task with a check.
Build it for real
Parts
- Arduino Uno R3
- Mini breadboard
- 5 mm LED
- 220 Ω resistor
- 2 male-to-male jumper wires
Wires
| From | To |
|---|---|
| D8 | 220 Ω resistor |
| Resistor | long LED leg |
| Short LED leg | GND |
You can also put the resistor on the cathode side, the current is the same. Any value from 220 to 470 Ω works: with 470 Ω the LED is dimmer.
Open the schematic in the builderPinout of the lesson boardLED pinout
The sketch below goes to the board with the default numbers: onMs 500, offMs 500. The numbers you changed in the lesson are passed to the flasher by the To the board link above the code.
The whole sketch
// D8 -> 220 Ω resistor -> LED -> GND
const int led = 8;
int onMs = 500; // on, ms
int offMs = 500; // off, ms
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("Мигалка на D8");
}
void loop() {
digitalWrite(led, HIGH);
delay(onMs);
digitalWrite(led, LOW);
delay(offMs);
}
What to keep in mind on a real board
On a new LED the anode is longer than the cathode. If the legs are trimmed, find the cathode by the flat edge on the rim of the bulb.
Breadboard holes in one column a-e are connected to each other, and so are f-j. The channel in the middle separates them.
The sketch takes 2048 bytes of flash and 214 bytes of RAM.
Licenses of the lesson code
The avr8js 0.21.1 emulator, © 2019-2025 Uri Shaked, MIT license. The CodeMirror 6 editor, © Marijn Haverbeke and contributors, MIT license. The three.js scene, © three.js authors, MIT license.
The lesson firmware is built with the Arduino AVR core (LGPL 2.1), sources: ArduinoCore-avr. The lesson sketch and scene are made for this site.
MIT license text: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.