Common Arduino Problems
Wrong USB port selected
Wrong Board profile selected
Use of TX and RX pin while uploading the code
We are allowed to use the TX and RX pins as general purpose inputs or outputs (GPIO), which are pins 0 and 1 on the Arduino Uno. However, these pins are primarily intended for serial communication, and are in use when uploading to the board, or communicating with the serial port. So, avoid using them unless you really need to use every single GPIO pin on the board (perhaps you could consider a shift register instead)
Serial port in use when uploading
While trying to upload code to the Arduino, the serial port can’t be used for anything else. The Arduino IDE will automatically close the serial monitor if it's in use, but you might have another application trying to use the same port as the Arduino, for example, a processing or p5js sketch that interfaces with your Arduino.
Reset button before uploading the code
Some Arduino-based boards will like to be reset immediately before uploading to the board. Check the particular model online for advice on how to use the reset button.
You can also run into trouble uploading if the code is using the serial port heavily. With some trial and error, pressing the reset button at just the right moment before uploading can solve the problem.
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 another easy mistake to make, that can cause a real headache. The compiler will recognise that there is a missing curly bracket, but it has no way of knowing where you intended to place it. Typically the compiler will indicate that the bracket is missing at the end of the code block at the last possible place it could be placed. However, this is probably not where it should be! Take great care to go through your code line by line if you ever get a missing bracket message, and ensure it gets put back in the right place.
If you have your code split into multiple tabs in the Arduino IDE, then the compiler will often indicate that the bracket is missing from the wrong tab.
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.
One way to fix the above example is to show explicitly that 9 should be handled as a float.
Or like this
Â
Â