How to use VS Code to develop Arduino?


You’ve got two great ways to use VS Code for Arduino work:
the official Arduino IDE extension (simple, close to Arduino IDE)
PlatformIO (full project manager, libraries, multiple boards, CI-friendly)
Here’s how to set up both and when to use each.
1) VS Code + Arduino Extension (Official)
Install
Install VS Code.
Install Arduino IDE (for toolchains & cores) or Arduino CLI.
In VS Code: Extensions → search “Arduino” by Arduino → Install.
Press Ctrl+Shift+P → “Arduino: Initialize” to create
.vscode/arduino.json
.
Configure
Board: Cmd Palette → Arduino: Board Manager → pick your board.
Port: Cmd Palette → Arduino: Select Serial Port.
Programmer: (usually not needed) “Arduino: Select Programmer”.
.vscode/arduino.json
example:
json
{
"sketch": "src/blink.ino",
"port": "COM4",
"board": "arduino:avr:uno"
}
Develop
New sketch:
src/your_sketch.ino
(or.ino
at root).Libraries: Cmd Palette → Arduino: Library Manager (or install via Arduino IDE; VS Code picks them up).
IntelliSense: The extension generates
c_cpp_properties.json
. If symbols are missing, run Arduino: Rebuild IntelliSense Index.
Build / Upload / Monitor
Status bar buttons: ✔️ Verify, → Upload, 🔌 Serial Monitor.
Change baud in the status bar (e.g., 9600/115200).
Pros / When to choose
Quick start, mirrors Arduino IDE behavior.
Great if you already use Arduino cores & examples and want VS Code editing.
2) VS Code + PlatformIO (Recommended for larger projects)
Install
- In VS Code: Extensions → PlatformIO IDE → Install (it bundles its own toolchains; no Arduino IDE required).
Create a project
PIO Home → New Project
Board: e.g., Arduino Uno, ESP32 Devkit, STM32 etc.
Framework: Arduino
Project structure:
bash
project/
platformio.ini
src/main.cpp
include/ # headers
lib/ # private libraries
Example platformio.ini
ini
[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 115200
Build / Upload / Monitor
Left sidebar alien head (PlatformIO) → Build, Upload, Monitor.
Or tasks:
Ctrl+Alt+B Build
Ctrl+Alt+U Upload
Ctrl+Alt+S Serial Monitor
Libraries
PIO Home → Libraries (online registry), or drop libs into
lib/
.Pin versions in
platformio.ini
for reproducible builds:
ini
lib_deps =
adafruit/Adafruit BME280 Library@^2.2.4
Multiple boards / environments
ini
[env:uno]
platform = atmelavr
board = uno
framework = arduino
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
build_flags = -DLED_PIN=2
Use the env switcher on the VS Code status bar.
Pros / When to choose
- Scales well, per-project deps, reproducible builds, CI-friendly, great IntelliSense, easy multi-board support.
Debugging notes (important)
Classic Arduino boards (AVR): no real on-chip debug; use Serial.print(), watch variables, and logic analyzers.
Debugger-capable boards (e.g., certain ESP32, SAMD, STM32): PlatformIO supports hardware debugging via J-Link/ST-Link/ESP-Prog. Configure in
platformio.ini
:
ini
debug_tool = stlink
debug_init_break = tbreak setup
Common issues & fixes
Port not showing (Windows): Install board’s USB driver (CH340/CP210x), try a different cable/port.
Linux permissions:
sudo usermod -a -G dialout $USER
, re-login; set correct/dev/ttyUSB*
or/dev/ttyACM*
.IntelliSense missing symbols: Rebuild index (Arduino ext) or PlatformIO: Rebuild C/C++ Project Index.
Upload errors: Close any open Serial Monitor; reset the board; check selected board/port.
WSL: Prefer native VS Code on Windows for USB serial; or use VS Code Remote with USB pass-through carefully.
Quick pick guide
Hobby / one board / quick sketches → Arduino Extension.
Serious / multi-board / versioned deps / CI → PlatformIO.
Subscribe to my newsletter
Read articles from ampheo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
