30 Days Lost in Space → Help Center

Troubleshooting

Code Compiles but Nothing Happens

Your code uploaded without errors. No red text, no warnings. But the Arduino does nothing. No LED, no serial output, no movement. Total silence.

What You See

You hit Upload, the IDE says "Done uploading," and then... nothing. The Arduino just sits there. No blinking LEDs (other than the power LED), no serial messages, no servo movement, no sound. Your code compiled and uploaded fine, so the problem is not a syntax error. It is a logic problem somewhere in your code, or a mismatch between what your code does and what you are looking at.

This is frustrating because there is no error message to point you in the right direction. But there are a handful of common reasons this happens, and they are all fixable.

Most Likely Causes

1. Wrong Pin Numbers

This is the simplest and most common cause. Your code controls pin 10 but your LED is on pin 9. Or you typed A0 when you meant pin 7. The code runs perfectly but talks to a pin that has nothing connected to it.

How to check: Add Serial.begin(9600) to setup and Serial.println() calls to confirm your code is running. If Serial prints but the hardware does nothing, the problem is definitely a pin number mismatch.

Fix: Verify every single pin number in your code against your physical wiring. Do it wire by wire.

2. Code Is in setup() but You Expect It in loop() (or Vice Versa)

setup() runs once and then never again. loop() runs over and over forever.

If you put your LED blink code in setup(), it blinks once and then stops forever. If the blink is fast (like a single 100ms flash), you might miss it entirely.

If you put your initialization code in loop(), it re-initializes every iteration, which can cancel out whatever work it did.

Fix: Make sure one-time setup code (like pinMode, Serial.begin, servo.attach) is in setup(), and repeating behavior (like reading sensors, blinking, updating displays) is in loop().

3. Your if-Condition Is Never True

You have code inside an if block that never executes because the condition is never met:

void loop() {
  int value = digitalRead(buttonPin);
  if (value == HIGH) {
    // This never runs if the button is wired with INPUT_PULLUP
    // because unpressed = HIGH, pressed = LOW
    Serial.println("Button pressed!");
  }
}

Or a common mistake with analog readings:

if (analogRead(A0) == 512) {
  // This almost never triggers because analogRead returns
  // a noisy value that rarely lands on exactly 512
}

Fix: Add Serial.println() calls to print the actual values your code is seeing. Then you can see whether the condition could ever be true:

void loop() {
  int value = digitalRead(buttonPin);
  Serial.print("Button value: ");
  Serial.println(value);
  // Now you can SEE what the pin reads
}

4. Variable Scope Issue

A variable declared inside setup() does not exist in loop(). A variable declared inside a for loop does not exist outside it. If you are using a variable that is out of scope, the code might compile (if there is another variable with the same name elsewhere) but behave unexpectedly.

void setup() {
  int ledPin = 10;        // Only exists inside setup()
  pinMode(ledPin, OUTPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH); // ERROR if ledPin is not global
  // If there is a GLOBAL ledPin with a different value, it compiles
  // but uses the wrong value
}

Fix: Declare variables that need to be shared between setup() and loop() at the top of the file, before any function:

const int ledPin = 10; // Global, accessible everywhere

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH); // Works, uses the global
}

5. delay() Is So Long It Looks Like Nothing Is Happening

If you have delay(60000) (60 seconds) at the start of your loop, the Arduino is technically running but it looks dead for a full minute. Or if your delay value is in the wrong units, like using 1000000 when you meant 1000, your "1 second delay" is actually 16 minutes.

Fix: Check all your delay() values. Remember that delay() takes milliseconds, not seconds. 1000 = 1 second. While debugging, use short delays like delay(500) so you can see results quickly.

6. You Are Watching the Wrong Serial Port

If you have the Serial Monitor open on a different COM port than the one your Arduino is on, you will see nothing. Or if you have multiple Arduino IDE windows open, the Serial Monitor might be attached to the wrong one.

Fix: Close all Serial Monitor windows. Re-open it from the same IDE window where you uploaded the code. Check that Tools > Port shows the correct port.

7. The while Loop That Never Ends

A while loop that never has its condition become false will block forever:

void setup() {
  Serial.begin(9600);
  while (Serial.available() == 0) {
    // Wait for serial input
  }
  // Code below here never runs until you send something in Serial Monitor
  Serial.println("Got input!");
}

Or accidentally creating an infinite loop:

int i = 0;
while (i < 10) {
  Serial.println(i);
  // Forgot to increment i! This loops forever printing 0.
}

Fix: Check all while loops. Make sure the condition can eventually become false. Add a timeout or use if instead of while if you just need to check once.

8. The Code Actually Runs but the Output Is Invisible

Maybe your code works fine but you are looking at the wrong thing:

  • You are watching pin 13's built-in LED but your code outputs on a different pin
  • The display is updating but with empty strings or values of 0
  • Serial output is happening but the Serial Monitor baud rate is wrong (so you see nothing or garbled text)

Fix: Add obvious debug output that you know you will see:

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.println("SETUP RUNNING");
  // Blink built-in LED 3 times so you KNOW setup ran
  for (int i = 0; i < 3; i++) {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(200);
    digitalWrite(LED_BUILTIN, LOW);
    delay(200);
  }
}

The Universal Debug Strategy

When nothing happens and you do not know why, add "breadcrumb" prints throughout your code:

void setup() {
  Serial.begin(9600);
  Serial.println("1: Starting setup");
  pinMode(myPin, OUTPUT);
  Serial.println("2: Pin mode set");
}

void loop() {
  Serial.println("3: Loop start");
  int val = analogRead(A0);
  Serial.print("4: Analog value = ");
  Serial.println(val);
  if (val > 500) {
    Serial.println("5: Condition is true");
    doSomething();
  } else {
    Serial.println("5: Condition is false");
  }
  Serial.println("6: Loop end");
  delay(500);
}

Open the Serial Monitor and watch which breadcrumbs appear. The last one you see before things go wrong tells you exactly where the problem is.

Test Code: The "Am I Running?" Sketch

Upload this when you are not sure if your board is even executing code. It uses both serial output and the built-in LED so you have two independent ways to confirm it is alive.

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  delay(100);

  Serial.println("=== Arduino Is Running ===");
  Serial.println("Built-in LED should be blinking.");
  Serial.println("If you see this text, upload and serial work.");
}

void loop() {
  static unsigned long count = 0;
  count++;

  digitalWrite(LED_BUILTIN, HIGH);
  Serial.print("Blink #");
  Serial.print(count);
  Serial.println(" ON");
  delay(500);

  digitalWrite(LED_BUILTIN, LOW);
  Serial.print("Blink #");
  Serial.print(count);
  Serial.println(" OFF");
  delay(500);
}

If the built-in LED blinks and you see serial output, the board is fine and the problem is in your project code. Go back to your code and add those breadcrumb prints.