using hobby servos with the arduino living with the lab © 2012 david hall

8
Using Hobby Servos with the Arduino living with the lab 2012 David Hall

Upload: ursula-matthews

Post on 04-Jan-2016

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Using Hobby Servos with the Arduino living with the lab © 2012 David Hall

Using Hobby Servos with the Arduino

living with the lab

© 2012 David Hall

Page 2: Using Hobby Servos with the Arduino living with the lab © 2012 David Hall

living with the lab

2

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.

DISCLAIMER & USAGE

Page 3: Using Hobby Servos with the Arduino living with the lab © 2012 David Hall

wires to power & control servo

3

living with the lab

red = 5V

black = Gnd

white = signal

output shaft

Page 4: Using Hobby Servos with the Arduino living with the lab © 2012 David Hall

servo components

4

living with the lab

1. small DC motor2. gearbox with small plastic gears to reduce the RPM and increase output torque3. special electronics to interpret a pulse signal and deliver power to the motor

Page 5: Using Hobby Servos with the Arduino living with the lab © 2012 David Hall

types of servos

5

living with the lab

continuous rotation

pulse tells servowhich way to spin & how fast to spin

pulse tells servowhich position to hold

standardcan only rotate 180 degreescan rotate all the way around in either direction

Page 6: Using Hobby Servos with the Arduino living with the lab © 2012 David Hall

Arduino programming

6

living with the lab

void loop() { digitalWrite(3, HIGH); delayMicroseconds(1700); // hold pin 3 high for 1700μs or 1.7ms digitalWrite(3, LOW); // hold pin 3 low for 20ms delay(20); }

these lines of code make the servo go full speed counter clockwise

time (milliseconds)

volta

ge (V

)

5V -

0V -

20ms

full speedclockwise

full speedcounter clockwise

pulse width varies between 1.3ms and 1.7ms

pulse width(μs)

servo action

1300 full speed CW

1400 ½ speed CW

1500 stopped

1600 ½ speed CCW

1700 full speed CCW

speed not linear with pulse duration

Page 7: Using Hobby Servos with the Arduino living with the lab © 2012 David Hall

wiring servo to breadboard

7

living with the lab

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.

The red wire from the power bus should go back to Vin or 5V, and the black wire should go back to Gnd.

Page 8: Using Hobby Servos with the Arduino living with the lab © 2012 David Hall

playing around with programing

8

living with the lab

“for” loop executes 200 times i = 0, 1, 2, 3, 4, . . . 199

void setup() { pinMode(3, OUTPUT); }void loop() { int i; for (i=0; i<200; i++) { digitalWrite(3, HIGH); delayMicroseconds(1300); digitalWrite(3, LOW); delay(20); } delay(1000); for (i=0; i<400; i++) { digitalWrite(3, HIGH); delayMicroseconds(1700-i); digitalWrite(3, LOW); delay(20); } }

this for loop causes the servo to go from full speed CCW (pulse width = 1700ms) to full speed CW (pulse width = 1300ms)

create a square wave with a pulse width of 1300ms followed by a 20ms pulse

wait one second