⚡
usefultools.dev
{ }

Arduino Code Formatter (.ino Beautifier)

NEW

Arduino code formatter for .ino and C++ sketches: re-indent by braces, K&R or Allman style, operator spacing and a diff — free, in your browser.

Runs 100% in your browser — your input is never uploaded or stored on our servers.

18 lines changed

  • Re-indented lines: 9
  • Brace / line-break moves: 3
  • Spacing fixes: 31
  • Blank lines removed: 2
  • Trailing whitespace trimmed: 0
  • Lines: 29 → 24

Formatted code

#include <Servo.h>
#define LED_PIN 13   // on-board LED

Servo myServo;
const int angles[] = {0, 45, 90,
  135, 180};

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  myServo.attach(9);
}

void loop() {
  for (int i = 0; i < 5; i++) {
    myServo.write(angles[i]);
    digitalWrite(LED_PIN, i % 2 == 0 ? HIGH:LOW);
    Serial.println("angle = " + String(angles[i]));
    delay(500);
  }
  if (millis() - lastPrint >= 1000) { lastPrint = millis(); } else {
    // nothing to do
  }
}

A lightweight, token-based formatter — not clang-format. String and character literals, comments and #directives are kept exactly; ambiguous spacing such as a*b or a&b between two names, and anything that looks like a template (vector<int>), is left as written.

⚡

Quick Examples

Typical inputs and the results this tool produces.

Operators
int x=a+b;
int x = a + b;
Calls
pinMode (13,OUTPUT);
pinMode(13, OUTPUT);
Keywords
if(a>b){x=1;}
if (a > b) { x = 1; }
Loops
for(i=0;i<3;i++) f(i);
for (i = 0; i < 3; i++) f(i);
Strings kept
Serial.print ("a,b=c");
Serial.print("a,b=c");
📖

Overview

This Arduino code formatter tidies .ino sketches and small C++ files the way the IDE’s Auto Format does, with a few more options: 2-space, 4-space or tab indentation, K&R or Allman braces, consistent spacing around operators and after commas and keywords, collapsed blank lines and no trailing whitespace.

It is meant for hobby sketches, forum posts and pull requests where you want readable code without installing clang-format. A built-in C/C++ tokenizer reads the code first, so text inside strings, character literals, comments and #define lines is never touched, and unbalanced braces or an unterminated string are reported with a line and column instead of being guessed.

Everything runs in your browser — your sketch is not uploaded. A summary and a unified diff show exactly what changed before you copy or download the result.

Why use this tool?

  • Clean up pasted forum or tutorial code in seconds
  • Match a team style: 2 or 4 spaces, K&R or Allman
  • See every change in a diff before you keep it
  • Strings, comments and macros stay byte-for-byte
  • No install, no upload — runs locally
⭐

Features

↹

Brace-based indentation

Indentation is rebuilt from { } and ( ) nesting, including switch/case bodies and unbraced if/for bodies.

{

K&R or Allman

Move opening braces to the header line or onto their own line, and join or split } else.

➕

Operator spacing

Spaces around =, ==, +=, <<, && and binary + - while leaving unary minus, pointers and templates alone.

🔒

Literal-safe tokenizer

Strings, raw strings, char literals, comments and #directives are emitted exactly as written.

🔍

Diff summary

Counts of re-indented lines, brace moves, spacing fixes and blank lines, plus a unified diff.

💾

Copy or download

Copy the formatted code or save it as an .ino file with your own file name.

🛠️

How to Use

1

Paste your sketch

Paste .ino or C++ code into the input box, or load the Sample.

2

Pick a style

Choose indentation, brace style, max blank lines and whether to fix spacing.

3

Review the changes

Read the summary and open Show diff to check every changed line.

4

Copy or download

Use Copy code or Download .ino, or Replace input with result to keep editing.

🤔

Frequently Asked Questions