Sub topic 4
Selecting the board and port, then uploading
This chapter assumes you understand variables and basic voltage, current, and resistance. You also need an Arduino-compatible board, a data-capable USB cable, and the Arduino IDE installed. You should already have a sketch containing setup() and loop().
Why the board and port matter
The Arduino IDE must know two separate things:
- The board is the hardware model and microcontroller target. It determines how the sketch is compiled and how it is uploaded.
- The port is the computer connection used to communicate with the board. It identifies the USB or serial device.
Selecting the wrong board can produce compilation or upload errors even when the board is connected correctly. Selecting the wrong port sends the upload to another device or to no device at all.
The board and port are often shown together in the IDE 2 board selector near the top of the window. You can also choose them from the Tools menu.
| Setting | Example | What it controls |
|---|---|---|
| Board | Arduino Uno | Compiler settings and upload protocol |
| Port | COM5 or `/dev/cu.usbmodem...` | The connected board used for communication |
Prepare a test sketch
Use a small sketch so that you can test the complete upload process. This example uses the board’s built-in LED, so it does not require external wiring.
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}Save the sketch with a useful name, such as BlinkTest. The Arduino IDE stores sketches in folders whose names normally match the main .ino file. Save before compiling or uploading so that your latest changes are used.
Select the board
Connect the board with the USB cable, then select its hardware model.
- Open the board selector, or open Tools > Board.
- Choose the board family and exact model. For example, select Arduino AVR Boards > Arduino Uno for a standard Uno.
- If the board package is missing, open Tools > Board > Boards Manager.
- Search for the package that supports your board and install it.
- Select the model again after installation.
Some third-party boards use a different package from official Arduino boards. Read the board documentation if the model is unclear. A board that looks like an Uno may use a different microcontroller or USB interface.
Select the port
Open the board selector or Tools > Port. Choose the port that appeared when you connected the board.
Port names depend on the operating system:
- Windows commonly uses names such as
COM3orCOM5. - macOS commonly uses names beginning with
/dev/cu.usbmodemor/dev/cu.usbserial. - Linux commonly uses names such as
/dev/ttyACM0or/dev/ttyUSB0.
If several ports are listed, disconnect the board, note the list, reconnect it, and choose the new entry. Do not select a Bluetooth, modem, or unrelated serial device.
Verify and upload
The Verify button compiles the sketch without sending it to the board. Use it first when you want to separate code errors from connection errors.
- Click Verify.
- Read the output panel. A successful compilation reports that the sketch uses a percentage of program storage and dynamic memory.
- Click Upload.
- The IDE compiles the sketch again, resets the board, and transfers the compiled program.
- Wait for a message such as Done uploading.
During upload, the board may briefly reset. The board’s transmit and receive indicators often flash. After the upload finishes, the board starts the new program automatically. The built-in LED should turn on for about one second and off for about one second.
Separate compilation errors from upload errors
A compilation error means the computer could not turn the sketch into machine code. Typical causes include a missing semicolon, misspelled function, or unavailable library.
An upload error occurs after compilation or while communication begins. Common messages include “port not found,” “access denied,” and “programmer is not responding.” Check the selected port and board first. Then try a different data cable, close programs using the serial port, and reconnect the board.
If the port disappears when you start uploading, the USB driver, cable, connector, or board may be at fault. Some boards require a USB-to-serial driver. Follow the manufacturer’s instructions rather than installing an unrelated driver.
Exercise
The sketch verifies successfully, but uploading reports that the selected port cannot be found. What should you check first?
Show answer
Reconnect the board, reopen the port list, and select the port that appears for that board. If no new port appears, check the USB data cable, USB socket, and required driver.