Sun-Tracking Solar Panel

My main project is the Sun-Tracking Solar Panel. It is essentially just a solar powered charger that follows the Sun’s movement across the sky. I started with a regular charger and then added the sun-tracking feature. Using python, I also made a feature which can graph voltages so I can see how much the sun-tracking feature actually helped.

(For all code and other resources see the bottom of the page)

Engineer

Srikar N

Area of Interest

no clue

School

Lynbrook Highschool

Grade

Freshman

Final Milestone

Reflection

Overall BlueStamp has really helped in exposing me to the world of engineering. In the past, just the thought of sitting at a desk typing up code was enough to bore me to death. But with this experience, I was able to try all of these things that I originally had no clue about. It completely opened up my view of the field and now I know that I have at least some interest in it. I really enjoyed the fact that everything was individual. It gave a lot of room for improvement in terms of an overall understanding of what’s happening and how to solve problems on your own. Even though it was individual, you could also ask for advice from peers or the staff which I think mirrors the real world really accurately. While I struggled a lot, I had a lot of fun getting know all sorts of new things and learning the process of persevering through something alone.
My final milestone was just wrapping everything together. I had to move things from my breadboard to a PCB. I also decided that I wanted to make graphs of the solar panel’s output with and without the sun tracking feature. This would be a good way to show how useful the sun tracking actually is and it ended up being the bulk of this milestone. It was a really long process but I learned a lot.

Printed Circuit Board

There honestly wasn’t much to the soldering. It’s basically just copying things from the breadboard to a PCB with the only difference being that you have to make the connections yourself. Usually, this means putting all of the wires right next to each other and connecting it with solder material. One thing I learned was that it’s really important to plan things out before you solder them. It’s a lot more painful to desolder. I made the mistake of switching up a few wires and I ended up spending a lot of time trying to fix things.

Graphing

The graphing took a lot of work but it was definitely worth it. I learned a lot about different coding languages. I started with a little Java but I heard that Python is usually better for graphing. For four full days, I got to know the basics of Python and made some basic sketches. But when I moved on to the actual graphing code, I had a lot of problems importing the modules I needed. I pivoted a lot from text editor to text editor and had no success. The issue ended up being that Plotly (the graphing module) wouldn’t work unless I connected it to my profile. Matplot was a lot simpler and as soon as I switched it worked. I had a framework that just required me to input whatever values I wanted to graph. As it turned out, the Arduino IDE had a built-in graphing feature which I could’ve used the whole time. It was overall easier to use and could even update live so I ended up using that.

  • It should be noted that when graphing, you need to directly connect the solar panel to the voltage reading circuit. The lithium polymer charger regulates the output at around 3.75 volts so there will be no variance if connected through that. This can be done with a breakout board.

Demo Night Video

-still working on getting graphs

Third Milestone

The third milestone is to build a structure that can support the solar panel. It’s easily the most annoying milestone to complete and takes hours of pure manual labor. I can safely say that I made some hard gains from all the physical work. Overall though, the end result was definitely worth it. I ended up with a really nice, functional support structure.

Wood

For the wood, there really weren’t any technical problems. It’s a pretty straightforward process. It’s just a lot of cutting, gluing, and then waiting for everything to dry. That process, though simple, ended up being really tedious and long-winded. After spending multiple hours cutting the wood with a hand saw, my hands were completely raw and I was sore. In the future, I would be sure to get properly sized wood in order to minimize the amount of cutting needed. Something thin and not super bulky would probably be the best. One thing I learned that made the process go a lot smoother was that when sawing, it’s better to focus on speed and not strength. Otherwise, the saw gets stuck a lot.

(A good  wood size is pictured above)

Putting Everything Together

The rest of the third milestone consists of connecting the solar panel to the servo and making a stable system to allow the panel to rotate. I did this with two steel rods. One went across the wooden structure and one went through the servo’s arm. Both of these ran through a piece of wood at the bottom of the solar panel which turned the panel. The hardest part of this process was calibrating the servo so it could supported the panel. It worked fine until the solar panel reached a certain point. At that point everything went slack and it stopped rotating. I tried changing the code so that it wouldn’t turn as much. It worked but it limited the rotation too much. After doing some research on leverages, I tried putting one of the holes farther out. This spread out the weight and balanced everything out.

Completion

75%

My final milestone is just to transfer everything to a PCB. If it’s possible, I would also like to compare the amount of sunlight gathered with and without the sun tracking feature.

Second Milestone

The second milestone for the Solar Powered Charger is to make it sun tracking. Not only will this make the system more efficient, it makes it a lot less lame. I found a good reference to use so the process ended up going pretty quick.

The Circuit


