servo sweep - arduinoteacher.com · servo sweep the arduino teacher . what we’ll do in this...

23
Servo Sweep The Arduino Teacher www.ArduinoTeacher.com

Upload: others

Post on 18-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Servo Sweep

The Arduino Teacherwww.ArduinoTeacher.com

Page 2: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

What We’ll Do in this Lesson

2

★ Wire a 3 pin Servo Motor★ Write a more advanced code to control a Servo Motors motion in a

sweeping pattern based on a feedback loop

Page 3: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Let’s Get Ready!

3

Page 4: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

You’ll need these things to make your circuit

4

Black Wire

Red Wire

Yellow Wire

Servo Motor

Page 5: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Safety!

5

Page 6: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Keep yourself safe when working with Arduinos!

6

You should never connect power and ground wires directly while they are plugged into your Arduino board.

This results in a short circuit.

A short circuit can result in temperatures hot enough to burn the user and the Arduino.

Always think safety first. When in doubt, seek help!

Page 7: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Let’s Build your Circuit!

7

Page 8: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Step 1

8

Use your colored wires to match the wires leading out of the Servo motor. Then, plug the black ground wire into the GND pin. Plug the red power wire into the VIN pin. Plug the yellow signal wire into Pin 9.

What type of pin is pin 9?

Page 9: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Plug In!

9

Connect your Arduino to your computer using the USB cable. If done correctly, the green light on the Arduino board should power on!

Page 10: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Let’s Write your Code!

10

Page 11: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Port

11

Make sure your computer knows which port the Arduino is plugged into.

Page 12: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Step 1

12

Include the Servo Library , name your Servo, and create a variable for the servo position.

Page 13: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Step 3

13

Tell the Arduino where the Servo is plugged in

Page 14: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

About Loop Codes

14

The next code you will write features a For Loop. This allows our code to adapt to the actions it performs. A For Loop checks the status of your code and completes actions until all conditions are met. Then, it can move onto another series of actions based on a new set of conditions.

We will write a code that will check the position of your servo and perform an action based on its position.

We will make the servo travel from 0 to 180 degrees in one For Loop.

We will make the servo travel from 180 to 0 degrees in another For Loop.

Page 15: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Step 4

15

Write your loop code to control the Servos motion based on a feedback loop

Which LED code does this resemble?

Page 16: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Verify

16

Verify your code by clicking the check in the upper left corner. Codes with errors will show an orange warning at the bottom.

Page 17: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Upload

17

Upload your code to your Arduino by clicking the arrow in the top left corner. Notice the green status bar in the lower right corner.

Page 18: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Did it work??

18

Page 19: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Troubleshooting

19

Page 20: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

If your Arduino isn’t performing as expected...

20

★ Wiring issues○ Double check that your wires are plugged all the way in to the correct pins

and the correct locations on the breadboard○ Check the alignment of wires on your Servo to the pins on the board. The

black wire is always GND. The power wire may be red or brown. The signal wire may be white, orange, or yellow.

★ Coding issues○ Check your capitalization and punctuation against the example code.○ Make sure you uploaded your code. It should read “Done Uploading” in the

bottom right corner.

Page 21: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Challenges!

21

Page 22: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

Can you take it a step further?

22

★ Try sweeping your Servo in a different pattern or at different intervals.

★ Can you edit this code to make an LED Fade?

★ Can you add an LED that fades with the Servo sweep?

Page 23: Servo Sweep - arduinoteacher.com · Servo Sweep The Arduino Teacher . What We’ll Do in this Lesson 2 ★Wire a 3 pin Servo Motor ★Write a more advanced code to control a Servo

For more lessons and project ideas, visit The Arduino Teacher

www.ArduinoTeacher.com