Whenever someone sends me some code that doesn’t work, there are a few common Arduino programming mistakes that I check. Some of these mistakes I make myself.  In most cases my code will compile just fine. Sometimes, these mistakes won’t generate any compiler error.

When my Arduino code is acting up, these are the first things I check. Here are my 5 common Arduino programming mistakes, I use to debug non-working code.

What was one of the first things you were taught, when learning to program?  “Comment Your Code!”  And of course, like all programming students, you ignored that advice.  Or, if you are like me, you made vague comments as the lines of “variable called var.”

Tonight I opened up some code I haven’t touched in two years.  Code that when I wrote it, made perfect sense to me… at the time.

The code was for my binary clock project, BinBoo.  So I need your help, check out the code below and see if you can help me remember what it does!

Warning, the title of this post is a little bit misleading. It isn’t just one-click to get cleanly formatted code, it’s actually two.

There are two things seasoned programmers will tell new programmers, that they don’t understand (at first):

  1. Always comment your code
  2. Properly indent code

The problem?  As a new programmer, you might not know how to do #2 until you get some experience.

There is one mistake that all C programmers make, regardless of experience.  You’ll do it often when you get started, but never completely stop.  The mistake?  Confusing the “assignment” operator with the “comparison” operator.  Take a look at this line of code:

[cpp] if (something = 0) {

Notice the problem?  If not, then you might fall into this common trap.  The most annoying part?  A C-Compiler won’t give an error.  That code is legal C.  Legal code doesn’t mean you’ll get the results you expect.  In fact, this is probably not even close to what you wanted.   This simple mistake and why it “works” is explained below.