//Created by Barbu Vulc.
//This is a simulation of an solar tracker using an Arduino UNO R3.
/*
We have 2 LDR sensors and 1 servo motor. In real life when more light is going down
on either one of the sensors, the solar panel will rotate in that direction.
In this example, the hypothetical solar panel rotates only on one axis!
*/
//Servo library:
#include <Servo.h>
Servo SM; //Servo object...
const int servoPin = 2;
void setup() {
//Attach SM to pin 2 to the Arduino UNO board!
SM.attach(2);
}
void loop() {
//The photoresistor variable...
int LDR = analogRead(A0);
//0-600 (LDR sensor values) -> 0-180 (Servo Motor values(degrees))...
uint16_t angle1 = map(LDR, 0, 100000, 0, 90);
//Record the now-adjusted value of the sensor to the servo motor.
uint16_t angle2 = map(LDR, 49999, 100000, 91, 180);
SM.write(angle1); SM.write(angle2);
}
//Representation:
// /######/######/######/######/######/
// /######/######/######/######/######/
// /######/######/######/######/######/
// /######/######/######/######/######/
// /######/######/######/######/######/
// /######/######/######/######/######/
// /######/######/######/######/######/
// /######/######/######/######/######/
// /######/######/######/######/######/
// | |
// | |
// | | <--
// /| |\ \
// |\|__|/| | The axis
// \| |/ /
// | | <--
// |__|