Wrong USB port selected
Wrong Board profile selected
Use of TX and RX pin while uploading the code
Programming Errors
A missing semicolon at the end of a statement
In c++ you must have a semicolon ( ; ) at the end of every statement! Fortunately, the compiler will spot this one straight away. Another common typo is using a colon ( : ) instead of a semicolon ( ; ).
An uneven number of opening and closing brackets, or wrongly placed closing brackets.
This is a
Equals and Comparison
‘=' is not the same as '==’.
A single equals sign is used to assign a value:
float y = 20.4; Serial.println(y); // this will give you 20.4
Two equals is a comparator
if (test == true) { Serial.println("true"); }
You probably already know this, but it’s a very easy typo to make and it can be frustrating to spot in your code once it happens. One way to avoid the problem is to always use this shorthand version below, and stop using '==' altogether.
if (test) { Serial.println("true"); } if (!test) { Serial.println("false"); }
Float and Integer Arithmetic
A float can store values with a decimal point, and integers can store only whole numbers. What you might not realise, is that integer maths works a little different to floating point maths. On the Arduino, if you divide an integer by an integer, the result is always rounded to give an integer result.
int x = 2; float y = 9 / x; // the compiler only sees integers here, so it does integer math! Serial.println(y); // this will give you 4.00!
One way to fix the above example is to show explicitly that 9 should be handled as a float.
float y = (float)9 / x;
Or like this
float y = 9.0 / x;