Help please

I have been trying to work through the Evil Genius Book for Arduino but having trouble with controlling a servo motor with the sketch in the book and the one from the playground on this site can someone tell me what’s wrong with this code? Please as I am tearing my hair out and at my age don’t have much to spare.

// Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

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

All I get is a slight flick of the servo and that’s it

Adrian

First off post the code properly, read the how to use this forum sticky.

Next increase that value in the delay.

I’ll hazard a guess that the servo is powered directly from the Arduino board. Even for one servo that can cause a problem to do with insufficient current, in spite of it being the way certain tutorials tell you to wire it up. For more than one, it’s a definite no-no…

So if that’s the way you’ve done it, give the servo its own power (eg from 4x AA batteries which will give about 6V), ie red and black servo wires to the battery, with the yellow or orange control wire still to the Arduino of course. Then lastly, join either end of the black (ie the battery end or the servo end) to the Arduino ground.

Oh, and of course keep the Arduino powerd up however you have it at the moment.

Member zoomkat has a nice little pic of how to do that wiring: search the forum for his posts maybe with the keyword “servo” and you’ll find the pic.

Edit… I remembered I made the pic below to show how to hook up a servo with breadboard.

Thanks for your help gents. I apologise for the break in protocol. I will have to get my head around the numbering system on the board, keep forgetting start at zero. Had the signal wire from the Arduino connected at pin 8 not 9 :~ The picture made the penny drop.

Adrian