How to read an Arduino sketch
Understand setup(), loop(), pin configuration, input decisions, outputs, timing, and the role of drivers.
Find the program flow
setup() runs once after reset. It commonly configures pins, starts serial communication, and initializes libraries. loop() runs repeatedly, so read it as the device's recurring decision cycle.
Trace one path through the code: input reading → decision → output command. Then identify where the load receives its actual power. A GPIO command may control a driver; it is not necessarily the load's power path.
Follow the names and units
Look for constants that name pins, thresholds, durations, and device addresses. Check the board-specific meaning of each pin and the units expected by each library. Print raw measurements before tuning thresholds.
Some sketches use delay(), which pauses ordinary loop work. Others use millis() to schedule tasks while the loop continues. Inspect what the actual sketch does rather than assuming a timing pattern.
Change one thing at a time
- Compile the unchanged sketch for the exact board.
- Identify one input and one output in both the code and wiring.
- Change one constant or condition, then compile and test with the load made safe.
- Record what you expected and what you measured.
General checks do not replace the exact board and component documentation. Find a project guide.