Solar Panel Sun Tracker- Phone Charger

My main project is the Solar Panel Sun Tracker. It has a bonus of being a phone charger as it uses free clean energy. The project follows the Sun’s movement across the sky. To track the sun, it uses a servo system controlled by an arduino for panel positioning.

Engineer

Kaasha M.

Area of Interest

Not sure; Education/Engineering

School

Saratoga High School

Grade

Incoming Sophomore

Final Milestone

to be added…

Third Milestone

to be added…

Second Milestone

to be added…

First Milestone

Circuit Diagram

Code for 1st Milestone

#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 readings

int westLDR = 0;

int difference = 0; //Create a variable to compare the two LDR’s

int error = 10;  // Variable for is there is a noticable difference between the tow 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 >=15) {     // if so, send panels back to east for the sunrise

      servoSet ++;

      servo.write(servoSet);

      delay(100);

    }

  }

 

  difference = eastLDR – westLDR ; //Check the difference 

  if (difference > 10) {          //Send the panel towards the LDR with a higher reading

    if (servoSet <= 140) {

      servoSet ++;

      servo.write(servoSet);

    }

  } else if (difference < -10) {

    if (servoSet >= 15) {

      servoSet –;

      servo.write(servoSet);

    }

  }

  Serial.print(eastLDR);      //Serial monitor can be useful for debugging/setting up

  Serial.print(”   – “); //Use it to see if your LDR’s are noticeably different when

  Serial.print(westLDR);      //They have equal light shining on them, if so, correct with the error value

  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);

}

My first milestone was to figure out how to use the photo resistor which is a light controlled variable resistor to turn the servo and trigger the LED. Basically, after I upload my code to the Arduino, the servo will turn and the LED will light up.  The servo rotates by the amount of light given to the photo resistor. Before coding the Arduino, I actually had to hook up all these components to a breadboard. It took me a while to figure out how to code the Arduino use the photo resistor to turn the servo as well as triggering the LED. But, after some time it worked! Unfortunately after some time of working, the Arduino was facing some issues uploading and it couldn’t find the right port to connect to which is Arduino Uno. After doing some research and watching some videos, I figured out how to solve the issue. I learned throughout this process was how to solve issues if the Arduino couldn’t upload the code. My next milestone will be to build the support structure for the solar panel to sit on and to mount the servo onto the structure. Thank you!

Starter Project: RGB LED Night Light

RGB LED Night Light

My starter project was the RGB LED Night Light.  It was extremely fun and easy to hook up into the breadboard. RGB stands for Red, Green, and Blue, and these three differently colored Light-Emitting Diodes (LEDs) are built into one component. For this project, I needed an RGB LED, a photo resistor, 3 330 ohm resistors, a 10k ohm resistor, 12 jumper wires, and a potentiometer. I also needed a breadboard and an Arduino Uno. I had to hook up all the components into the breadboard and input code into the Arduino. At first, my code was successfully uploading but nothing wasn’t happening. Then, I restarted my computer and it worked! To make the LED light up in bright light or using it in the day, you need to cover the photo resistor in order to make the resistance higher. A photo resistor is a light controlled variable resistor. To make the LED change color, you can twist the potentiometer. A potentiometer is a simple knob that provides a variable resistance, which we can read into the Arduino board as an analog value. Through the process of making this project, I learned how a breadboard works and how to input code into an Arduino. With the other attempted starter projects I did, I learned how to solder and desolder well and how to read resistor color code. I struggled with the light organ as I first put the LED’s on the wrong side and had to start over. I also struggled with the MintyBoost as I soldered the wrong resistors in the wrong places. My next milestone of my main project which is a solar panel phone charger will be to figure out how to use photo resistor to turn servo and trigger the LED. 

HOW IT WORKS

Circuit Diagram

Code for RGB LED Night Light

int photoresistor;          //variable for storing the photoresistor value

int potentiometer;          //this variable will hold a value based on the position of the knob

