Trying out the Servo (1st activity)
We first have to learn how servos work.
Step 1) Wire up your servo like this.
1) The brown/black wire goes to GND 2) The red wire goes to 5V 3) The last wire goes to pin 9 (Note, the last wire could be several different colors) You can actually plug your servo's orange cord to any pin, just make sure to type that pin number in myservo.attach(#) where # is what you plugged in. Notice the example picture is plugged into 9? |
The Code
Type in the code below. Remember that text after // are just comments. You do not need to type the // or what comes after them. They are just there to tell you what that line of code does.
Tip: The # symbol for #include is made by pushing shift and 3 together.
Tip: The # symbol for #include is made by pushing shift and 3 together.
Step 2) This code uses the < > symbols. Those are next to the m key.
To get the < symbol, hold shift and the , key. To get the > symbol, hold shift and the . key
Step 3) Validate the code like yesterday's activity using the check box button the upper left. Here is a link if you need a reminder: https://www.rcccamp.org/day-1-monday-basics-and-lights.html
Step 4) Did you get an error? If so go through the checklist:
a) Are all the colored parts in this picture colored in your code?
b) Check CaPiTaL letters.
c) You may have forgotten a ;
d) You may have forgotten a parenthesis ( or )
e) Did you type the curly brackets? { }
If you get no error, then you can move on.
Step 5) Upload the code using the right arrow symbol (top left)
*remember that "problem uploading to board" means you have to change your port.
to do that go to: tools, port, and select Arduino
Step 6) Is it working? If so, that's cool! Save your work!
*If it is not working, a common thing is that your wires have some glue stuck on the metal ends. Use your finger nails to rub any glue off of the wires you are using.
Once you get it to work, feel free to play with the numbers on the code and re-upload it to see how those numbers effected the servo.
To get the < symbol, hold shift and the , key. To get the > symbol, hold shift and the . key
Step 3) Validate the code like yesterday's activity using the check box button the upper left. Here is a link if you need a reminder: https://www.rcccamp.org/day-1-monday-basics-and-lights.html
Step 4) Did you get an error? If so go through the checklist:
a) Are all the colored parts in this picture colored in your code?
b) Check CaPiTaL letters.
c) You may have forgotten a ;
d) You may have forgotten a parenthesis ( or )
e) Did you type the curly brackets? { }
If you get no error, then you can move on.
Step 5) Upload the code using the right arrow symbol (top left)
*remember that "problem uploading to board" means you have to change your port.
to do that go to: tools, port, and select Arduino
Step 6) Is it working? If so, that's cool! Save your work!
*If it is not working, a common thing is that your wires have some glue stuck on the metal ends. Use your finger nails to rub any glue off of the wires you are using.
Once you get it to work, feel free to play with the numbers on the code and re-upload it to see how those numbers effected the servo.