Arduino IDE: boards, ports, uploading and errors
The lab sheets show how to set up the IDE. This page explains what is happening, so you can fix it when the upload fails or the sketch does not compile.
What happens when you click Upload
- Verify (compile): your sketch is turned into machine code for the Uno's ATmega328P chip. Errors here are mistakes in your code (or a missing library). Nothing is sent to the board yet.
- Upload: the IDE resets the Uno through the USB port and sends the program to it. Errors here are connection problems: wrong port, wrong board, port busy, cable.
So: an error after Verify → read your code. Verify works but Upload fails → check the board, port and cable.
Board and port
- Tools → Board → Arduino AVR Boards → Arduino Uno.
- Tools → Port: the port of your Uno. On Windows
COM3,COM5...; on the Pi/dev/ttyACM0.
Not sure which port? Look at the list, unplug the Uno, look again: the one that disappeared is the Uno. On Windows, Device Manager → Ports (COM & LPT) shows it too. No port appears at all:
- Some USB cables only charge: swap the cable.
- Clone boards with a CH340 chip need the CH340 driver on Windows (shows as "USB-SERIAL CH340").
- Try another USB port; avoid unpowered hubs.
Sketch structure
void setup() {
// runs once, after power-up, reset, upload or opening the Serial Monitor
}
void loop() {
// runs again and again, as fast as it can, forever
}
Everything you put in loop() repeats. delay(1000) pauses everything for one second: during a delay the Uno cannot read buttons or sensors.
Compile errors (after Verify)
The IDE shows the line number. The error is usually on that line or the line before.
| Error | Usual cause |
|---|---|
expected ';' before ... | Missing ; at the end of the previous line |
'xyz' was not declared in this scope | Typo or wrong capitals (serial vs Serial, digitalwrite vs digitalWrite), variable declared inside another { } block, or a library missing |
xyz.h: No such file or directory | Library not installed: Sketch → Include Library → Manage Libraries (or Add .ZIP Library) |
expected '}' at end of input | A { without a matching }. Use Tools → Auto Format (Ctrl+T) to see the structure. |
stray '\342' in program | Smart quotes or odd characters pasted from a PDF/Word. Retype the quotes and minus signs. |
redefinition of 'void setup()' | Two sketches in one: another .ino file in the same folder, or setup() pasted twice |
invalid conversion from 'const char*' to 'int' | Text in quotes where a number was expected |
Arduino code is C++: case-sensitive, every statement ends with ;, and = (assign) is not == (compare). if (x = 5) compiles but is always true.
Upload errors
| Error | Fix |
|---|---|
avrdude: ser_open(): can't open device "COM3" / Port busy / Access is denied | Another program has the port: Serial Monitor in a second IDE window, Serial Plotter, or Python on the Pi. Close it. |
avrdude: stk500_recv(): programmer is not responding / not in sync | Wrong board selected, wrong port, or something connected to pins 0 and 1 (the USB serial line). Unplug wires from D0/D1 while uploading. |
No device found on COM3 / port greyed out | Board unplugged or cable charge-only. |
| Upload works but nothing happens | Wrong sketch open? Check the title bar. Press the Uno's RESET button. |
Libraries used in the labs
| Hardware | Library name in the Library Manager | Include |
|---|---|---|
| Grove LCD RGB Backlight | Grove - LCD RGB Backlight | #include "rgb_lcd.h" |
| Grove Ultrasonic Ranger | Grove Ultrasonic Ranger (or the ZIP from the lab) | #include "Ultrasonic.h" |
After installing, File → Examples has working example sketches for each library. When your sketch does not work, run the library's example first: if the example fails too, the problem is wiring, not your code.
The Uno's pins
| Pins | Use |
|---|---|
| D0, D1 | USB serial: avoid (they break uploads and Serial Monitor) |
| D2–D13 | Digital in/out. ~ marked pins (3, 5, 6, 9, 10, 11) can do PWM |
| D13 | Also the onboard L LED |
| A0–A5 | Analog inputs (0–1023); also usable as digital pins |
| A4, A5 | Also I2C (SDA, SCL), used by the Grove LCD |
| 5V, 3.3V, GND | Power for sensors. Never connect 5V straight to GND. |
Each pin can give about 20 mA safely (40 mA absolute max). Enough for an LED with a resistor; not for a motor.