Sub topic 4
Selecting the board and port, then uploading
This chapter covers the step between writing a sketch and seeing the LED change. It assumes you have the Arduino IDE installed, a board and a USB cable, and you know that a sketch has setup() and loop(). You also need to know what a digital pin does. The chapter explains what the IDE does when you press Upload, which two settings you must choose, and how to read the errors that appear when something goes wrong.
What "upload" actually does
The processor on your board cannot run C++ text. The IDE has to turn your sketch into machine code for that specific chip, then copy it into the chip's flash memory. Flash is non-volatile storage that keeps its contents when power is removed. The two stages are:
- Compile. The IDE merges your sketch with the Arduino core, the library of board-specific code that provides
pinMode(),digitalWrite(),delay()and the startup routine. It runs a compiler for the board's processor family and produces a binary file. - Upload. A tool sends that binary over USB to the board. On a classic Uno, a small program called a bootloader receives the data and writes it into flash. A bootloader is a short program that lives permanently in a protected part of flash and runs briefly after each reset. If no new upload arrives, it hands control to your sketch.
Both stages depend on knowing which board you have. A different board means a different processor, a different compiler setting and a different upload method. That is why the IDE asks you to choose a board before it can do anything useful.
Choosing the board
The board setting tells the compiler which processor and core to target. Choose the one that matches the physical board.
In the Arduino IDE 2.x, use the board selector drop-down in the toolbar. It lists boards that the IDE detects over USB. If your board is not listed, choose "Select other board and port" and search by name.
Boards from some families need a board package before they appear. A board package, also called a core, is a download that adds compiler settings and support code for a family of boards. The Uno, Nano and Mega ship with the "Arduino AVR Boards" package, which is installed with the IDE. Newer boards such as the Uno R4 need their own package, and boards from other makers need theirs as well. Install packages from the Boards Manager, which you open from the left sidebar.
Common names and what to pick:
| Physical board | Board entry | Notes |
|---|---|---|
| Arduino Uno R3 | Arduino Uno | Uses the AVR core |
| Arduino Nano (classic) | Arduino Nano | Check the Processor menu |
| Arduino Mega 2560 | Arduino Mega or Mega 2560 | Different processor from the Uno |
| Arduino Uno R4 Minima or WiFi | Matching Uno R4 entry | Needs the Renesas core |
The Nano is a common trap. Older Nano boards use the ATmega328P with the old bootloader, while newer ones use the new bootloader. The IDE shows a Processor option under the Tools menu. If uploads fail with a "not in sync" error, try the other bootloader option.
Choosing the port
The port is the connection through which your computer talks to the board. Over USB, the operating system creates a virtual serial port when it sees the board. The upload tool sends the binary through that serial port.
Port names depend on the operating system:
| System | Typical port name |
|---|---|
| Windows | `COM3`, `COM4` and so on |
| macOS | `/dev/cu.usbmodem14101` or `/dev/cu.usbserial-1410` |
| Linux | `/dev/ttyACM0` or `/dev/ttyUSB0` |
A simple way to find the right port is to open the port list with the board unplugged, then plug the board in and look again. The new entry is your board. Select it in the port selector next to the board drop-down, or under Tools, then Port.
When the port does not appear
If no new port shows up after plugging in the board, check these causes in order:
- The cable carries only power. Some USB cables have no data wires. Swap it for a cable you know transfers files.
- A driver is missing. Clone boards with a CH340 chip may need a driver on Windows and older macOS versions.
- The USB port or hub is faulty. Try a different port and connect directly to the computer, not through a hub.
- Linux permissions. On Linux, your user may not be allowed to open the serial device. Add your user to the
dialoutgroup (on some distributions,uucp), then log out and back in.
On Linux, the command looks like this:
sudo usermod -a -G dialout "$USER"Verify and Upload are different buttons
The toolbar has two main buttons.
- Verify (the check mark) compiles the sketch and reports errors. It does not touch the board and does not need a port.
- Upload (the right arrow) compiles first, if needed, and then sends the binary to the board. It needs both the board and the port to be correct.
Verifying before uploading is a quick way to separate two kinds of failures. If Verify fails, the problem is in your code or board selection. If Verify passes and Upload fails, the problem is in the connection, the port or the bootloader.
Uploading the blink sketch
Use the built-in example so that any problem is not caused by your own code. Open File, then Examples, then 01.Basics, then Blink. It is the same sketch shown earlier in this tutorial:
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}LED_BUILTIN is a constant defined by the board's core. It stands for the pin number of the LED soldered onto the board. On the Uno that is pin 13. Because the core defines it for each board, the same sketch works across boards without edits.
Follow these steps:
- Connect the board with the USB cable.
- Select the board in the board drop-down.
- Select the port.
- Press Upload.
While uploading, the TX and RX LEDs on the board flicker as data moves. The output area at the bottom shows progress. A successful upload ends with a message such as "Done uploading", and the on-board LED on pin 13 begins to flash once per second.
What happens during the reset
Uploading needs the bootloader to be running, and the bootloader only runs just after a reset. The IDE therefore forces a reset at the start of an upload. On the Uno, opening the serial port toggles the DTR line, a control signal on the serial connection. The board is wired so that this signal pulses the reset pin of the processor. The bootloader starts, waits a moment for incoming data, receives the binary and writes it to flash. Then the sketch runs.
This explains two behaviours you may notice:
- The board restarts every time the serial port is opened, including when you open the Serial Monitor. Your sketch begins again from
setup(). - If something else is already holding the port, such as a second IDE window or a serial terminal program, the upload cannot open it and fails.
Boards with native USB, such as the Leonardo and some newer boards, work differently. The IDE asks the running sketch to reset into the bootloader, and the port may disappear and come back under a new name during the upload. If you select the port by hand, choose the one that is present when the upload begins.
Reading the output
The output pane gives the most useful clues. Open Preferences and turn on "Show verbose output during upload" when you need more detail.
A healthy compile ends with a summary of memory use:
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.Program storage is flash. Dynamic memory is SRAM, the working memory for variables. Both matter later, when larger sketches approach their limits.
Common errors and what they mean:
| Message | Likely cause | What to try |
|---|---|---|
| `Board at COM3 is not available` or `port busy` | Another program holds the port, or the board is unplugged | Close the Serial Monitor and other terminals, replug the board |
| `avrdude: stk500_recv(): programmer is not responding` | Wrong board, wrong port or wrong bootloader | Recheck the board and Processor settings |
| `avrdude: stk500_getsync(): not in sync: resp=0x00` | The board did not answer in the expected protocol | Same checks, and try the old bootloader option on a Nano |
| `Permission denied` on `/dev/ttyACM0` | Linux user lacks serial access | Add yourself to `dialout`, then log in again |
| `'xyz' was not declared in this scope` | A compile error, not an upload error | Fix the code, then Verify again |
| `Error compiling for board Arduino Uno` with unrelated errors | Board package not installed or wrong board chosen | Install the package in Boards Manager |
The avrdude messages come from the upload tool for AVR boards. Boards in other families use different tools, and their messages look different, but the ideas are the same: the tool could not reach the bootloader.
Checking that the upload really replaced the old program
A common mistake is to assume that the new sketch is running when the upload actually failed. The board keeps running whatever was in flash before. To avoid being misled, make a visible change that you can recognise. For example, change both delays from 1000 to 200. After upload, the blinking should be clearly faster. If the speed does not change, read the output pane for an error you missed.
The binary stays in flash after you unplug the board. Plug it into a plain USB power supply and it starts the sketch again. No computer is needed after the upload.
A short checklist
- Verify compiles without errors.
- The board selection matches the physical board, including the Processor option where one exists.
- The port is the one that appears when the board is plugged in.
- No other program is using the port.
- The cable carries data.
- The output pane ends with a success message.
Exercise
You press Upload and see avrdude: stk500_getsync(): not in sync: resp=0x00. Verify passed earlier with no errors. Name two settings or conditions you would check first, and explain why a passing Verify does not rule them out.
Show answer
Check that the board selection (including the Processor option on a Nano) matches the physical board, and that the selected port is the one that appears when the board is plugged in. Also check that nothing else is holding the port and that nothing is wired to pins 0 and 1. Verify only compiles the code and never contacts the board. It can pass with the wrong port, a busy port or the wrong bootloader setting, because those only matter during the upload stage.
Exercise
You upload the Blink sketch with both delays changed from 1000 to 100, but the on-board LED still blinks once per second and the output pane shows an error near the top that you did not read. What is the most likely state of the board, and what should you do?
Show answer
The upload failed, so the board is still running the previous program from flash. Scroll through the output pane to find the error, fix the cause (port, board, cable or busy port), and upload again. The faster blink confirms success when it appears.