Introduction to Arduino Programming 5: Troubleshooting Your Code

Why you buggin’: Troubleshooting your Arduino!

One of the most frustrating moments of your early programming career will be getting used to debugging your programs. I won’t sugar coat it, it’s not fun at first. Once you’ve mastered your tools though, you’ll feel more confident and better at squashing them.

A fun fact Grace Hopper, an incredibly influential computer scientist had one her “computer operators” (as they used to be called back in the day) remove an actual bug from a program that had “bugs”.

src: wikipedia


Red red console

Most common errors when you first program are syntax errors ! Remember that statements like:

Need semicolons!

Also functions like analogWrite need two arguments, one being the output snap you are turning on and the amount of electricity you’d like to send it.

As far as variables go don’t forget to telly your Arduino what type they are. They Arduino can’t read minds (YET) so you’ll need to indicated if your variable is an integer, number, or string of characters.

Lastly you’ll enter all your code in-between the setup and loop { } curly braces. Depending on what function you’re calling, code like Serial.begin(9600) will be in setup() and Serial.println(“hello”) will exist in loop().

Following the clues

Look closely at the bottom of the gif we just saw, you’ll see a little message about what and where things went wrong.

Sometimes the messaging can be cryptic, but it will give you some clues as to what went wrong syntactically (what language rules were broken) and where it happened.

You’ll be given a line number in the error message telling you where you can hunt down the bugs. You can find line numbers of your code on the bottom left of the IDE.

Note! Errors can happen at or before the line number indicated by the compiler / IDE.


Uploading remedies

This is so important that it needs it’s own heading! If you can’t your program to run or if your Arduino is stuck on “Uploading…” like this:

Then try some of these homemade remedies!

  • First things first: BEFORE you open the Arduino IDE , you have to create your circuit or at least turn the Arduino on. The IDE does not automatically pick-up your module sometimes.
  • Make sure the right port and board are selected, if you don’t know what that means look at this guide.
  • If you don’t see the correct port or board try turning it of and turn it on. Restart the Arduino IDE or restart your Arduino (with USB cable hooked-up to your computer):

  • If that doesn’t help try restarting your computer.
  • Look out for the lights you’ll know your program is being uploaded when you see this sequence of lights, it shouldn’t take more then a few seconds:

  • Don’t give up! Rinse, repeat and you’ll be coding in no time!

More Tips & Tricks

Tips & Tricks
Synth Tips & Tricks: Connect To Other Instruments

Hi Synthsters! Did you know that you can combine your Synth Kit with other instruments? In this blog tutorial, we will show you ho...

Tips & Tricks
Tips & Tricks: Cloud Module

Welcome to the cloud! With the cloudBit, now you can snap the internet to anything. We’ve compiled a number of fun and useful tips...

Tips & Tricks
Tips & Tricks: Mounting Board

      The mounting board allows you to keep your circuit intact and move it around with ease! It can, at times, req...