- In the menu bar of the Arduino software, go to Sketch>Include Library>Servo.
- Notice “#include ” <Servo.h>" appears at the top of your code.
Warning: Be sure not to add or delete any other code at this point as this may prohibit your code from working properly.
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.
Can’t find ‘Servo’ in Sketch>Include Library
- It’s there, keep looking
Can’t find “#include ”
- Check the very top of the sketch code
- Try this step again Teacher notes
Notice there are 3 wires on the Servo. The red and black lead are for the positive and negative sides of power, respectively, and the white lead is for the PWM signal. The PWM signal comes in a certain shape and the Servo will behave differently depending on this shape. This is like how your heart rate has a certain shaped signal. Depending on the shape of the heart signal, you could learn different pieces of information about it. Including the Servo library makes it easier to generate the correctly shaped signals.