# Parallax Servo Problems

I am currently working on a senior project in which we are required to design a solar tracker.

Thus far, it is working alright in one direction; the problem comes in when we try to power our horizontal adjustment servo, a Parallax continuous rotation servo, that simply spins in one direction whenever we run power to it.

Below is a picture of the circuit we are using (we removed the far right potentiometer and simply added a delay time) and a copy of the code, if someone could be so kind as to take a look and tell me if they see anything glaringly obvious that might be causing the issue.

``````#include <Servo.h> // include Servo library

Servo horizontal; // horizontal servo
int servoh = 90; // stand horizontal servo

Servo vertical; // vertical servo
int servov = 90; // stand vertical servo

// LDR pin connections
// name = analogpin;
int ldrlt = 0; //LDR top left
int ldrrt = 1; //LDR top rigt
int ldrld = 2; //LDR down left
int ldrrd = 3; //ldr down rigt

void setup()
{
Serial.begin(9600);
// servo connections
// name.attacht(pin);
horizontal.attach(9);
vertical.attach(10);
}

void loop()
{
int lt = analogRead(ldrlt); // top left
int rt = analogRead(ldrrt); // top right
int ld = analogRead(ldrld); // down left
int rd = analogRead(ldrrd); // down rigt

int dtime = analogRead(4)/20; // read potentiometers
int tol = analogRead(5)/4;

int avt = (lt + rt) / 2; // average value top
int avd = (ld + rd) / 2; // average value down
int avl = (lt + ld) / 2; // average value left
int avr = (rt + rd) / 2; // average value right

int dvert = avt - avd; // check the diffirence of up and down
int dhoriz = avl - avr;// check the diffirence og left and rigt

if (-10 > dvert || dvert > 10) // check if the diffirence is in the tolerance else change vertical angle
{
if (avt > avd)
{
servov = ++servov;
if (servov > 180)
{
servov = 180;
}
}
else if (avt < avd)
{
servov= --servov;
if (servov < 0)
{
servov = 0;
}
}
vertical.write(servov);
}

if (-10 > dhoriz || dhoriz > 10) // check if the diffirence is in the tolerance else change horizontal angle
{
if (avl > avr)
{
servoh = --servoh;
if (servoh < -180)
{
servoh = -180;
}
}
else if (avl < avr)
{
servoh = ++servoh;
if (servoh > 180)
{
servoh = 180;
}
}
else if (avl == avr)
{
// nothing
}
horizontal.write(servoh);
}
delay(20);
}
``````

It looks like you are powering the servos from the Arduino 5v pin. That is completely out of the question. Your servos must have a separate power supply with a common ground connection to the Arduino ground.

...R

95% or all servo problems reported here seem to be related to inadequate
power supplies for Servos. Budget 1 to 2A per servo (if simultaneously active),
depending on size. They pull high spikes of current everytime they start moving,
or continuous high currents if physically obstructed.

Powering motors or servos from the Arduino 5V rail also risks damaging the board
(or even your computer if under USB power), since inductive loads are able to
generate voltage spikes, in general you keep motors separately powered from
logic circuits.

a Parallax continuous rotation servo, that simply spins in one direction whenever we run power to it.

Besides using a separate power supply.
You can't control the angle of a continuous rotation servo. Use unmodified servos for both. You only need 180 degrees to track the sun.
This link may be some help: http://www.instructables.com/id/Arduino-Solar-Tracker/