-
Try to complete the “Sprinkler Challenge” with the standard Servo by changing the code so that your standard Servo behaves like a water sprinkler. Starting at 0, the Servo should move to a range of angles between 0 and 180 degrees before rapidly returning to 0 degrees and then cycling through the range of angles again.
-
Try changing your code so that the continuous Servo begins at a stop, then begins slowly rotating, then slowly speeds up until it is at maximum speed in that direction (0 or 180), then comes to an abrupt stop before repeating.
-
Remember to upload the code each time you change it to see the changes take effect.
At the Thinkabit Lab, we provide students with a process that help them determine how to choose the correct Servo and write the program for that Servo, as follows:
Ask students to think of what they want the Servo to do.
Write it out as a list:
- I want my flower to spin to the right for 1 second.
- I want my flower to stop spinning for 3 seconds.
The fact that I want my Servo to “spin” tells me I should use the continuous Servo.
Next, break up that list into Servo actions and Arduino pauses (remember Simon says!)
- Spin to the right
- Pause for one second
- Stop spinning
- Pause for one second
Then associate that list with lines of code that will accomplish that.
Line 1: Spin to the right
- Values greater than 90 will make the continuous Servo spin to the right.
- Let’s choose 150. This will give us: “myservo.write(150);”
Line 2: Pause for one second
- A delay will pause the Arduino before reading another line of code, meanwhile all previous actions will continue to run meaning that the Servo will spin to the right for this 1 second pause.
“delay(1000);”
Line 3: Stop spinning
- A value around 90 should get the continuous Servo to stop.
- Try different values close to 90 until it does stop. “myservo.write(90);” (or the value close to 90 you found to be “stop”).
Line 4: Pause for 3 seconds
- A delay will pause the Arduino before reading another line of code, meanwhile all previous actions will continue to run, meaning that the Servo will stay stopped for this 3 second pause “delay(3000);”
If you are using the Thinkabit Lab Notebook:
Use the examples on pages 16 and 17 to help describe how you might change the values to cause the Servo to move differently.
The program was uploading before, but not anymore / “problem uploading to board”
-
Check the most obvious first, that the Arduino board is connected to the computer with the USB cable.
-
Check that the Arduino is connected to the right COM port, then upload again.
-
To check, go to Tools > Port and see if “COM# (Arduino/Genuino Uno)” is next to the word “Port”.
-
If not, select the option mentioned above.
-
If no COM# shows “(Arduino/Genuino Uno)” next to it, make sure that your USB cable is connected to both the Arduino board and the USB port of the computer.
-
3. Try unplugging and re-plugging the USB cable and uploading again.
4. Try disconnecting all wires from the Arduino board and uploading again.