Making a Solar tracker

  • With the help of a 3D printer, an Arduino board, some light sensors, a small servo motor a mini solar panel, we have made in Spain a Solartraker of one axis which is monitorized on the screen of a laptop, as you can watch in the video:

     

     

     

    This code summarize how the sensors detect and compare their values in order to rotate the servo in each direction (from 0 to 180 degrees and return), depending on the light position.

    void loop()
    {
      int readTop = analogRead(ldrTop);
      int readDown = analogRead(ldrDown);
      if (readTop > readDown)
      {    
         if (servov < 0)
         {
          servov = 0;
         }
         else
         {
          servov = --servov;
         }
      }
     
      if (readTop < readDown)
      {  
        if (servov > 179)
        {
          servov = 180;
        }  
        else
        {
          servov= ++servov;
        }
      }

      vertical.write(servov);
      delay(80);
      Serial.write(servov);
      }