Other Debugging Techniques
- Ask someone else to look over your project. We sometimes become blind to our own mistakes. Don’t tell the other person what connections you meant to make; have them verify that you have correctly implemented whatever schematic you are working from. This way, you don’t prejudice them to see what you intended to do and miss the mistake. If you don’t have a schematic, you should make one. Of course, the schematic might also have a mistake, which will be the next thing to check.
- “Divide and rule” works for sketches, too. Save a copy of your sketch, and then start removing the parts of your sketch that don’t have anything to do with the part that is giving you trouble. You might find an unexpected interaction between something that seems to be working fine and the problem. If this doesn’t solve your problem, it will provide the minimal test program that demonstrates your problem, which will make it easier when you ask for help.
- If your project involves any sensors (including switches), test each one individually with the most basic appropriate examples: AnalogReadSerial and DigitalReadSerial, which you can find at File→ Examples→ 01.Basics→ AnalogReadSerial/DigitalReadSerial.
- If any sensor fails, verify that the Arduino input is working correctly. Disconnect your sensor, and connect a jumper from the suspect input directly to 5V and GND (one at a time, obviously), while monitoring with AnalogReadSerial or DigitalReadSerial. You should see 0 when the input is connected to GND, and 1 or 1023 when the input is connected to 5V.If you have multiple sensors and one is failing while others work, swap parts of the circuit (one at a time) between the one that works and the one that fails, and see if the problem moves.
- If your project involves any actuators, test each one individually with the most basic appropriate examples: Blink or Fade. If the actuator fails, replace it with an LED to make sure the Arduino output is working correctly.
- If your sketch involves decision making, such as
if
statements, use the Serial.println()
function to tell you what it’s doing. This is also useful in loops, to make sure the loop is starting and stopping when you think it should.
- If you are using any libraries, verify they work correctly using the examples that came with them. If you are having trouble with a library that is not from Arduino, see if there is a forum or other online community for that library and join it.
- If these suggestions don’t help, or if you’re having a problem not described here, search for “troubleshooting” at arduino.cc.
Leave a Reply