# Introduce a scale to compare 2 AnalogRead

Hi guys, i have a code in which i want to instroduce a scale. For example, if my ldr1 read 80 and ldr2 read 85, my solar panel won't move. (or if ldr1 = 20 and ldr2 = 15, for example)

But i realy don't know how to do that. My code :

``````int ldr_right = A1;
int ldr_left = A2;
int left_read;
int right_read;

int MotorPin = 7;                 // Moteur connecté au pin 7

void setup()
{
pinMode(MotorPin, OUTPUT);      // met la broche numérique du moteur en sortie
}

void loop()
{
int left_read = analogRead(A2);
int right_read = analogRead(A1);

if(right_read > left_read)          // Si la LDR droite capte plus de luminosité que celle de gauche 'luminosité vers la droite)
{
digitalWrite(MotorPin, HIGH);   //
delay(1000);                   // attend une seconde
}

else if(left_read > right_read)      // si la luminosité est vers la gauche
{
digitalWrite(MotorPin, LOW);
delay(1000);        // attend une seconde
}
else
{
delay(60000);        // attend une minute
}
}
``````

Thank's for help !

Alazarus: Hi guys, i have a code in which i want to instroduce a scale. For example, if my ldr1 read 80 and ldr2 read 85, my solar panel won't move. (or if ldr1 = 20 and ldr2 = 15, for example)

Do you mean you want it to move if they more than 5 apart, so 85,70 will move, 85,83 won't?

Yes, it is :) If i don't do that, my solar tracker will always move :roll_eyes:

``````if(abs(right_read - left_read) > 5)
{
// Get a move on
}
``````

It's all about mathematics and i was searching a special code... damn ! Thank's :)

Can i write this ?

``````else if ((abs(right_read - left_read) > 5) && (abs(left_read - right_read) >5))
delay(600000)
``````

Edit : no it's stupid, i should have the two conditions in two loop!

no it's stupid, i should have the two conditions in two loop!

How are the two conditions different?

left_read - right_read is not the same as right_read - left_read, but abs(left_read - right_read) is the same as abs(right_read - left_read).