Sub topic 12
Troubleshooting common setup and upload problems
This chapter assumes you have installed the Arduino IDE, connected a board over USB, and tried to upload Blink at least once. It also assumes you know the roles of the board and port menus. Here you will learn a method for finding the cause of a failure, and then the specific fixes for the most common failures.
A model for diagnosing failures
Pressing Upload runs a chain of steps. A failure always happens at one link in the chain, and the error message usually tells you which one.
Work from the top down. Do not change several settings at once. If you change one thing and test again, you learn which change mattered.
The Output panel at the bottom of the IDE shows the full log. By default it shows only a short summary. To see more, open the preferences and enable verbose output during compilation and upload. This lets you see the exact command the IDE ran and the exact line where it stopped.
Failures before upload: compile errors
A compile error means your code never reached the board. The IDE highlights a line and prints a message in the Output panel. Three errors cover most beginner cases.
| Message | Likely cause | Fix |
|---|---|---|
| `expected ';' before '}' token` | A missing semicolon on or just above the flagged line | Add the semicolon. The flagged line is often the line after the real mistake. |
| `'Serial1' was not declared in this scope` or similar | You used a name the selected board does not define | Check the board selection, or correct the spelling. Names are case sensitive. |
| `fatal error: Servo.h: No such file or directory` | A library is not installed | Install it with the Library Manager. |
Two habits help here. First, fix the first error in the list and compile again. Later errors are often side effects of the first one. Second, read the message literally. was not declared in this scope means the compiler has not seen a definition for that name at that point in the file.
A compile error that appears only after you switch boards is a hint. Some names, such as extra serial ports or specific pin constants, exist only for certain boards. This is one reason the board selection matters even before you upload.
Failures at the port: the port is missing or greyed out
If the Port menu is empty or has no entry that looks like your board, the computer has not recognized the board as a serial device. Check these causes in order.
- A charge-only cable. Some USB cables carry power but no data lines. The board lights up, but the computer sees nothing. Try a different cable, ideally one you know transfers data with another device. This is the most common cause.
- A loose or unpowered connection. Plug the board directly into the computer, not into an unpowered hub. Reseat both ends of the cable.
- A missing driver. Genuine Uno boards use a chip that Windows, macOS, and most Linux systems support. Many clone boards use a CH340 or CP210x USB-to-serial chip. These can require a separate driver on some systems. If the board never appears, look up the chip name printed on the board, install its driver, and reconnect.
- Permissions on Linux. On Linux, serial devices usually belong to a group such as
dialoutoruucp. If your account is not in that group, the port can appear but the upload fails with a permission error.
On Linux you can check the group and add yourself to it from a terminal:
# Show the groups your account belongs to
groups
# Add your account to the dialout group (log out and back in afterward)
sudo usermod -a -G dialout "$USER"The group change takes effect only after you log out and back in. Some distributions use uucp or plugdev instead, so check which group owns the device with ls -l /dev/ttyACM0 or ls -l /dev/ttyUSB0.
A useful test is to unplug the board, look at the Port menu, plug the board in, and look again. The entry that appears is your board. If nothing new appears, the problem is below the IDE level, in the cable, the driver, or the hardware. Changing IDE settings will not fix it.
Failures at upload: the board does not respond
Once the port is present, the uploader can still fail to reach the board. The messages differ by board family, but they describe the same situation: the uploader sent a request and received no valid reply.
Not in sync
On an Uno or Nano, the error often reads like this:
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00The uploader (avrdude) is talking to a bootloader, a small program that lives on the board and receives new sketches over serial. "Not in sync" means no bootloader answered. Check these in order:
- Wrong board selected. This is the most common cause. A different board type uses a different upload protocol or speed, so the bootloader does not recognize the request. Confirm the board name in the menu matches the physical board.
- Wrong port selected. If several ports are listed, you may be sending the sketch to another device. Use the unplug and replug test to identify the right one.
- Another program holds the port. Only one program can use a serial port at a time. A Serial Monitor window, a second IDE window, or a terminal program can block the upload. Close them and try again.
- Pins 0 and 1 in use. On an Uno, digital pins 0 and 1 share the serial line with USB. A wire or shield on those pins can interfere with the upload. Disconnect anything attached to them and upload again.
- A damaged or missing bootloader. This is rare. It can happen on boards that were programmed with an external programmer. Reburning the bootloader fixes it, and it needs extra hardware.
Clone Nano boards add a variation. Many use an older bootloader. If the upload fails with the standard Nano selection, change the Processor option under the Tools menu to the "Old Bootloader" variant and try again.
Permission denied and port busy
A message such as cannot open port or Permission denied means the operating system refused the connection. On Linux, this points back to the group membership above. On any system, a busy port means another program has it open. Close the Serial Monitor first, since it is the program most often forgotten.
Timeouts and boards that need a reset
Some boards, such as ones based on native USB chips (Leonardo, Micro, and many 32-bit boards), do not reset automatically in the same way. During an upload the IDE asks the board to restart into its bootloader, and the port number can change for a few seconds. If the upload fails because the port vanished, try this:
- Start the upload.
- When the IDE reports it is uploading, press the reset button on the board once, or twice quickly on boards that support double-tap reset.
- Check the Port menu again. A new port may have appeared while the board is in bootloader mode. Select it and retry.
Failures after upload: it uploaded but nothing happens
Sometimes the IDE reports "Done uploading" and the board does nothing visible. The upload chain worked, so the problem is in the sketch or the circuit.
- The LED does not blink. Check that the sketch is Blink and that it is the version you uploaded. Confirm that you used
LED_BUILTIN, which maps to the correct onboard pin for the selected board. If you used a hard-coded pin number such as13, that pin may not drive the LED on a different board. - The Serial Monitor shows nothing. Check that the monitor is open on the same port as the board. Make sure the sketch calls
Serial.begin(9600)insetup(). - The Serial Monitor shows garbage characters. The baud rate in the monitor does not match the rate in
Serial.begin(). Set the monitor to the same value as the sketch, for example 9600. - The sketch seems to restart. Opening the Serial Monitor on many boards resets the board, so your
setup()runs again. This is normal for AVR boards such as the Uno.
The following sketch is a good test for the "nothing happens" case. It checks both the LED and the serial output in one upload:
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("LED on");
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("LED off");
delay(1000);
}If the messages appear but the LED stays dark, the code runs and the problem is the LED pin or the board. If the LED blinks but nothing appears in the monitor, the problem is the baud rate or the port. If neither works, the sketch did not reach the board, so return to the upload steps.
Environment problems
A few failures come from the IDE itself and not from the board.
- Board missing from the menu. The board package is not installed. Open the Boards Manager, search for the package that supports your board, and install it.
- Stale package or library lists. If the Boards Manager or Library Manager shows nothing, check your network connection and any proxy settings. These managers download an index file from the internet.
- A library that will not compile. Some libraries support only certain boards. The error often names a missing register or header. Check the library's documentation for supported architectures.
- Strange errors after an update. Restart the IDE. If a single package seems broken, remove it in the Boards Manager and install it again.
A repeatable checklist
When an upload fails, run through this list in order. Stop at the first step that changes the result.
- Read the first error line in the Output panel and decide which link of the chain failed.
- Confirm that a data-capable cable is plugged directly into the computer.
- Unplug and replug the board, and confirm that a new port appears.
- Select the board that matches the physical board, then select the new port.
- Close the Serial Monitor and any other program that might use the port.
- Disconnect anything wired to pins 0 and 1.
- Press reset, or try another USB port or cable.
- Upload the test sketch above to separate upload problems from code problems.
Exercise
You upload Blink to an Uno and see "not in sync: resp=0x00" ten times in a row. The Port menu shows one port that appeared when you plugged the board in. List three causes to check, in a sensible order, and say how you would tell each one apart.
Show answer
Check the board selection first: confirm the menu says Arduino Uno and not another board, because a mismatch changes the upload protocol. Next check whether another program holds the port: close the Serial Monitor and other serial tools, then retry. Then check pins 0 and 1 for attached wires or a shield, and disconnect them. Because the port appeared on plugging in, the cable and driver are probably fine, so you can rule them out. A damaged bootloader is a last resort.
Exercise
The upload succeeds, the Serial Monitor is open on the right port, and it shows unreadable characters such as "ÿ" and "?". What is wrong and how do you fix it?
Show answer
The baud rate in the Serial Monitor does not match the rate passed to Serial.begin(). Set the monitor's baud dropdown to the same value as the sketch, for example 9600. No re-upload is needed if the sketch itself is correct.