Before coding, let's get familiar with the IDE. Here is some vocabulary and where to find the different parts.
We will show you:
|
This is a video of IDE basicsIf you are doing this on your own at home, this video teaches you what we did in class.
|
|
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's code to blink the Arduino
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) Are there curly brackets, { } If you get no error (the bottom box is not orange), then you can move on. Still having issues? Let your teacher know! |
If you are having issues, read this.
You may not be used CaPiTal lEttErs maTterING! Things change color as you type them correctly. The words like OUTPUT, HIGH, setup, 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 ] .
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 ] .
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.
To fix this, click the select board drop-down and select your 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.
To fix this, click the select board drop-down and select your 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 you need help.
Give the board a second to upload, it should be blinking quickly, and then run your code. Let your teacher know you need help.
SaveNow that you have made your first successful code, you should save it.
Name it something memorable so you can always find it again later. Your teacher will show you how, or you can watch this video. |
|
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")
Save your new code using a different name. (maybe: "MultiBlink")
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.
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.
Lesson 2:
Controlling "off-board" LEDs
It is important to know LEDs only let current flow through it one way.
If your light does not turn on, try flipping how your LED is connected. It may just be in backwards. |
LEDs only work when the longer end connects to positive pins on the board. The + pins on the board are any of the numbered pins, the 3V, or the 5V.
|
How to find the 220 Ohm resistor?
Your kit may or may not have the resistor values written on your strips. If it does not, you will have to find the 220 Ohm resistor using the color combinations on the resistor. To learn how to do that, go to this lesson and your teacher will help you learn how to do this.
<--Use this button to learn how |
Watch this video if you need help for how to do it. |
|
Lesosn 3: Introducing a Breadboard:
It Connects Many Parts Together
It has different rows and columns all connected together under the holes.
This picture shows which parts are connected. You may have a smaller board than this, but this picture still shows the basics.
This picture shows which parts are connected. You may have a smaller board than this, but this picture still shows the basics.
Watch this for more about how breadboards work
Now, let's use this board to connect a bunch of lights!
Lesson 4:
Series and Parallel Circuits (LEDs)
Now that you got one light to work on the board, let's try to get lights to work off of the Arduino board. See if you can get several lights to turn on at once. Try hooking up your lights in these three different ways. How are each different. Is the brightness any different?
This activity does not need any code. It plugs directly into the 5V (aka +) and the Ground lines (GND aka -). Plugging those wires in is just like using a battery.
Remember: plug in your Arduino with the USB cord!
This activity does not need any code. It plugs directly into the 5V (aka +) and the Ground lines (GND aka -). Plugging those wires in is just like using a battery.
Remember: plug in your Arduino with the USB cord!
LEDs are Light Emitting Diodes. Light Emitting means they make light. A diode is something that only lets electric current go one way. That means direction matters! The longer LED wire is the + side, and the shorter LED wire is the - side.
Tip: use black wires to connect - parts (aka GND) and red wires to connect + parts (aka 3.3 or 5V lines) See how that is done in the pictures above? |
Connect your lights to the breadboard like the pictures above. See what changes between each type of setup (single, series, parallel). Can you figure out how to power all three setups off the same board? Once you get your lights to work in parallel, try to use different colors. What happens when you try to use all different colored lights?
It is ok if you don't understand how all this works today.
The more we practice, the more you will get!
Ask your teacher if you have any questions or need help.
It is ok if you don't understand how all this works today.
The more we practice, the more you will get!
Ask your teacher if you have any questions or need help.
Lesson 5: Defining Variables at the start of code
Here is the example multi-blink code from earlier. See how we have to keep typing LED_BUILTIN over and over? We can avoid that by making what is called a "variable". Variables are easily able to be adapted/changed. If you have taken algebra, think solving for x, where x is the variable!
What if we wanted to change which light to turn on? We would then have to then retype all of the LED_BUILTIN parts, gross! If we make a variable for the light at the start of our code? Then we will only have to change the pin we want to light up in just one spot! |
See this small change we added to the beginning of our code, line 1?
This is the variable we are defining. Const means constant. That means we are telling the computer that this variable will not be changing when the code runs. int means integer. An integer means whole numbers. Integers are numbers like 1, 5, 22, etc. LED_BUILTIN is actually connected to Arduino pin 13, so we could have just typed in 13 there if we wanted. |
This video explains how to use variables
Changing the variable changes the pin to light up!
Now that we have made that variable, we can control other lights too!
We can control lights connected to any Arduino pin using our blink code now. I can do that by changing the ledPin variable. Your teacher will now show you what that means. You can control your off-board LEDs using your blink code now : )
We can control lights connected to any Arduino pin using our blink code now. I can do that by changing the ledPin variable. Your teacher will now show you what that means. You can control your off-board LEDs using your blink code now : )
This video shows some of what you can do!
Lesson 6: Analog Write Blink off-board LED
Look on the rail of your Arduino. Some of the digital pin row numbers have a ~ symbol. The ~ means PWM (Pulse Width Modulation). Modulation means it can modulate up and down from various values. The digitalWrite we used before just uses on and off. If you move your wiring to use one of these ~ pins, like ~3, we can make it blink with different brightness.
|
Give this a try. Send it to your board and see if your light blinks at different brightnesses.