// =================================== // SolarRobot Control software // Arduino NG version with ATmega 168 // // Created by E.Dertien June 3th 2008 // // for Interactivos?08 // =================================== // version 1.0 // In this version the timing is set by potmeter 1, potmeter 2 defines a voltage trigger level // // Globals and variables int timingPotmeter = 1; // select the input pin for the potentiometer int triggerLevelPotmeter = 2; // select the input pin for the potentiometer int voltageSense =3; // select the input pin for the voltage divider int ledHIGH = 3; // select the pin for the LED (bi-color, so two pins are being used) int ledLOW = 2; int powerOUT = 9; // select output pin for transistor int delaytime,n,SolarVoltage = 0; // variable to store the value coming from the sensor #define MIN_MOTOR_TRESHOLD 80 //(1/11 voltage divider causes AD resolution of 0.0537 V/bit) The minimum value where a motor still works is hereby set at 4.3 V //#define SERIALPORT // if not defined, then the serial routines will not be compiled void setup() { #ifdef SERIALPORT Serial.begin(9600); // prints title with ending line break Serial.println("SolarRobot Control software"); #endif pinMode(ledHIGH, OUTPUT); // declare the ledPin as an OUTPUT pinMode(ledLOW, OUTPUT); // declare the ledPin as an OUTPUT pinMode(powerOUT, OUTPUT); // declare transistor pin as output // wait for the long string to be sent delay(100); } void loop() { for (n=0;n<250;n++) // n=100 gives a maximum time interval of 250 * 1023 ms = 255 sec { // // voltageSense gives a value of 93 at 5V, 293 at 12V (1/11 voltage divider causes AD resolution of 0.0537 V/bit) // if the timer interval just started, and if sensed voltage level is higher than preset level by potentiometer, turn on motor // // // the maximum value of analogRead(voltageSense) is 25V (maximum voltage of solarpanel) divided by 0.0537 V/bit = 465 // the triggerLevelPotmeter value is maximal 1023, so devididing this value by three maps both ranges better. // still, in time mode the motor is not turned on when the solar voltage is not above the MIN_MOTOR_TRESHOLD value (80*0.537 = 4.2V) SolarVoltage = analogRead(voltageSense); if ((n==0) && SolarVoltage >((analogRead(triggerLevelPotmeter)/3)+MIN_MOTOR_TRESHOLD)) { analogWrite(powerOUT,255); // turn the motor on. The powerlevel is determined by the solar voltage. digitalWrite(ledHIGH, HIGH); // sets the LED on digitalWrite(ledLOW,LOW); // turn the LED on } if ((analogRead(voltageSense))