Servo Library
First off, this is a library. Therefore, we must initiate the servo library before the code. We do this by doing this command:
#include <Servo.h>
Now, we must define a servo, just like a variable.
Servo servothingy;
This code initiates a servo named servothingy. Usually, this goes before the actual code.
Now we must give the servo a port. Say that our servo motor is connected to port 6. We must tell the code that the servo motor is attached to port 6 by doing this code..
servothingy.attach(6);
This attaches the port 6 to the servo that we previously called servothingy.
Now we are ready to do stuff with the servo motor. Let's tell it to go to 180 degrees.
servothingy.write(180);
This sends a signal of whatever is in the () to the servo. The number that is in the () is going to be the position of the servo.
This is a brief lesson, for servos are pretty easy to use...in MY opinion :3
#include <Servo.h>
Now, we must define a servo, just like a variable.
Servo servothingy;
This code initiates a servo named servothingy. Usually, this goes before the actual code.
Now we must give the servo a port. Say that our servo motor is connected to port 6. We must tell the code that the servo motor is attached to port 6 by doing this code..
servothingy.attach(6);
This attaches the port 6 to the servo that we previously called servothingy.
Now we are ready to do stuff with the servo motor. Let's tell it to go to 180 degrees.
servothingy.write(180);
This sends a signal of whatever is in the () to the servo. The number that is in the () is going to be the position of the servo.
This is a brief lesson, for servos are pretty easy to use...in MY opinion :3
Servo -- How to use it
Here...is a little, pretty simple motor. I have one of these, and it costed around $5 ($10 for 2 :3). Notice the color of the three wires: yellow, red, and brown. Here's where to connect these wires:
red--->power output (5V port for arduino)
brown--->ground
yellow--->digital port
red--->power output (5V port for arduino)
brown--->ground
yellow--->digital port