Try out the continuous rotation servo. You control the continuous rotation servo by writing a speed to it instead of a position.
Example 4.2
In this example, you will use the exact same code as in the previous example, but this time with a continuous rotation servo.
Materials
- 1 Arduino Uno board
- 1 Education Shield
- 1 continuous rotation servo
Instructions
- Attach the shield onto the top of the Arduino board.
- Connect the continuous rotation servo to D9.
- Upload the following code:
Result
The servo should spin in one direction for one second, then spin in the other direction for another second, and repeat.
New commands
servoName.write( speed )
: makes the continuous rotation servo rotate with the specified speed.speed
can be a value between 0 and 180 where 0 is full speed in one direction and 180 full speed in the opposite direction.
How it works
- The Servo library is included.
- The Servo object
myservo
is declared. - In
setup()
,myservo
is attached to pin 9. - In
loop()
, the servo shaft is rotated continuously with speed 0, full speed counter clockwise. - The program pauses for 1000 milliseconds.
- The servo shaft is rotated continuously with speed 180, full speed clockwise.
- The program pauses for another 1000 milliseconds.
loop()
continues to loop.
Learn by doing
- See what happens when you change the values inside the
write()
function. - Determine the value that makes the servo stop rotating.