Tab Content
Tab Title
Instructions
Tab Content
  1. Type: “delay(2000);” after “myservo.write(180);” and before the last curly bracket.

 

STEM Connections

This delay function will cause the program to pause and not read the next line for 2000 milliseconds (or 2 seconds).  Meanwhile, the Servo has been instructed to move to 180°, which it will do and then remain there until it receives another command.

Remember, the loop function runs any lines of code that are between the curly brackets that follow it repeatedly. So, the program will not end after it moves the Servo to 180° and pauses for 2000 milliseconds. Because these lines of code are part of the loop function, the program will return to the first line of code in the loop, which instructs the standard Servo to move to 0°.

Tab Title
Implementation
Tab Content

At the Thinkabit Lab, we provide an in-depth explanation of what it means to add the final line of code, “delay(2000);” after “myservo.write(180);” and before the last curly bracket, as follows:

  • Remind students that delay is the time that the code is not being read, and allows time for the Servo to physically get to its new position.
  • Ensure that students have written all the necessary code to control the Servo.
  • Emphasize that a missed semicolon or a word spelled wrong will prohibit your code from uploading properly.
  • Check for student understanding by asking: “Describe what the Servo would do, if there was only 1 state (or 1 command) for the standard Servo?”
  • Students should respond: The Servo would not move because it is a position based Servo. If the Servo is programmed move to one position, then the Servo will stay at that position.

 

If you are using the Thinkabit Lab Notebook:
 

Have students fill in the next blank on page 15:
delay(2000);                wait 2 seconds      

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

Tab Title
Troubleshooting
Tab Content

‘delay’ didn’t turn orange

  1. Check the spelling of the word “delay” and make sure that no letters are capitalized.

  2. 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