"Here comes the sun..." with Solar Tracker

Well it's Solar Time again! Yep, it's been like, what, days since I've done a solar or energy related project? Well enough of that! Today's Hardware Friday by Graham Ross might seem simple, but is one that I think you can adapt for anything number of cool hardware projects...

Solar Tracker

Project Description
This project is deployed to a netduino, it uses a Arduino Compatible Mega Motor Shield, a linear actuator and a photocell out of a garden light to move a set of solar panel so that they face the sun throughout the day.

Required components
Netduino version 4.2 .NetMF
image

Motor shield http://www.robotshop.com/ca/arduino-compatible-mega-motor-shield-1a-5-28v-2.html
image
12V DC 12 in. Stroke Linear Actuator
image

Completed unit
image

And of course the source is available (which is the real cool part of this project)

image

Here's the Program.cs. It gives you a real nice feel for all the features to play with and code to check out...

public class Program
{
     private const int IterationTimeout = 5000;
     private static LinearActuator _linearActuator;
     private static LightSensor _lightSensor;
     private static readonly LcdText _lcdText = new LcdText();
     private static Thread _workerThread;
     private static long _lastTime;
     private static bool _setup;
     public static void Main()
     {
         _workerThread = new Thread(UpdateLCD);
         _workerThread.Start();
         InitializeActuator();
         InitializeLightSensor();

         var button = new InterruptPort(Pins.GPIO_PIN_A3, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
         button.OnInterrupt += button_OnInterrupt;

         Thread.Sleep(Timeout.Infinite);

     }


     static void button_OnInterrupt(uint data1, uint data2, DateTime time)
     {
         var currentTime = time.Ticks;
         var delta = currentTime - _lastTime;
         if (delta > 500)
         {
             _lastTime = currentTime;
             if (_setup == false)
             {
                 _setup = true;
                 if (_linearActuator.IsTracking == false)
                 {
                     _linearActuator.SetupDaylength(_lightSensor.LenghtOfDaylight.Ticks / TimeSpan.TicksPerMillisecond);
                 }
             }
             _linearActuator.Step(null);
             _lcdText.DebugLine2 = "Force step, Pos:" + _linearActuator.CurrentPosition;
         }
     }


     private static void UpdateLCD()
     {
         var lcd = new Lcd { Visible = true };
         lcd.Clear();
         lcd.ShowCursor = true;
         // set up the LCD's number of columns and rows: 
         lcd.Begin(24, 2);
         bool toggleDebug = false;
         while (true)
         {
             lcd.Clear();
             if (toggleDebug)
             {
                 lcd.SetCursorPosition(0, 0);
                 lcd.Write(_lcdText.DebugLine1);
                 lcd.SetCursorPosition(0, 1);
                 lcd.Write(_lcdText.DebugLine2);
             }
             else
             {
                 lcd.SetCursorPosition(0, 0);
                 lcd.Write(_lcdText.ActuatorText);
                 lcd.SetCursorPosition(0, 1);
                 lcd.Write(_lcdText.SensorText);
             }
             toggleDebug = _lcdText.HasDebug ? !toggleDebug : false;
             Thread.Sleep(IterationTimeout);
         }
     }

     private static void InitializeActuator()
     {
         _linearActuator = new LinearActuator(_lcdText);
         return;
     }

     private static void InitializeLightSensor()
     {
         _lightSensor = new LightSensor(_lcdText);
         _lightSensor.Dusk += LightSensorDusk;
         _lightSensor.Dawn += LightSensorDawn;
     }

     static void LightSensorDawn(object sender, EventArgs e)
     {
         _linearActuator.GoEast();
         // start tracking
         _linearActuator.StartTracking(_lightSensor.LenghtOfDaylight.Ticks / TimeSpan.TicksPerMillisecond);
     }

     static void LightSensorDusk(object sender, EventArgs e)
     {
         // stop tracking and return to east
         _lcdText.ActuatorText = "Waiting for morning";
         _linearActuator.GoEast();
     }
}

Tags:

Follow the Discussion

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.