Servo Motors (Week 8)_Alyssa

What are the different motors?

DC motors rotate continuously. Their speed is controlled by PWM, which actually turns the motor on and off so rapidly it looks like a smooth movement. DC motors rotate until power is detached.

Servo motors are good for exact tasks because they can be more precisely controlled than standard DC motors. Power to the motor is constant but regulated by the servo control circuit. PWM  “unlike DC  motors it’s the duration of the positive pulse that determines the position,   rather than speed, of the servo shaft.” (source: https://www.quora.com/What-is-the-difference-between-a-DC-motor-a-servomotor-and-a-stepper-motor)

Stepper motors use electromagnets around a central gear to determine the position. Each electromagnet must be individually powered to make the motor shaft turn.

 Goals: Experiment with a new motor.

I picked up this 6.5kg standard servo motor from Tinkersphere to try out in the circuit for my final project. Was interesting to have more power, but I definitely didn’t use the right resistor, as something started to smell like burning. Didn’t need this motor after all, but will come up with a project that uses this at some point.

Motor runs when the photocell is exposed to light; stops when the photocell is dark.

Components: Servo motor, 1K ohm resistor, photocell, jumper wires

Code:
// code from:
//http://forum.arduino.cc/index.php?topic=149576.0
//https://www.arduino.cc/en/Tutorial/Sweep
// https://www.arduino.cc/en/Reference/ServoWrite

#include <Servo.h> // include the servo library

Servo servoMotor; // creates an instance of the servo object to control a servo

int analogPin = 0; // the analog pin that the sensor is on
int analogValue = 0; // the value returned from the analog sensor

int servoPin = 9; // Control pin for servo motor. As of Arduino 0017, can be any pin

int pos = 0;

void setup() {
servoMotor.attach(servoPin); // attaches the servo on pin 2 to the servo object
}

void loop()
{
analogValue = analogRead(analogPin); // read the analog input (value between 0 and 1023)
if(analogValue < 400) {
servoMotor.write(90); // Spin servo at max speed clockwise
} else {
servoMotor.write(0); // Stop the servo

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servoMotor.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
servoMotor.write(pos); // tell servo to go to position in variable ‘pos’
delay(15);
}

}

delay(15); // waits for the servo to get there

}

[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *