Changing the default Arduino New Project Template


When I start a new Arduino project, i would prefer the template be the main.cpp found in the arduino cores directory (i.e. based on main() instead of setup() & loop().). I’ve searched everywhere and cannot find out how to do this…

I did learn how to use snippets… a pretty cool feature; but I would still prefer it if I could somehow change the starting template.

can someone point me in the right direction?


Currently, we don’t provide this configuration. However, this feature request will help here

Thanks for the quick feedback. In the mean time, I will just drag my template into the project src file when i create a new project.

I wonder who put the code there in the first place - EVERY NEW project has this in the main.cpp:

#include <Arduino.h>

// put function declarations here:
int myFunction(int, int);

void setup() {
  // put your setup code here, to run once:
  int result = myFunction(2, 3);

void loop() {
  // put your main code here, to run repeatedly:

// put function definitions here:
int myFunction(int x, int y) {
  return x + y;

Where does this code come from … I’m NOT aware of typing that at any time !

The PlatformIO core autocreates it.

AND … ???

My problem is - can I change it ?
If so, where do I do it ?

There is no functionality for that to be user-changable. It’s hardcoded in the PlatformIO core code. The above linked issue tracks that.

Why not use the power of VSCode?
You can create custom snippets!
You can find instructions here:

  1. Watch the Video
  2. Edit the cpp.json and add this:
	  "Arduino default code" : {
		"prefix" : "adc",
		"body" : [
			"#include <Arduino.h>",
			"void setup() {",
			" Serial.begin(115200);",
			" Serial.println(\"Hello World\");",
			"void loop() {",
  1. If you have created a new PIO project:
  • Press CTRL+A on your keyboard to select everything
  • Enter “adc” (or the prefix you have used)
  • Press ENTER

This will only cost you 5 keystrokes (if you count the combination CTRL+A as one :wink: )

1 Like