int threshold = 700;            //if the photoresistor reading is lower than this value the light will turn on

//LEDs are connected to these pins

int RedPin = 9;

int GreenPin = 10;

int BluePin = 11;

 

void setup() {

  Serial.begin(9600);           //start a serial connection with the computer

//set the LED pins to output

  pinMode(RedPin,OUTPUT);

  pinMode(GreenPin,OUTPUT);

  pinMode(BluePin,OUTPUT);

}

void loop() {

 photoresistor = analogRead(A0);         //read the value of the photoresistor

  potentiometer = analogRead(A1);

 

  Serial.print(“Photoresistor value:”);

  Serial.print(photoresistor);          //print the photoresistor value to the serial monitor

  Serial.print(”  Potentiometer value:”);

  Serial.println(potentiometer);          //print the potentiometer value to the serial monitor

 

  if(photoresistor < threshold){          //if it’s dark (the photoresistor value is below the threshold) turn the LED on

    //These nested if statements check for a variety of ranges and 

    //call different functions based on the current potentiometer value.

    //Those functions are found at the bottom of the sketch. 

    if(potentiometer > 0 && potentiometer <= 150)

      red();

    if(potentiometer > 150 && potentiometer <= 300)

      orange();

    if(potentiometer > 300 && potentiometer <= 450)

      yellow(); 

    if(potentiometer > 450 && potentiometer <= 600)

      green();

    if(potentiometer > 600 && potentiometer <= 750)

      cyan();

    if(potentiometer > 750 && potentiometer <= 900)

      blue(); 

    if(potentiometer > 900)

      magenta();  

  } 

  else {                                //if it isn’t dark turn the LED off

 

    turnOff();                            //call the turn off function

 

  }  

 

  delay(100);                             //short delay so that the printout is easier to read

}

 

void red (){

 

    //set the LED pins to values that make red    

    analogWrite(RedPin, 100);

    analogWrite(GreenPin, 0);

    analogWrite(BluePin, 0);

}

void orange (){

 

    //set the LED pins to values that make orange

    analogWrite(RedPin, 100);

    analogWrite(GreenPin, 50);

    analogWrite(BluePin, 0);

}

void yellow (){

 

    //set the LED pins to values that make yellow

    analogWrite(RedPin, 100);

    analogWrite(GreenPin, 100);

    analogWrite(BluePin, 0);

}

void green (){

 

    //set the LED pins to values that make green    

    analogWrite(RedPin, 0);

    analogWrite(GreenPin, 100);

    analogWrite(BluePin, 0);

}

void cyan (){

 

    //set the LED pins to values that make cyan    

    analogWrite(RedPin, 0);

    analogWrite(GreenPin, 100);

    analogWrite(BluePin, 100);

}

void blue (){

 

    //set the LED pins to values that make blue

    analogWrite(RedPin, 0);

    analogWrite(GreenPin, 0);

    analogWrite(BluePin, 100);

}

void magenta (){

 

    //set the LED pins to values that make magenta   

    analogWrite(RedPin, 100);

    analogWrite(GreenPin, 0);

    analogWrite(BluePin, 100);

}

void turnOff (){

 

    //set all three LED pins to 0 or OFF

    analogWrite(RedPin, 0);

    analogWrite(GreenPin, 0);

    analogWrite(BluePin, 0);

}

STEM Summer Camps Coding & Robotics Classes For Kids San Francisco Coding & Robotics Classes For Kids New York Coding & Robotics Classes For Kids Denver Coding & Robotics Classes For Kids Palo Alto STEM Summer Camps For Kids in New York STEM Summer Camps For Kids in Palo Alto STEM Summer Camps For Kids San Francisco STEM Classes For Kids in New York STEM Classes For Kids in Palo Alto STEM Classes For Kids in San Francisco Code Classes For Kids Code Classes For Kids in New York Code Classes For Kids in Palo Alto Code Classes For Kids in San Francisco STEM Summer Camps For Kids

Leave a Comment

Start typing and press Enter to search