solar tracker

Hello, i have 3d printed and built the circuit below using the required components and schematics from https://www.instructables.com/id/Arduino-Solar-Tracker/
and i noticed that the picture diagram's pinout is different from the code, so i followed the codes pinout and made everything else the same, Except the potentiometers used for speed and tolerance, i used 20k and the diagram suggest 10k, but specifically mentions that the value of the pot doesn't matter and all i had was 20k.
When i power the circuit it doesn't work as intended and will move a little and then bug out and not work correctly. Is there anything wrong with the code or picture diagram?

#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 (-1*tol > dvert || dvert > tol) // 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);
}

Nothing on the link shows how the device is powered, and you never said how you are doing it.It might be rather important to being able to get it to work.

Paul

Is there anything wrong with the code or picture diagram?

Yep. In addition to Paul's comment above, the Fritzing-for-idiots diagram shows the servos powered by the 5V output of the Arduino.

That is guaranteed to cause problems, possibly even to the point of destroying the Arduino board.

As you have discovered, avoid Instructables. Most of them are posted by people who have little to no idea what they are doing.

jremington:
Yep. In addition to Paul's comment above, the Fritzing-for-idiots diagram shows the servos powered by the 5V output of the Arduino.

That is guaranteed to cause problems, possibly even to the point of destroying the Arduino board.

As you have discovered, avoid Instructables. Most of them are posted by people who have little to no idea what they are doing.

I see what you guys are saying, so can i power servos with another 5v power supply rated to handle the amperage and then use a common ground to arduino?

power servos with another 5v power supply rated to handle the amperage and then use a common ground to arduino?

Of course! In fact, that borders on a Universal Truth.

Spread the word.

jremington:
Of course! In fact, that borders on a Universal Truth.

Spread the word.

hell ya brother