Visual Studio Code (or VSCode) is a very popular text editor with powerful capabilities. VSCode is a great choice for developing Arduino applications. In this guide, I will show you how to setup VSCode as your main Arduino development environment. After using VSCode, you probably won’t go back to Arduino IDE again.
Installing Arduino IDE, VSCode and Arduino extensions
First, go to VSCode website and download it. Follow instructions to install VSCode on your system (either Windows, Mac or Linux). This is quite straight-forward.
Then open Extensions tab on the left panel, search for Arduino extension and install it. You should also find and install the C/C++ extension as shown in the image below
The Arduino extension in VSCode requires Arduino IDE, so head to Arduino official website, download and install it. VSCode will invoke Arduino IDE behind the scene, but we won’t be using Arduino IDE editor.
Using VSCode for Arduino development
Now you have installed all required software components, in this section, we will look at common tasks when doing Arduino development using VSCode:
- Open a sample project in Arduino IDE
- Select an Arduino board
- Select Serial Port
- Compile and upload code to Arduino board
- Open Serial Monitor
- Add a library
- Create a new Arduino project
Opening a sample project
In VSCode, you can invoke a command by clicking
View > Command Palette .... or use shortcut key combinations
Cmd + Shift + P. If you type
Arduino, you will see a list of supported commands in VSCode as shown below
To open a sample project, open command palette and type
Arduino: Examples in the search box, a window with examples will be shown:
You can open a project by clicking on the project name. For instance, if you click Blink, a new window containing the project files will be opened. From here, you can edit your code in
Selecting an Arduino board
To select an Arduino board, you can use the bottom status bar. On the bottom right corner, there’s a button
<Select Board Type>. If you click it, the Arduino Board Configuration will be shown and from there, you can select your target board. For example, here I select Arduino Mega 2560 as my Arduino board.
Alternatively, you can use the command palette and type
Arduino: Board Config. The same window will show up so that you can select your board.
Selecting Serial Port
To select the serial port to program the arduino board, you can use the bottom status bar where there’s a button
<Select Serial Port>. Connect your Arduino board to your computer using a USB cable and click the button. Then select the port from the dropdown list. Another option is to use command palette and type
Arduino: Select Serial Port.
Compile and upload your code
To compile your code, use the command palette and type
Arduino: Verify. You will see the output log messages in the
To upload your code to Arduino, use the command palette and type
Open Serial Monitor
Serial Monitor is useful when debugging your project. To open Serial Monitor, click on the icon
<Open Serial Monitor> on the left hand side of
<Select Serial Port>. You will need to select serial port before opening serial monitor. Another way to open serial monitor is to use command palette and type
Arduino: Open Serial Monitor. You can specify the baud rate for the serial monitor on the bottom status bar.
Adding a library
To install a library, open command palette and type
Arduino: Library Manager. The Arduino Library Manager window will show up. From there, you can search for your library, select a version and click Install button to install the library.
Creating a new Arduino project
To create a new project, just create a file with .ino extension and VSCode will recognise it as an Arduino file.
In this article, you have learnt how to use VSCode as the development environment for your Arduino project. With many powerful features and capability to install extensions, VSCode is a great option for your main Arduino development.