Tab Content
Tab Title
Instructions
Tab Content
  1. Type: “delay(2000);” after “myservo.write(0);”

STEM Connections

As we learned in the LED Blink activity, the delay function can be used to adjust how long a computer program pauses between running lines of code. Writing “delay(2000);” will cause the program to pause for 2000 milliseconds (or 2 seconds) while the Servo moves to 0 degrees and remains there. If you don’t give it a long enough delay, it may not have time to reach the angle.

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.
Tab Title
Implementation
Tab Content
  1. Ask students: Thinking back on the LED Blink code, what would cause the Arduino to pause before from reading the next line of code?
    Answer: a delay.();
     
  2. While the program pauses during this delay before it reads the next line of code, all previous actions will continue. For example, if the Servo was signaled to go to 0 degrees, then it will continue to receive that signal until given another one, thus remaining at 0 degrees.
     
  3. Delay is often a hard concept for students to understand. Although it looks like it is telling the Servo how long to stay at each position, it really is not actually giving any instructions to the Servo. It is the time the Arduino waits before giving the Servo its next command. This concept gets especially difficult when you start controlling multiple objects at the same time.
     
  4. A good way to help your students understand this is to use the “Simon Says” analogy. Play a quick game of Simon Says with your class, alternating between 2 simple commands like pat your head and rub your belly. With the first few commands, have about a 2 second pause between each command. Then speed up, and have very short pauses between commands. Then ask your students what changed. They should tell you that you waited less time between giving commands. Explain to them that that is what the delay does in the code. The Arduino is giving a command to the Servo and then the Arduino waits (for the amount of time specified in the delay) before giving the next command. Note to the students that they continued to move while you (Simon) waited to give the next command and only did a different action when instructed to do so. Likewise, the Servo will continue to do the action it was told to do while the Arduino pauses and until it gets its next command.
     
  5. Servos are physically moving and need time to get there or fully rotate. If you get a have time after this activity, try changing the delay value and finding what is the minimum value the delay can be to allow the standard Servo to go from 0 degrees to 180 degrees.
Instruction Category