# Automatic solar panel servo limit

hello,

As a project I am making an automatic solar panel.
I just have a little problem. how do you set a limit on your servo's?
the servo_10 has to be between 50 and 120 degrees.

here's my program:

``````#include <Servo.h>
//Initialize variables
int topLeftLight = 0;
int topRightLight = 0;
int bottomLeftLight = 0;
int bottomRightLight = 0;
int LeftLight = 0;
int RightLight = 0;
int TopLight = 0;
int BottomLight = 0;
//Declare two servos
Servo servo_9;
Servo servo_10;

void setup()
{

pinMode(A3, INPUT);   //Light sensor up - left
pinMode(A2, INPUT);   //Light sensor up - right
pinMode(A1, INPUT);   //Light sensor bottom - left
pinMode(A0, INPUT);   //Light sensor bottom - right
servo_9.attach(9);    //Servo motor right - left movement
servo_10.attach(10);  //Servo motor up - down movement
servo_9.write(100);    //Servo motor right - left movement
servo_10.write(60);  //Servo motor up - down movement
delay(1000);
}

void loop()
{

//Calculate the average light conditions
TopLight = ((topRightLight + topLeftLight) / 2);
BottomLight = ((bottomRightLight + bottomLeftLight) / 2);
LeftLight = ((topLeftLight + bottomLeftLight) / 2);
RightLight = ((topRightLight + bottomRightLight) / 2);
//Rotate the servos if needed
if (abs((RightLight - LeftLight)) > 4) {    //Change position only if light difference is bigger then 4%
if (RightLight < LeftLight) {
}
}
if (RightLight > LeftLight) {
}
}
}
if (abs((TopLight - BottomLight)) > 4) {  //Change position only if light difference is bigger then 4%
if (TopLight < BottomLight) {
}
}
if (TopLight > BottomLight) {
`servo_9.write(constrain(servo_9.read() + 1, 50, 120));`