Why Does My Code Compile But Not Work?
If the code compiles, the syntax is fine. The problem is usually logic, wiring, or timing.
Top causes
- Wrong pin number: code and wiring do not match.
- Missing pinMode: pin never configured as input or output.
- Bad wiring: loose breadboard connections.
- Wrong board or port: code uploads to the wrong device.
Fast debug steps
- Test with the Blink example.
- Print values to Serial Monitor.
- Check wiring against your pin numbers.
Bottom line
Compiling only checks syntax. If it runs wrong, verify wiring and add debug prints.
Related: How do I use Serial Monitor correctly? · Why do I get expected semicolon before...? · Why does my loop run too fast?