Download presentation
Presentation is loading. Please wait.
1
using servos
2
DISCLAIMER & USAGE The content of this presentation is for informational purposes only and is intended only for students attending Louisiana Tech University. The author of this information does not make any claims as to the validity or accuracy of the information or methods presented. Any procedures demonstrated here are potentially dangerous and could result in injury or damage. Louisiana Tech University and the State of Louisiana, their officers, employees, agents or volunteers, are not liable or responsible for any injuries, illness, damage or losses which may result from your using the materials or ideas, or from your performing the experiments or procedures depicted in this presentation. If you do not agree, then do not view this content. The copyright label, the Louisiana Tech logo, and the “living with the lab” identifier should not be removed from this presentation. You may modify this work for your own purposes as long as attribution is clearly provided.
3
wires to power & control servo
white = signal red = 5V black = Gnd output shaft
4
servo components small DC motor
gearbox with small plastic gears to reduce the RPM and increase output torque special electronics to interpret a pulse signal and deliver power to the motor
5
which way to spin & how fast to spin
types of servos continuous rotation standard can only rotate 180 degrees can rotate all the way around in either direction pulse tells servo which position to hold pulse tells servo which way to spin & how fast to spin
6
full speed counter clockwise
Arduino programming these lines of code make the servo go full speed counter clockwise void loop() { digitalWrite(7, HIGH); delayMicroseconds(1700); // hold pin 7 high for 1700μs or 1.7ms digitalWrite(7, LOW); // hold pin 7 low for 20ms delay(20); } full speed clockwise pulse width (μs) servo action 1300 full speed CW 1400 ½ speed CW 1500 stopped 1600 ½ speed CCW 1700 full speed CCW pulse width varies between 1.3ms and 1.7ms time (milliseconds) voltage (V) 5V - 0V - full speed counter clockwise 20ms speed not linear with pulse duration
7
wiring servo to breadboard
8
wiring servo to breadboard
Since the servos will likely be hooked up for a while, it is worthwhile to keep the wiring tidy, cutting short jumpers from the power bus.
9
using the servo library
both programs below cause a servo attached to pin 7 to continuously spin full speed CCW put this statement in your program to use library don’t forget the space void setup(){ pinMode(7,OUTPUT); } void loop() { digitalWrite(7, HIGH); delayMicroseconds(1700); digitalWrite(7, LOW); delay(20); #include <Servo.h> Servo myservo1; void setup() { myservo1.attach(7); myservo1.writeMicroseconds(1700); } void loop() { “declare” the name of your servo as “myservo1” can choose any name indicate that servo will be wired to pin 7 send a pulse of 1700 μs or 1.7ms out pin 7 this program continues to send pulses to the servo so that it continues to run almost all of the execution time is spent on the delay(20) function and you can’t do anything else while this is happening writeMicroseconds(1700) continues to send pulses to the servo unless the myservo1.detach() function is called you could also send writeMicroseconds(1500) to stop the motion of the servo without detaching it when using the servo library, you can do other things, like check whisker status, while the servo is running
10
using functions (experiment on your own to control robot path)
#include <Servo.h> Servo myservo1; // declare servo 1 Servo myservo2; // declare servo 2 void setup() { myservo1.attach(7); // attach right servo to digital pin 7 myservo2.attach(8); // attach left servo to digital pin 8 } void loop() { forward(); // go to forward function delay(1000); // wait 1 second stop_robot(); // go to stop_robot function delay(500); // wait for 1/2 second void forward() { // declare function named forward myservo1.writeMicroseconds(1445); // spin right wheel counterclockwise myservo2.writeMicroseconds(1550); // spin left wheel clockwise void stop_robot() { // declare function named stop myservo1.writeMicroseconds(1500); // stop left wheel myservo2.writeMicroseconds(1500); // stop right wheel
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.