Your first upload: Blink
Blink turns the lamp on pin 13 on for a second and off for a second, for ever: L on the UNO, D13 on the Nano. Uploading it proves the whole chain works: the IDE, the driver, the cable, the CH340C, the reset, the bootloader and the chip.
Open Blink
The IDE comes with Blink: File > Examples > 01.Basics > Blink. It opens in a new window. The sketch on this page is the same program with its Tools rows written at the top; paste it in instead if you prefer.
Before uploading, check the two rows from board and port: Board Arduino Uno, Port the CH340's.
Verify, then Upload
Two buttons sit at the top left of the IDE. Verify, the tick, compiles the sketch and stops: it checks the program and needs no board at all. Upload, the arrow, compiles it and then sends it. The output pane at the bottom ends a good compile with two lines like these:
Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.The first is flash, the second is SRAM: the two memories from the first article. With Arduino Nano chosen, the first line says 3% of a maximum of 30720 bytes, because the Nano's settings keep 2 KB of flash for the bootloader. Your numbers may differ a little with a different version of the board package.
What happens when you press Upload
Press Upload in the figure and watch the order. The part you never see is the reset: opening the port makes the CH340C pulse its DTR pin, number 13 on that chip, and a 100 nF capacitor turns the pulse into a short dip on the ATmega328P's RESET. That is a press of the reset button, done for you.
After a reset, the bootloader runs before your sketch. It flashes L, then listens on pin 0 for about a second. avrdude, the uploader inside the IDE, is already sending: the new program goes down at 115200 baud, the bootloader answers every block, and it writes each one into flash. On the board you see RX and TX flicker together, because each lamp lights while its line is LOW, and a line carrying bytes drops LOW thousands of times a second.
When the last block is in, the bootloader starts the new sketch. The IDE says Done uploading. and L goes on and off once a second.
What this proves
A working Blink means every link works: the IDE has the board package, the computer has a driver, the cable carries data, the CH340C resets the chip, and the bootloader is there. From here on, a failed upload is a change you made, not the setup. If yours did not work, when the upload fails reads the message for you.
The sketch stays in flash. Unplug the board and plug it into a USB charger, and L blinks again: no computer needed.
The code
The IDE's own Blink, with the Tools rows written at the top. Paste it into a new sketch, or open File, Examples, 01.Basics, Blink: the two do the same thing.
// Blink_L_Lamp.ino — the pin-13 lamp on for a second, off for one
// Tools > Board: Arduino Uno, or Arduino Nano with
// Processor ATmega328P (Old Bootloader if the upload says
// "not in sync")
// Tools > Port: the CH340 port
// Wiring: none. The lamp on pin 13 is on the board: L on the
// Uno, D13 on the Nano.
const byte LAMP = LED_BUILTIN; // 13 on both boards
void setup() {
pinMode(LAMP, OUTPUT); // 13 drives, it does not listen
}
void loop() {
digitalWrite(LAMP, HIGH); // lamp on
delay(1000); // one second
digitalWrite(LAMP, LOW); // lamp off
delay(1000);
}LED_BUILTIN is 13 on both boards. On the UNO pin 13 drives the L lamp through a buffer; on the Nano it lights the D13 lamp directly, through 5.1 kΩ. Change both 1000s to 100 and upload again: the lamp blinks ten times faster, which proves the new sketch replaced the old one.
When it does not work
Look at the lamp on pin 13, marked L on the UNO (in the column left of centre) and D13 on the Nano, not at ON. If it really is dark, check that the sketch says LED_BUILTIN or 13, and that the output ended with Done uploading rather than an error further up.
Many boards leave the factory with a Blink-like sketch on them. Change the delays to 100 and upload again: if the rhythm changes, your upload worked.
Verify only compiles, so the fault is after the computer: the port, the cable, the driver or the board. The messages and what each one means are in when the upload fails.
The bootloader never answered. Check that Tools, Board names your board and Tools, Port is the entry that appears when the board is plugged in, close the Serial Monitor, and take any wire out of pins 0 and 1. On a Nano, try Tools, Processor, ATmega328P (Old Bootloader).
The messages a failed upload prints, what each one means, and where in the chain it broke.
When the upload fails →Edit this page — content/books/atmega328p/your-first-upload.mdx
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.