Warning: Be sure not to add or delete any other code at this point as this may prohibit your code from working properly.
-
In the menu bar of the Arduino software, go to "Sketch", down to "Include Library" and select "Servo".
-
Notice “#include <Servo.h>” appears at the top of your code.
STEM Connections
The code that allows the Arduino board to control the Servo is quite complex. Rather than recreate this entire code, you can use a library. A library is a large piece of code that helps the Arduino board communicate with different components like sensors or Servos. Many libraries come preloaded onto the Arduino software. The function “#include <Servo.h>” tells the Arduino software to add all the code from the Servo library into the code you are writing. You will not see this code in your window. The Arduino software will add the Servo library code before translating your code into a machine language.
Explain to students that Including the Servo library makes it easier to write code to control our Servos. If we were to control more than 1 Servo in the same code, we would only need to include the Servo library once.
If you are using the Thinkabit Lab Notebook:
Have students fill in the first blank on page 15:
#include <Servo.h> include the Servo library
Alternatively, you can write the entire code on the computer and fill in the notebook at the end.
Can’t find ‘Servo’ in Sketch>Include Library
- It’s there, keep looking
Can’t find “#include <Servo.h>”
-
Check the very top of the sketch code
-
Try this step again