#include <Time.h> //Allows arduino to tell current time. #include <Servo.h> //Controls servo motor. #define NUM_SAMPLES 10 int sum = 0; // sum of samples taken unsigned char sample_count = 0; // current sample number float voltage = 0.0; // calculated voltage Servo myservo; //Create servo object to control the servo. int postn = 80; //Variable to store the servo position. int lightPin1 = A5; //Define a pin (A0?) for Photoresistor 1. int lightPin2 = A4; //Define a pin (A1?) for Photoresistor 2. void setup() { myservo.attach(9); pinMode(lightPin1, not use INPUT_PULLUP resistor. pinMode(lightPin2, //Attaches the servo on Pin 9 to servo object "myservo." INPUT); //Specify pinmodes for two photoresistors. We do because the photoresistors are specified with a pull-down INPUT); Serial.begin(9600); //Set baud rate for communication with serial monitor. myservo.write(80); // // //Set servo to midpoint of min and max angles Serial.print("Current position: "); Serial.println(postn); //Choose auto or manual mode on startup. Serial.println("Input current hour to begin or see app for manual mode."); } void loop() { if (Serial.available()>0){ int incomingByte = Serial.parseInt(); Serial.println(incomingByte); setTime(incomingByte, 0, 0, 0, 0, 0); AutoMode(); int pin1 = analogRead(lightPin1); //Collect Sensor 2. int pin2 = analogRead(lightPin2); Serial.print("lightPin1: "); Serial.println(pin1); Serial.print("lightPin2: "); Serial.println(pin2); if(pin1 > (pin2 + 20)){ Serial.println("Photoresistor 1 is getting more sunlight; consider decreasing angle."); } if((pin1 + 20) < pin2){ Serial.println("Photoresistor 2 is getting more sunlight; consider increasing angle."); } if(pin1 < 900 && pin2 < 900){ Serial.println("Insufficient light. Consider moving panel.");} // take a number of analog samples and add them up while (sample_count < NUM_SAMPLES) { sum += analogRead(A2); sample_count++; delay(10); } // calculate the voltage // use 5.0 for a 5.0V ADC reference voltage // 5.015V is the calibrated reference voltage voltage = ((float)sum / (float)NUM_SAMPLES * 5.015) / 1024.0; // send voltage for display on Serial Monitor // voltage multiplied by 11 when using voltage divider that // divides by 11. 11.132 is the calibrated voltage divide // value Serial.print("Battery Voltage: "); Serial.print(2*voltage * 11.132); Serial.println (" V"); sample_count = 0; sum = 0; } } void AutoMode() { //AUTO automates turning process. //Compare sensors and print which one is getting more sunlight. //Collect Sensor 1. //Turn motor based on time of day until it is 8 pm. USE TIME LIBRARY OR HAVE USER ENTER TIME EVERY HOUR. if(hour() == 8){ Serial.println("Time is 8 A.M."); myservo.write(58); } else if(hour() == 9){ Serial.println("Time is 9 A.M."); myservo.write(62) ; } else if(hour() == 10){ Serial.println("Time is 10 A.M."); myservo.write(64) ; } else if(hour() == 11){ Serial.println("Time is 11 A.M."); myservo.write(67) ;} else if(hour() == 12){ Serial.println("Time is 12 P.M."); myservo.write(70);} else if(hour() == 13){ Serial.println("Time is 1 P.M."); myservo.write(74);} else if(hour() == 14){ Serial.println("Time is 2 P.M."); myservo.write(80);} else if(hour() == 15){ Serial.println("Time is 3 P.M."); myservo.write(84); } else if(hour() == 16){ Serial.println("Time is 4 P.M."); myservo.write(88); } else if(hour() == 17){ Serial.println("Time is 5 P.M."); myservo.write(92) ;} else if(hour() == 18){ Serial.println("Time is 6 P.M."); myservo.write(95) ;} else if(hour() == 19){ Serial.println("Time is 7 P.M."); myservo.write(99) ;} else if(hour() == 20){ Serial.println("Time is 8 P.M."); myservo.write(103) ;} }