Sweep program
The sweep program is used to control a Servo motor. First we have to include the Servo "language" so that we able to use a Servo motor. There is a variable that creates a Servo called myservo and then a variable called pos that we can use later to store the Servo position. In the void setup(); we attach the Servo to pin 9 on our Arduino board. The loop then tells the motor that when the position is is at 0, move to 180 (degrees) and when the motor is at 180, move back to 0, and do these motions in steps of 1 degree. The delays waits 15 ms for the Servo to reach the designated position. We don't want the delay to be smaller than 15ms because the motor needs enough time to reach its final position.
Modified Sweep Program
We next modified the Sweep program to have to have to motor do a different motion. This helped us learn how the programing for the Servo motors works. For our modification, Olivia and I made the motor move only 90 degrees. We also changed the delay and the steps, and thus made it move differently on the second loop. If we increase the delay (as we did here with 3000ms) for the second for loop, you can really see how changing the 'steps' affects the motor. It will move, in this case, 15 degrees at a time until it reaches 90. Our video was taken before we made the change though, so the 'steps' aren't seen here.
Knob program with Servo Motor
Another example program for a Servo motor is the Knob program. For this program, we use a potentiometer to control the movement of the motor, i.e. when we turn the knob on the potentiometer, the motor moves at the same time. We connected the potentiometer to the analog pin A0 on our Arduino and ran the program. The value is read from the potentiometer pin (potpin) and then that value uses map(); to change the scale of the potentiometer to the scale of the motor. This makes the motor have the same motion as the potentiometer.
Our final task of the day was to use the potentiometer to control the blink rate of the LED, meaning it blinks slower when you turn the knob one way and blinks faster when you turn it the other way. We took our program for the servo and changed it to fit the LED. We again used map to scale the potentiometer reading to the LED rate.
I really liked your post! Everything was documented in a clear order and with concise explanations. I thought that your comments in the Arduino programs themselves were helpful to my understanding of what the commands mean. Good work!
ReplyDelete