The circuit uses a lot of new parts. At the center of everything were two photoresistors (LDRs). These are basically just regular resistors with the only difference being that the strength varies based on the light it senses. These are combined with regular resistors to make a voltage divider. Then I attached a servo to the circuit and coded it to rotate based on the strength of the LDRs. To tie everything together, I attached everything to an Arduino. I made a really dumb mistake while putting in the LDRs which was that I connected the two legs together on the breadboard. This is bad because it makes a loop where the + part of the circuit is connected to the part. It took a while for me to find the mistake but once I did it was easy to fix.

The Code

For the code, I pulled something off the internet and started to edit it. It works by reading the different inputs from the LDRs and comparing them. If one LDR reads more light than the other, it changes the servos position until they’re balanced. If there isn’t enough light, it defaults to facing east. This is so it faces the sunrise during the night. In order to help debug, I added a sequence of Serial.prints that showed the value of each LDR and their difference. I used this to keep things balanced. At first, I had some problems positioning the servo, but with the serial monitor I noticed a common difference and added something to the code to even it out. I expect this value to change once I mount the servo on the wooden structure.

Sun Tracking Code
/* 
Sun Tracker Sketch 

This sketch is designed for use with a 9gram servo, should be powered with an external power supply such as 3 AA or 3AAA batteries. For the purpose of this project, I'm using a rechargeable 5v battery pack. 
*/ 

#include <Servo.h> Servo servo; // Create a servo object to control the servo 

int eLDRPin = A0 ; // Assign pins to the LDR's 
int wLDRPin = A1;
int eastLDR = 0; //Create variables to store to LDR reading
int westLDR = 0; 
int difference = 0; //Create a variable to compare the two LDR's 
int error = 10; // Variable for if there is a noticable difference between the two LDR's 
int servoSet = 130; //Variable for position of servo - will be different for each device

void setup() { 
servo.attach(9); //attaches the servo object to PWM pin 9 Serial.begin(9600);
}

void loop() { 
eastLDR = analogRead(eLDRPin); //Read the LDR values 
westLDR = analogRead(wLDRPin); 
if (eastLDR < 400 && westLDR < 400) { //Check to see if there is low light on both LDR's 
while (servoSet <=140 && servoSet >=30) { // if so, send panels back to east for the sunrise 
servoSet ++; 
servo.write(servoSet); 
delay(100); 
} 
} 
difference = eastLDR - westLDR ; //Check the difference 
if (difference > 20) { //Send the panel towards the LDR with a higher reading 
if (servoSet <= 140) { 
servoSet ++; 
servo.write(servoSet); 
} 
} 
else if (difference < -20) { 
if (servoSet >= 15) 
{ 
servoSet – ; servo.write(servoSet); 
} 
} 

/*The Serial monitor section is for debugging purposes, or for general interest, one, once the device is functioning correctly, can be disabled. Use it to see if your LDRs are noticeably different when they have equal light shining on them.*/ 

Serial.print(eastLDR); 
Serial.print(" - "); 
Serial.print(westLDR); 
Serial.print(" - "); 
Serial.print(difference); 
Serial.print(" - "); 
Serial.print(servoSet); //Fine tune the servo settings, to maximise swing available 
Serial.print(" - "); 
Serial.println("."); 
delay(100); 
}

Toggle For Code

Progress

Circuitry 90%
Code 100%
Struture 20%
Overall 75%

My third milestone is to build a wooden structure to use as a stand for the panel. It will also include finding a way to connect my circuits

First Milestone

The first milestone for the Solar Powered charger is to set the groundwork for the rest of the project. This means building all the circuitry and doing the coding so that an Arduino can read the output. The entire process took a while because I went in with almost no knowledge of anything. Along the way I learned a lot.

The Circuit

To sum it up, the circuit was there to lower the output from 6v to 5v so an Arduino could read the voltage. One huge challenge in this was having to design one on my own. I essentially freestyled everything because I didn’t have a schematic I could reference. To get around this, I tried to mix and match a few smaller circuits I found on the internet. After doing some research and going through a few iterations, I settled on using a voltage divider. A voltage divider uses 2 resistors to divide the voltage proportionally to their strength. I used a 2k and 10k resistor to divide it by a factor of 1.2. I had a lot of issues trying to ground it properly but I eventually got it down.

The Code

The coding proved to be its own little problem. I found some things on the internet that I could use but I decided I wanted to try and make the code on my own. In order to learn the basic of the Arduino IDE, I decided to just jump right into some examples. Using these, I was able to dissect the different bits and pieces to learn what everything does. For my code specifically, I had to apply things like ints, floats, while loops, and other basic formulas. The code works by reading the values from the A2 pin. Then I take an average from a few of these samples to give a more even number. In order to compensate for the voltage divider, I multiplied the average by 1.2 to get the final voltage. Then using Serial.print, I recorded these values.

  • For the actual charger, just connect the solar panel to the lithium polymer charger and connect that to a lipo battery. From there you can plug in your phone to the remaining port through an adapter.

