The choice to go up or down in order to follow the light is done in a very simple way. There are four LDR two up and two down. Arduino reads the analog value of all LDR, if the average of the two upper values is greater than the two lower the light is up so the angle of the microservo is incremented otherwise decremented.
2. A Little ClarificationSince the average is not a fixed number, as you can see in the code, a threshold is used. In this way the angle is changed if and only if the two averages are widely different.
const int threshold = 50;
[.....]
down_average = (A0_val + A1_val)/2;
up_average = (A2_val + A3_val)/2;
diff = abs(up_average-down_average);
if ((up_average > down_average) && (diff > threshold))
{
if (val < 180) //if different from max val
{
val++;
myservo.write(val);
}
}
if((down_average > up_average) && (diff > threshold))
{
if (val > 0) //if different from min val
{
val--;
myservo.write(val);
}
}
3. The CircuitMake the circuit below!
Download the attached file, print it, glue it on the cardboard and cut all the pieces for yours light follower. You should obtain something like this.
Mount the breadboard base in this way. Glue it if necessary.
Mount the servo like below. Screw it for more stability.
Mount the bracket in this way.
Mount the servo gear. Screw it in this way.
Put all together. You should obtain something like this
Glue the breadboard on the base. You can use the biadhesive tape of the breadboard.
Screw Arduino on the back of the base.
Well done. Now you have all the necessary. Download the code on your Arduino and enjoy with your light follower!
a_guadalupi

Comments
Please log in or sign up to comment.