Visual Studio Code (VS Code) has become a popular choice among developers for its lightweight yet powerful features and extensive customization options. While it’s commonly associated with software development, it’s also a versatile platform for programming hardware, including Arduino microcontrollers. In this guide, we’ll explore how to set up and use Visual Studio Code for Arduino development, leveraging its features to streamline the coding process and enhance productivity.
For Mac, we already have a separate guide – Setup Visual Studio Code on Mac For Debugging Arduino & WordPress.
Why I Will Use Visual Studio Code For Arduino?
It is true that VS Code is not the easiest way to write code for Arduino, ESP32 etc. Indeed, it is meaningless to use anything other than Arduino IDE for too small projects with less than 100 lines of code. Visual Studio Code is required for advanced projects with ESP32 or Arduino boards.
---
Visual Studio Code is available for Windows, macOS, and Linux, making it a versatile choice for Arduino development regardless of your operating system. You can use the same development environment across different platforms, ensuring consistency and compatibility. It is a powerful IDE for writing, editing, and managing your Arduino sketches. It offers syntax highlighting, code completion (IntelliSense), and other features that enhance the coding experience and productivity.
Visual Studio Code seamlessly integrates with version control systems like Git, allowing you to manage your Arduino projects and collaborate with others more effectively. You can commit, push, pull, and merge changes directly from within the editor, keeping your codebase organized and up-to-date.
Prerequisites to Use Visual Studio Code for Arduino
Before we begin, ensure you have the following prerequisites:
- Visual Studio Code installed on your computer. You can download it from Microsoft’s VS Code site.
- Arduino IDE installed (required for installing Arduino board definitions and libraries).
- Basic familiarity with Arduino programming concepts.
- Arduino board connected to your computer via USB.
Steps to Use Visual Studio Code for Arduino
Visual Studio Code offers extensions to expand its functionality, and there’s an official extension for Arduino development. Follow these steps to install it:
- Open Visual Studio Code. Initially, you can use the Quiet Light theme.
- Go to the Extensions view by clicking on the square icon on the sidebar or pressing Ctrl+Shift+X.
- Search for “Arduino” in the Extensions Marketplace.
- Click “Install” next to the “Arduino” extension offered by Microsoft.
Set Up Arduino in Visual Studio Code
Once the Arduino extension is installed, you need to configure it to work with your Arduino environment:
- Open the Command Palette by pressing Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac). Type “Arduino” and you’ll get the board options including that of ESP32. If your Arduino IDE is configured for ESP32, then you need not do anything more.
- Type “Arduino: Initialize” and select “Arduino: Initialize”.
- Choose the folder where you want to store your Arduino sketches.
- Select your Arduino board from the list of available options.
Create a New Arduino Sketch
Now that your environment is set up, you can create a new Arduino sketch:
- Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P).
- Type “Arduino: New Project” and select it.
- Enter a name for your project and choose the folder where you want to save it.
Once you have opened up an .ino file, VS Code reconfigures it to Arduino mode, which gives access to special functionality in its bottom blue margin, with icons to select the board, port etc and a top bar with an upload option.
Open %APPDATA%\Code\User in Windows explorer, open the settings.json file. This file should at least contain this things:
1 2 3 4 5 6 | { "arduino.path": "C:\\Program Files (x86)\\Arduino", "arduino.additionalUrls": "https://espressif.github.io/arduino-esp32/package_esp32_index.json", "C_Cpp.intelliSenseEngineFallback": "Disabled", "C_Cpp.intelliSenseEngine": "Tag Parser", } |
Go to Settings > Workspace > Workbench > Settings Editor and make use that it is using JSON file.
Press CTRL+SHIFT+P then type: “C/CPP: Edit Configurations” then press Enter when the correct setting is highlighted. This will create a file named c_cpp_properties.json, cop paste this content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | { "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:/Program Files (x86)/Arduion/hardware/arduino/avr/cores/arduino", "C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/EEPROM/src", "C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/HID/src", "C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/SoftwareSerial/src", "C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/SPI/src", "C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/Wire/src", "C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/SPI/src" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE", "F_CPU=16000000L", "ARDUINO=10805", "ARDUINO_AVR_UNO", "ARDUINO_ARCH_AVR" ], "compilerPath": "C:/Program Files (x86)/Arduino/hardware/tools/avr/bin/avr-gcc.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" } ], "version": 4 } |
Save it and launch VS Code as administrator.
Source of above ideas is this: https://github.com/microsoft/vscode-arduino/issues/438
Do not forget to add %SystemRoot%\system32 and %SystemRoot%in your PATH (by opening “Edit environment variable” from Windows search function). Once it was more difficult settings to find out.

Write and Upload Your Arduino Code
- Open the
.inofile created in your project folder. - Write your Arduino code in the editor.
- Connect your Arduino board to your computer via USB.
- Press Ctrl+Alt+U (Windows/Linux) or Cmd+Alt+U (Mac) to compile and upload your code to the Arduino board.
Monitor Serial Output
Visual Studio Code allows you to monitor the serial output of your Arduino board directly within the editor:
- Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac) to open the Command Palette.
- Type “Arduino: Open Serial Monitor” and select it.
- The Serial Monitor panel will open at the bottom of the editor, displaying the serial output from your Arduino board.
Conclusion
Setup of VS Code for the first time is painful due to a lot of bugs. But it is worth the time investment.
Tagged With question4n0 , как прогать ардуино на vs code в 2024