What's Been Done:

Code:

const int num_samples=10; 
int sum = 0; // sum of samples taken 
unsigned char sample_count = 0; // current sample number 
float voltage = 0.0; // calculated voltage 

void setup() {  
     Serial.begin(9600); 
     } 

void loop() {
      while (sample_count < num_samples) {//adds 10 sample values
           sum += analogRead(A2);
           sample_count++;
           delay(50);
           }      
     voltage = ((float)sum /(float)num_samples * 5.0) / 1024.0; /*averages values then puts in terms of volts*/
     Serial.print (voltage*1.2);//displays initial voltage (before resisted)
      Serial.println (" Volts"); //writes volts
      sample_count=0; //resets values
      sum=0;
 }

hover for code

For my next milestone, I plan on adding a feature so that the solar panel can track the Sun’s movement.

Starter Project

The Useless Machine

My starter project is a little device called the Useless Machine. The Useless Machine is essentially just a box with a switch on it. When the switch is flipped a little arm comes out and turns itself back off. Pretty useless. It was actually really fun to mess around with and I learned a lot while making it. Even though the project seems fairly simple, I faced a lot of problems that I had to overcome. When soldering at the beginning I placed the DPDT switch too high. This made it so that the lid wouldn’t fit on top.  I ended up making the hole on top bigger so that it would fit around the base of the switch. From this mistake, I learned how to work around problems and to solve problems before they get the chance to become a bigger issue. I also learned the basic parts of a circuit and what they do. The major parts that were used were a motor (for the movement of the arm inside), switches (to change the current based on contact), resistors (to control the amount of current), and LEDs to add a little flair.
oie_w4wowjankcmy

Resources:

Sun tracking schematic

Voltage reader schematic

Sun tracking code

/* 
Sun Tracker Sketch This sketch is designed for use with a 9gram servo, should be powered with an external power supply such as 3 AA or 3AAA batteries. For the purpose of this project, I'm using a rechargeable 5v battery pack. 
*/ 

#include <Servo.h> 

Servo servo; // Create a servo object to control the servo 
int eLDRPin = A0 ; // Assign pins to the LDR's 
int wLDRPin = A1; 
int eastLDR = 0; //Create variables to store to LDR reading 
int westLDR = 0; 
int difference = 0; //Create a variable to compare the two LDR's 
int error = 10; // Variable for if there is a noticable difference between the two LDR's 
int servoSet = 130; //Variable for position of servo - will be different for each device 

void setup() { 
  servo.attach(9); //attaches the servo object to PWM pin 9
  Serial.begin(9600); 
}  

void loop() {
  eastLDR = analogRead(eLDRPin); //Read the LDR values 
  westLDR = analogRead(wLDRPin); 

  if (eastLDR < 400 && westLDR < 400) { //Check to see if there is low light on both LDR's 
     while (servoSet <=140 && servoSet >=30) { // if so, send panels back to east for the sunrise 
       servoSet ++; 
       servo.write(servoSet); 
       delay(100); 
     }
  } 

  difference = eastLDR - westLDR ; //Check the difference 
  if (difference > 20) { //Send the panel towards the LDR with a higher reading \
     if (servoSet <= 140) { 
       servoSet ++; 
       servo.write(servoSet); 
     }
  } else if (difference < -20) { 
     if (servoSet >= 15) { 
       servoSet – ; 
       servo.write(servoSet); 
     } 
  } 

  /*The Serial monitor section is for debugging purposes, or for general interest, one, once the device is functioning correctly, can be disabled. Use it to see if your LDRs are noticeably different when they have equal light shining on them.*/ 

  Serial.print(eastLDR); 
  Serial.print(" - "); 
  Serial.print(westLDR); 
  Serial.print(" - "); 
  Serial.print(difference); 
  Serial.print(" - "); \
  Serial.print(servoSet); //Fine tune the servo settings, to maximise swing available 
  Serial.print(" - "); 
  Serial.println("."); 
  delay(100); 
}

Voltage reader code

const int num_samples=10; 
int sum = 0; // sum of samples taken 
unsigned char sample_count = 0; // current sample number 
float voltage = 0.0; // calculated voltage  

void setup() {
  Serial.begin(9600);
} 

void loop() {
      while (sample_count < num_samples) {//adds 10 sample values
         sum += analogRead(A2);
         sample_count++;
         delay(50);
      }
      voltage = ((float)sum /(float)num_samples * 5.0) / 1024.0; /*averages values then puts in terms of volts*/  
      Serial.print (voltage*1.2);//displays initial voltage (before resisted)
      Serial.println (" Volts"); //writes volts
      sample_count=0; //resets values
      sum=0; }

Leave a Comment

Start typing and press Enter to search

Bluestamp Engineering