- Type “Servo myservo;” after “#include ” and before “void setup(){“
STEM Connections
In the LED Blink activity you used the Arduino board to control an LED by turning the voltage for pin 13 on and off. The Arduino board can also control other devices like the Servo that require instructions that are more complex than “on” or “off”. When the Arduino board will be controlling this type of device, the program that you will send to the Arduino board must be able to tell what type of device it will be controlling. This is known as declaring and naming.
The word “Servo” in this line of code declares to the program that you will be using a Servo. The word “myservo” in this line of code gives your Servo the name myservo. You could choose any name you want for the servo, but to make sure it is clear to you and anyone looking at your code in the future, we will be using the name “myservo”. The name “myservo” is also used in the Servo examples that come with the Arduino software.
Remember, syntax matters! Make sure you type everything EXACTLY as shown on the screen or your code may not upload correctly.
Servo doesn’t change orange
- “‘Servo”’ should turn orange once it’s completed as shown in the video.
- Check that it is spelled correctly.
- Check that the ‘S’ in “Servo” is capitalized and that “ervo’” is lower cased
- Check that there is a space between “Servo” and “myservo;”
1. The semicolon at the end of each line of code is like a period at the end of a sentence. If you miss a semicolon in your code, you will get an error message when you try to upload the code to the Arduino and your code will not upload.
2. Be sure students are typing this line of code before the void setup (). Every so often, students miss where they should be placing the code.
3. If the board was only capable of controlling one Servo, then you would not need to declare and name a Servo. However, the Arduino can independently control up to 6 Servos at the same time, so we want to be able to individually address them and naming them is a way that can happen. If your class moves on to controlling 2 or more servos at the same time, that is when naming will be important as you will want to name it something that makes sense.
4. Encourage students to stick with the name “myservo” at this point and change the name later if they really want to.