EasyManua.ls Logo

SunFounder GalaxyRVR - Page 82

Default Icon
120 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder GalaxyRVR Kit for Arduino, Release 1.0
In the next step, we will go on a fascinating journey inside a servo motor to understand how it works. Excited? Lets
go!
Step 2: How does a Servo Work?
So how does a servo work its magic? Let’s go on an exciting journey inside a servo!
If we were to peek inside a servo, we would see a few parts. At the heart of a servo is a regular motor, very similar
to the motors that spin our Mars Rover’s wheels. Wrapped around the motor, there is a big gear that is connected to a
smaller gear on the motor shaft. This is how the motor’s fast, circular motion gets transformed into slower but stronger
motion.
But that’s not what makes a servo special. The magic happens in a tiny piece of electronics called a “potentiometer” and
the “control circuitry”. Heres how it works: when the servo moves, the potentiometer turns and changes its resistance.
The control circuitry measures this change in resistance and knows exactly what position the servo is in. Clever, isnt
it?
To control a servo, we send it a special kind of signal called a “pulse-width modulation” signal or PWM. By changing
the width of these pulses, we can control exactly how much the servo moves and hold it in that position.
In the next step, we’ll learn how to control a servo using an Arduino. Ready for some magic spells in the form of code?
Lets go!
Step 3: Controlling a Servo using Arduino
Alright, explorers, now that we know how a servo works, let’s learn how to control it using our magic wand, the
Arduino!
Controlling a servo is like giving it directions. Remember the pulse-width modulation (PWM) signals we mentioned
earlier? We are going to use those to tell the servo where to move.
Luckily, Arduino makes this task easy for us with a built-in library called Servo. With this library, we can create a
Servo object, attach a pin to it (the pin that our servo is connected to), and then use a simple command, write(), to
set the angle.
Heres a snippet of what the code looks like:
#include <Servo.h>
(continues on next page)
78 Chapter 3. Course Mode

Related product manuals