Alexis Santos

Creative Technology Consultant at Dangerously Creative, Producer of Shoot The Moon. Formerly, Engadget Contributing Editor and Head of Content for Binpress. Writer, podcaster, developer. New College of Florida alum. Loves entrepreneurship, technology, archaeology, and anthropology.

The Blog

Arduino Debugging Guide: Or how I learned to stop worrying and preserve my sanity

By Alexis Santos | July 23, 2016, 7:52 p.m.

Arduino projects blend code and the physical world, which is what simultaneously makes them a joy to work on and an absolute nightmare to debug. I’ve compiled a list of gotchas that have thwarted me at some point or another in the hopes that it’ll help others claim victory over roadblocks. Some tips are technically insightful while others are mistakes worthy of The Three Stooges.

This a living list, so I’ll add gotchas and tips as I run into them. If there are any you’d like to add, shoot me an email and I’ll include it!

Nothing is working! Why isn’t anything happening. Nothing’s even showing up on the serial monitor!

Are you sure the loop is running more than once? It might be getting caught up somewhere. Toss in an ol’ Serial.println("Looped!"); at the bottom of your loop.

My serial monitor isn’t showing anything. Or: My serial monitor’s output is all garbled.

Check your baud rate. You may be listening in at one baud rate while your project uses another.

Things just aren’t acting right. They should be, but they aren’t. I’ve triple checked the code. It. Makes. No. Sense.

  • Your sketch might be trying to use more RAM than it has available. Things will tend to go bonkers in unpredictable ways when you’ve written a RAM-hungry program.
  • Not Using The Right Arduino If your workspace is anything like mine, it goes through phases of chaos. Often, there will be at least two of the same Arduino boards, with USB cables attached, sitting on my desk. This could be a problem.
    • Are you uploading code to the right Arduino?
    • Are you listening in to the right Arduino on the serial monitor? Check your com port.
  • Is your sketch using the pin your sensor/LED/etc. is really attached to?
  • Does your sketch have a pin assigned to two different sensors/LEDs/etc.?
  • Does your sketch do something that’s somewhat sensitive to timing? It might be getting ahead of itself or stepping on some other function. Pepper in a delay(1000); or two around spots you suspect may be culprits.
  • Two or more of your libraries may be competing to use the same timer.
  • Are you powering your board correctly? While it may be receiving power over USB, you might be forgetting something attached to a breadboard that needs a power supply.
  • Your project might be using too much current. Figure out how many milliamps/Amps each component of your project draws, and how much your project can supply. Strange things happen when your current draw is too high.
  • Is there a short? Mayhaps some solder is connecting two pins in a case where never the twain should meet. Check for short circuits!
  • Maybe your Arduino’s MHz is affecting things. TMRpcm’s audio library, for example, is tuned to work on boards running at 16MHz. If your board is running at 12MHz, the audio will play slower. (If that’s the case, speed up your file by 33.33% in Audacity, and you’ll be golden.)
  • Question every assumption. “There’s no way INSERT HERE would be causing this problem.” It probably is.
  • Are you sure you connected [insert component here] to power and ground? You might have missed the right hole in the breadboard by one.
  • Did something come loose in transit? Makes sure jumpers and other things that can be jostled about are in the right place.

Last Ditch Tactics

  • DELETE ALL THE CODE: Anyone who’s programmed before knows this tactic well. Once you’ve backed everything up — you are using git, right? — reintroduce bits of code and run the sketch after each chunk. You’re bound to find the section of code that’s fouling things up.
  • UNPLUG ALL THE THINGS: This is the hardware equivalent of the tried and true DELETE ALL THE CODE. Hopefully, you’ll do this while still using a breadboard. Unplug all your LEDs, sensors, etc., and run the sketch as you plug each one back in. In some instances, you may want/have to do this while deleting/reintroducing the pertinent code, too.