Tab Content
Tab Title
Instructions
Tab Content
  1. Type “Servo myservo;” after “#include <Servo.h>” 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, which 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.

Tab Title
Implementation
Tab Content

At the Thinkabit Lab we emphasize that placement of the code is important, as well as the naming of the Servos, as described below.

  • Tell students that the semicolon at the end of each line of code is like a period at the end of a sentence. If a semicolon is missing from the code, the code will not be uploaded to the Arduino board and will also generate an error message. Ensure students are typing this line of code, “Servo myservo;” before the void setup (). Every so often, students miss where they should be placing the code.

  • Encourage students to keep the name “myservo” and change it later, only if it is important to them do so.

  • Explain that the Arduino Uno can independently control up to 6 Servos at the same time, but each Servo must be named for it to function. If students need to control 2 or more Servos at the same time, then each will need to be named. A good tip is to have students name the Servo with a name that makes sense, for example, based on functionality (bigservo and smallservo).

  • We also explain that it is also possible for the Arduino Uno to only control one Servo and does not need to be declared and named, but it is good practice to do so.

 

If you are using the Thinkabit Lab Notebook:
 

Have students fill in the next blank on page 15:
Servo myservo;              names the Servo 'myservo'           

Alternatively, you can write the entire code on the computer and fill in the notebook at the end.

Tab Title
Troubleshooting
Tab Content

Servo doesn’t change color to orange

The word “Servo” should turn orange once the code to declare the Servo is entered as shown in the video.  If not, check the following:

  1. Check that words are spelled correctly.

  2. Check that the ‘S’ in “Servo” is capitalized and that ‘servo’ is lower cased.

  3. Check that there is a space between “Servo” and “myservo;”

  4. If it changed colors to a different color, the Arduino software may have been updated.  As long as it is colored, the code should still work properly.

Instruction Category
Video