Lesson 1: Learn How to Code!
We will start with writing simple code, saving, and sending it to the Arduino. Let's start by getting the board's orange light to blink like this.
Here is the code that makes the Arduino blink
|
One big thing that you may not be used to is that CaPiTal lEttErs maTter! Things change color as you type them correctly. The words like OUTPUT, HIGH, and LOW will not change colors if you type them wrong.
Another thing that you may not have seen before is an under-script, it looks like this _. To type _ you have to hold shift and - at the same time. The minus is beside the 0 (zero). |
Another new thing is every line of code ends in a ; semicolon. That button is beside the L.
You also may not have seen a curly bracket { } before. That can be found next to the P key. To make a {, hold Shift and [ . To make a } hold shift and ] .
Type in the blink code into Arduino IDE.
If you do not have Arduino IDE yet, directions are in the preacademy prep page. Click here to see the directions.
You also may not have seen a curly bracket { } before. That can be found next to the P key. To make a {, hold Shift and [ . To make a } hold shift and ] .
Type in the blink code into Arduino IDE.
If you do not have Arduino IDE yet, directions are in the preacademy prep page. Click here to see the directions.
See if you get an error message?
|
If you got an error message, check the following things.
1) Are all the colored parts in this picture here colored in your code? 2) Check CaPiTaL letters. (they matter) 3) Have you forgotten a ; 4) You may have forgotten a ( or ) 5) Did you type the curly brackets, { } If you get no error (bottom box is not orange), then you can move on. Still having issues? Let your teacher know! |
What is your Arduino doing? Is the code working?
Below explains what each line of code is doing.
|
The // double dashes are just comments. You do not need to type them. The Arduino does not do anything with them. They they help people know what each line of code is supposed to do.
Remember, this video shows what the Arduino should be doing. |
|
Did you get an error? (Is it working right?)
You may get a "Problem uploading to board" or something similar.
If you do, it is because your Arduino does not know where the Arduino is plugged in. Or, your USB cord may not be plugged all the way in.
Follow the steps in the picture below if you get the Port Error.
Open the tools tab, Port, and select the port COM that says Arduino.
If you do, it is because your Arduino does not know where the Arduino is plugged in. Or, your USB cord may not be plugged all the way in.
Follow the steps in the picture below if you get the Port Error.
Open the tools tab, Port, and select the port COM that says Arduino.
Step 4) If you fixed the port issue if needed, push the arrow button beside the check box at the top again.
Give the board a second to upload, it should be blinking quickly and then run your code.
Let your teacher know if it still does not work and you need help.
Give the board a second to upload, it should be blinking quickly and then run your code.
Let your teacher know if it still does not work and you need help.
Learn how to Save
Now that you have made your first successful code, you should save it.
Name it something memorable so you can always find it again later.
Name it something memorable so you can always find it again later.
Watch this video to learn how to save
After Saving, try changing the code
|
Play around with the code's delay values. Right now it is 1000. Try changing it. What does changing it do? Re-upload to the board after you try it.
Save your new code using a different name. (maybe: "MultiBlink") If you have time, try something creative like adding more HIGH and LOW lines into the loop code to make cool patterns. This can be done like the example below. Adding more lines to add blinking complexity. |
Save your file, upload to board, and review
Plug the Arduino board into one of your computer's USB ports.
After it is plugged in, upload the code to the board. Click the right arrow beside the check mark at the top of the Arduino program. See the picture below for what that looks like.
You just made your first Arduino program! Congratulations.
After it is plugged in, upload the code to the board. Click the right arrow beside the check mark at the top of the Arduino program. See the picture below for what that looks like.
You just made your first Arduino program! Congratulations.