Motor exercise (more things to come!)

I made a motor spin! This is my first project with enough bits on the breadboard that I’m not entirely sure what they all mean (what’s that diode do, anyway? and why is the 9 pin not connected to the motor??). BUT, that just means getting more practice for the final project! I’ve been excited since the beginning of class to work with more complicated sensors and data outputs, so this might seem like a very uncomplicated breadboard in another six weeks’ time…

I’ll never let you down, little servo!

Hi, everybody!  So, I did my best to modify this code a little bit, but never really understood why I couldn’t control the function better. I’m pocketing this question for class. But, here’s what the sample code looks like:

[code]

#include <Servo.h>

Servo myservo;

int pos = 0;

void setup()
{
myservo.attach(9);
}

void loop()
{
for(pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 180; pos>=0; pos-=1)
{
myservo.write(pos);
delay(15);
}
}

[/code]

Here’s the closest thing to the way I had it in the end, when it still wasn’t functioning… I don’t have a video of that, because it really wasn’t any different with the exception of a little skip in the middle of the sweep.

[code]

#include <Servo.h>

Servo myservo;

int pos = 0;

void setup()
{
myservo.attach(9);

void loop()
{
for(pos = 0; pos <= 10; pos += 1)
{
myservo.write(pos);
delay(50);
}
for(pos = 10; pos <= 20; pos -= 1)
{
myservo.write(pos);
delay(50);
}
for(pos = 10; pos <= 20; pos += 1)
{
myservo.write(pos);
delay(50);
}
for(pos = 20; pos <= 30; pos += 1)
{
myservo.write(pos);
delay(50);
}
for(pos = 30; pos <= 40; pos += 1)
{
myservo.write(pos);
delay(50);
}
for(pos = 40; pos <= 50; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 50; pos <= 60; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 60; pos <= 70; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 70; pos >= 80; pos -= 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 80; pos <= 90; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 90; pos <= 100; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 100; pos <= 110; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 110; pos <= 120; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 120; pos <= 130; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 130; pos <= 140; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 140; pos <= 150; pos += 1)
{
myservo.write(pos);
delay(15);
}

for(pos = 150; pos <= 160; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 160; pos <= 170; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 170; pos <= 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 180; pos <= 0; pos -= 1)
{
myservo.write(pos);
delay(15);
}
}

[/code]

And here’s the video of the successful function, although I’m not happy that that’s all it does. I wanted it to function like an old yard sprinkler.

Thanks for looking!

Will

I got the servo down

I chose to do Sketch 04 from our booklet, the Servo Sweep.

Setting up this initial code and circuit was easy enough, but I then struggled to set up the slight modification with the potentiometer. I tried and tried and wrote the code and copied the code, and consulted the Adafruit tutorial, and hooked it up to outside power (9V battery instead of USB), but no matter what I did, my servo arm just moved in sporadic fits and mostly stayed still.

FINALLY, I figured out the problem. I was trying to share ground and power between both the potentiometer and the servo. They are both three-pronged pieces, after all! How elegant!

EXCEPT that the order of the servo arms is NEG, POS, SIGNAL, but order on the potentiometer is NEG, SIGNAL, POS! So, I let go of my elegant four wire solution and separated the potentiometer and servo, and it worked like a charm.