Troubleshooting Guide
After writing your code and attempting to upload it to your Arduino board, it might give you an error telling you it was not able to successfully upload the code. These errors are usually in red towards the bottom of the window. This guide will go over some of those errors and what might be the issue.
Uploading Code
You may get an error that says “Error uploading to board”. Before you try the following steps, click the “verify” button (the checkmark). If the code compiles with no errors then you have an issue related to uploading the code. If there are errors after clicking verify, you may have an issue with the code itself (skip to the next section).
If you get this error, you can try a few things:
- Select “Tools > board > Arduino Genuino Uno” and “Tools > port > [select the port that has Arduino Genuino Uno in parentheses]”
- The USB cable might not be plugged in all the way. Push both ends in a bit.
- Press the reset button, near the USB connector, then reupload the code.
- If all else fails, try using a different USB port on the computer or a different cable.
Code Errors
-
Missing semicolon
Missing a bracket or parenthesis somewhere
Mispelling words
You might get the error “expected ‘;’ before [function]”. With this error, you forgot a semicolon after a function somewhere in your code. Go to the line above the one highlighted, then look for a function without a semicolon after it. In the example above, notice that the “delay” function does not have a semicolon after it. Adding a semicolon (making it delay(1000);) will fix this issue).
Some errors (for example, “expected ‘}’ at the end of input”) indicate that you forgot a bracket (‘{‘ or ‘}’) or parenthesis somewhere in your code. Remember, you need an opening bracket at the beginning of void setup and void loop and a closing bracket at the end. In the example above, notice that there is no closing bracket at the end to indicate the end of void loop. Adding a bracket ‘}’ would fix the error.
You may get an error that says “not declared in this scope”. If this is the case, you probably spelled something incorrectly. Check the highlighted text to make sure you didn’t make a spelling error. If a variable is highlighted, ensure that you spelled it the way you want when you declared it.
Circuit Issues
If your code uploads with no errors, but the electronics are not doing what you want them to do, you might have an issue with circuitry. Try the following:
Wires aren't lined up right
LED in the wrong direction
Bad jumper cables
Bad components
Sometimes, the circuit isn’t working because wires aren’t lined up properly. Remember, if you want two components/wires to be electrically connected, they need to be in the same row (electricity runs the other way on the positive/negative rails). In the example above, the resistor is not in the same row as the short end of the LED; it is in the row next to it. Moving that end of the resistor to the same row as the LED will complete the circuit and make it work how it is supposed to.
LEDs have specific positive and negative ends. The positive end is the longer side and the negative end is the shorter side (it is also flat along the rim). Ensure that the negative end is connected to GND and the longer end is connected to a digital pin or to 5V. You may have to flip the LED around.
Sometimes, jumper cables break and are no longer able to conduct electricity properly. Try switching out all of the wires for new ones. If you are working on lesson 2 and you see only one value in the serial monitor (only 0 or only 1023), this is your issue!!
Sometimes components get damaged either from wear and tear or from abuse (i.e. not using a resistor). If all else fails, try switching out the component itself with a new one.
If you need more help figuring out why your code isn’t working, ask your advisor or your mentor.