First of all, sorry I'm new to programming, I learned my self so my knowledge is still expanding. Google is a mess for finding a solution, so I turn to you guys.

I have an small project thats redirect the sun from my balcony in to my living room with a servo controlled mirror. The function of the servo is that when the sun moves, the servo corrects the angle of the mirror. The whole setup is already done, I "think" that my code is almost done but a small problem; my servo keeps shaking :0.

int PhotoPin1 = 5; // the pin number of the 1st Photosensitive Resistanceint PhotoPin2 = 6; // the pin number of the 2nd Photosensitive Resistanceint PhotoPin3 = 7; // the pin number of the 3th Photosensitive Resistanceint PhotoPin4 = 8; // the pin number of the 4th Photosensitive Resistanceint PhotoPin5 = 9; // the pin number of the 5th Photosensitive Resistanceint angle = 90; // variable to store the servo position

if (PhotoPin1State == HIGH) { if (angle > 0) { angle -= 5; } myservo.write(angle); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there } if (PhotoPin2State == HIGH) { if (angle > 0) { angle -= 1; } myservo.write(angle); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there } if (PhotoPin3State == HIGH) { if (angle > 90) { angle += 0; } myservo.write(angle); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there } if (PhotoPin4State == HIGH) { if (angle < 180) { angle += 1; } myservo.write(angle); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there } if (PhotoPin5State == HIGH) { if (angle < 180) { angle += 5; } myservo.write(angle); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there }

In your photo (which looks very nice) all the LDRs seem to be facing the same way so I don't understand why you read them and react to them separately.

I suspect the vibration in your servo has one of two causes

the software may be asking it to go beyond the physical limit of its travel - 0degrees and 180degrees are only approximate and you may need to experiment to find what suits your particular servo.

the commands generated by your LDRs may be asking it to move this way and that way. This may have something to do with the fact that you read each LDR separately - they will not all behave identically. In any case the sun doesn't move fast so it would not be necessary to update the servo position more than once every minute or ten.

...R

Two or three hours spent thinking and reading documentation solves most programming problems.

What's the resistance of your LDRs? If it's over 10k ohms it may be that the ADC is not able to measure the voltage correctly. I read on another thread that it's a good idea with higher resistance potentiometers to read the same measurement twice in succession and just use the second reading, but I have not tried this. And the output from an LDR can vary very quickly so the idea may not be relevant to them.

Another possibility may be to treat the LDRs as "digital" devices and just take an on/off signal from them depending on whether the voltage is above or below some number - in other words don't bother with fine resolution.

...R

Two or three hours spent thinking and reading documentation solves most programming problems.