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”.

Operators traced an error in the Mark II to a moth trapped in a relay, coining the term bug. This bug was carefully removed and taped to the log book. Stemming from the first bug, today we call errors or glitches in a program a bug.

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 a integer number or a stringof 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):

and 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!

One of the things that gets beginners is that even a short power disconnect will cause the Arduino module to restart and this can change the USB assignments. Typically I use a wire split with both outputs going to an Arduino input so if one falls off the other keeps the power on. Also the Arduino module is sensitive to low battery voltage. So use a fresh battery if in doubt or a USB power module. Note the USB connector on the Arduino module does not provide power.

1 Like

Hey Peter (and other Arduino enthusiasts), for those brave souls who want to power their Arduino modules, here is an unofficial, yet littleBits’ sanctioned modification you can do to power it from the USB connection:


@codewizard58 these are all awesome notes. I’ll add them to the project page post as well if you don’t mind! (i’ll be sure to credit)

Hey @chris101, can you clarify what bridging the two tiny pads does? I don’t see the connection between the blob of solder and the USB power. :confused:

Hiya @Thingfully,

What it does is connect the USB power to Vcc, so that when you have your Arduino connected to the USB device it’s powered on, and you don’t need to have a power bit attached to it. I like this, because I program the Arduino on my desk, but build my circuits on a work-table. With the jumper, I don’t need to move anything but the Arduino bit from location to location.

How it does it, is to connect the +5 volt line in the USB connector directly to the +5 volt buss in the bit. You can see it on the left edge of the Arduino bit’s schematic. The idea came from littleBits’ engineer, Rory:


Thanks. Transparency rocks!

(I might have the wrong cable I don’t know) I connect my Arduino Module and it doesn’t show up anywhere and I power it with the power module full battery. I tried restarting my PC and that didn’t help. If I have the wrong cable, Please give me a link to buy the right one.

Thanks :grinning:

If you have the short USB cable - one end fits into a usb jack on your computer, and the other end fits the micro USB on the Arduino bit, then it’s the right cable. I have 2 Arduino bits, and one of them is not recognized by my computer. I program it through the ICSP pins (those 6 holes in the lower middle of the bit), but that is not a procedure I recommend to beginners.

I wonder if the littleBits engineers have come up with a solution (or fix, or workaround) to this common* problem? I have OSEPP Arduino clones that do the same thing, they have a patch, that worked on one, but not the other. Sometimes I hate computers.**

*Google “Arduino not found”.

** Did I say that out loud? :stuck_out_tongue:

Hi @Ghoster2004 @Thingfully @chris101 @codewizard58 @syedBits @system,

I tried a few different setups with my Arduino bit W6.
I found out that there are two different types of USB cables. They can be suitable for power charging ONLY and they can be suitable for power charging AND data transfer. :joy:
As far as I can see there is no difference you can see in the plug design.

The little black short cable that came with the Arduino Coding Set works fine for data transfer and the 1.5 meter long white cable that came with the wall power supply in the Smart Home Kit also works fine for data transfer.

I own several other USB cables that are only suitable for power charging.
They look exactly the same and have no different markings at all…
When you connect those type of cables with the Arduino when powered up, nothing happens.
When doing this with the correct cable, the RX led flashes once.

With the wrong cable the IDE shows this under tools/port selection:

Clicking on this port does not help.

When using the correct cable, the IDE shows a new COM port with the Arduino Leonardo name mentioned behind :

Clicking on this port will connect the Arduino and it works !

1 Like

@alexpikkert, thank you for this! I will be demonstrating the cloudBit™ at the East Bay Mini Maker Faire in Oakland, CA next month and lost the USB powerBit that came with the cloudKit.

1 Like

When I turn on my arduino the left d0/rx light comes on but th d1/tx light does not. I get an error message stating that “Board at Com1 is not available.”

Hello @cdiettersmith,
Please take a look at the following forum topic:

Maybe you find a solution there… :grinning:

Thank you Alex, I figured it out.

1 Like