Skip to Content
Circuitera

Fix a redefined loop() after combining Arduino sketches

Understand duplicate Arduino entry points and refactor pasted sketches into one loop() calling two helpers.

Count the definitions across the sketch

Copying complete sketches into one file or into two .ino tabs can add a second body named loop(). The Arduino build treats .ino tabs as parts of one sketch. Duplicate bodies in that source give a redefinition error. Separately compiled .cpp files can instead fail at link time with a multiple-definition diagnostic.

Combine behavior with helper functions

Keep one setup() and initialize shared hardware once. Keep one loop() and call both helpers. Use a clear name for each job and decide which owns a pin when both examples write to it. Compile after adding each helper. If one job uses delay(), test how long the other job waits.

Open the exact Uno example

The corrected sketch has one loop. The controlled second loop body reproduces the redefinition.

void lightOn() { digitalWrite(LED_BUILTIN, HIGH); }
void waitBriefly() { delay(100); }

void setup() { pinMode(LED_BUILTIN, OUTPUT); }
void loop() {
  lightOn();
  waitBriefly();
}

Verified with [email protected] on Uno R3 (2026-12-05 UTC). The intentionally broken variant reproduced the named diagnostic. This check did not use physical hardware.

Continue learning

Sources