Tab Content
Tab Title
Instructions
Tab Content

Challenge 1:

Try modifying the code to make the continuous Servo spin only one way, for example to the left, but still have the standard Servo move back and forth from 0 to 180 degrees with a 2 second pause at each stop.

Challenge 2:

Try modifying the code to make the standard Servo move back and forth faster (maybe a delay of 500), but keep the continuous Servo changing directions every 2 seconds.

Tab Title
Implementation
Tab Content

The challenges include at least one possible solution as they are a bit more difficult than the single Servo activity. The difficult concept for students to understand is that the delay is causing the Arduino to pause, not causing the Servo to spin or stay. The Servo does what it is programmed to do until it gets a new command. To best illustrate this, enlist 2 student volunteers and have one represent the regular Servo and the other represent the continuous Servo. You, the teacher, represents the Arduino. So as you read through the lines of code, you will be giving commands to the Servos when you read the “.write” lines of code and then pausing during the delays.

Challenge 1:

void loop(){
  standardServo.write(0);  //standard Servo goes to 0 degrees
  continuousServo.write(0);  //continuous Servo spins fast to the left
  delay(2000);    //wait 2 seconds
  standardServo.write(180);  //standard Servo goes to 180 degrees
  delay(2000);    //wait 2 seconds
}

Challenge 2:

void loop(){
  standardServo.write(0);  //standard Servo goes to 0 degrees
  continuousServo.write(0);  //continuous Servo spins fast to the left
  delay(500);    //wait ½ second
  standardServo.write(180);  //standard Servo goes to 180 degrees
  delay(500);    //wait ½ second
  standardServo.write(0);  //standard Servo goes to 0 degrees
  delay(500);    //wait ½ second
  standardServo.write(180);  //standard Servo goes to 180 degrees
  delay(500);    //wait ½ second
  standardServo.write(0);  //standard Servo goes to 0 degrees
  continuousServo.write(180);  //continuous Servo spins fast to the right
  delay(500);    //wait ½ second
  standardServo.write(180);  //standard Servo goes to 180 degrees
  delay(500);    //wait ½ second
  standardServo.write(0);  //standard Servo goes to 0 degrees
  delay(500);    //wait ½ second
  standardServo.write(180);  //standard Servo goes to 180 degrees
  delay(500);    //wait ½ second
}

Note: It is not incorrect to give both Servos an action for each delay (like the code below), but it is unnecessary. Once the Servo’s action has been programmed, it will continue to do that action until being programmed to do something different.

Challenge 1 (with unnecessary continuous Servo command added):

void loop(){
  standardServo.write(0);  //standard Servo goes to 0 degrees
  continuousServo.write(0);  //continuous Servo spins fast to the left
  delay(2000);    //wait 2 seconds
  standardServo.write(180);  //standard Servo goes to 180 degrees
  continuousServo.write(0);  //continuous Servo spins fast to the left (unnecessary)
  delay(2000);    //wait 2 seconds
}

Tab Title
Troubleshooting
Tab Content

Remember, any time code is modified, it must be uploaded to the Arduino board in order for the change in the Servos to be seen. If an error appears while trying to upload, try to read the error message and fix the problem. 

If the Servos do not move as intended, remember that the servo.write command gives instructions to the Servo while the delay causes the Arduino to pause.

Instruction Category
Video