- Type: “myservo.write(180);” after “delay(2000);”
STEM Connections
Remember, the write function determines the angle to which a standard Servo moves. So, the line of code “myservo.write(180);” tells the standard Servo to move to 180 degrees.
Before the Arduino board runs this line of code, the Servo was at angle 0. When the Arduino board runs this line of code, it will cause the standard Servo to rotate from 0 degrees to 180 degrees.
In the previous two steps, you told the Servo to move to 0 degrees, then pause at that angle for 2000 milliseconds (or 2 seconds). After adding this line, the Servo will move to 180 degrees.
Again, the write function will have a different effect on the continuous Servo, but we will explore that more in later steps.
‘write’ didn’t turn orange
- Check the spelling of the word “write” and make sure that no letters are capitalized.
- Check to make sure that there is a period between “myservo” and “write”.
1. You may want to mention that if they didn’t write this line of code here, the standard Servo would stay at the same spot (0 degrees) forever. You need to give another command for it to move. Just like in the LED Blink code, there were 2 states. State 1: LED on and State 2: LED off. Likewise, we also need 2 states for the standard Servo to see a back and forth motion.
2. Without giving a new command to the Servo, the previous line of ‘delay’ would be unnecessary because there wouldn’t beanother action to switch to.
3. After adding this line of code, the standard Servo is going instructed to move from 0 degrees to 180 degrees. However, it won’t have enough time to get to 180 degrees, but we unless we use another delay. OtherwiseWithout the delay, the Arduino will immediately get the next command line which is “‘myservo.write(0);”, moving it back to 0 degrees’. You may want to emphasize that the Arduino board reads through the code really fast. Without the next delay, it will look like the Servo is stuck at 0 degrees.