MANAGING THE ARDUINO CODE
STEP 3 – EDIT THE CODE
Try to Compile the Code
Now that you have figured out the correct order of your code, you can try to compile it. What does it mean to compile the code? It’s a way for the IDE to check your code to make sure there aren’t any problems with it.
To do this, with your sketch open, click the check mark at the top left corner of the IDE. The IDE will go through each line of code and look for issues with code syntax, undeclared variables, missing libraries and functions, and other stuff like that. If it finds any problems, it will highlight the problematic lines in the sketch and tell you what the issues are at the bottom.
Running the Arduino IDE Compiler
Set the Arduino Pins
The IDE should have found some errors with your sketch. It turns out that the code blocks you downloaded do not actually tell the Arduino which pins the electronic components are connected to. You will need to add the pin numbers yourself. There are five places in the code where you’ll have to do this. Find the following five dummy variables:
In the code, replace these dummy variables with the correct Arduino pin numbers. How do you know which pin numbers to enter? There are hints in the code. You can also just look at where the wires are connected to the Arduino.
Name the CSV File
There’s still one last thing you need to do before moving on. In the code, find the lines that include
INSERT_CSV_FILENAME. You will find this wherever there is an
SD.open() function. Replace
INSERT_CSV_FILENAME with whatever you want to name your data file. However, the file name must:
- Be written inside double quotations
- Have a length of eight characters (letters and numbers) or less
- Be followed by the .csv extension (e.g., “myfile.csv”)
This will allow the Arduino to create a comma separate value (CSV) file to store all your data. Make sure to use the exact same name each time! Also, if your file name is longer than eight characters, the code may still run but won’t create or save the file. In other words, the Arduino won’t save your data! This happens because the built-in SD card library only recognizes file names that have eight characters or less.
After you have made these edits, check to see if the code now compiles successfully. If it does, then you may move on to the next step.