![](https://static.wixstatic.com/media/12fdfe_7c882d0fb2134c94a5e371be5afe8865~mv2.png/v1/fill/w_378,h_600,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/12fdfe_7c882d0fb2134c94a5e371be5afe8865~mv2.png)
Justin W.H. Yuen
![20180909_012859_HDR.jpg](https://static.wixstatic.com/media/12fdfe_f8ad1e33101346d38d85e5f231e55fd1~mv2_d_5312_2988_s_4_2.jpg/v1/crop/x_1057,y_992,w_3198,h_1479/fill/w_979,h_454,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/20180909_012859_HDR.jpg)
![](https://static.wixstatic.com/media/12fdfe_68dd82ded0ca4093a5f7e777bf2958bef002.jpg/v1/fill/w_977,h_550,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/12fdfe_68dd82ded0ca4093a5f7e777bf2958bef002.jpg)
This was my first project where I designed and built an idea from the ground up. It was also my first time working with an Arduino and solar panel.
Goal
Program an Arduino to find and face the brightest source of light
Status
Complete
![](https://static.wixstatic.com/media/12fdfe_30bcee71e1a14e68b646b7eabbd8de72~mv2.gif)
What inspired me to start this project was seeing new ships and boats taking advantage of solar panels to power their motors. To visualize my ideas, I learned how to make a phone app with Unity that would allow me to see my 3D CAD file using augmented reality.
![IMG_9566.JPG](https://static.wixstatic.com/media/12fdfe_371e3691aae9452796cb051046b5eea8~mv2_d_5184_3456_s_4_2.jpg/v1/fill/w_495,h_330,al_c,q_80,usm_0.66_1.00_0.01,enc_auto/IMG_9566_JPG.jpg)
![IMG_9572.JPG](https://static.wixstatic.com/media/12fdfe_778b06d5df6c47ce8be5a3813348ff3e~mv2_d_5184_3456_s_4_2.jpg/v1/fill/w_494,h_329,al_c,q_80,usm_0.66_1.00_0.01,enc_auto/IMG_9572_JPG.jpg)
I used affordable and lightweight balsa wood from local arts and crafts stores to build the tower of the solar panel.
![IMG_9599.JPG](https://static.wixstatic.com/media/12fdfe_fe5762f599dc4066a5db4a8254dc90e1~mv2_d_5184_3456_s_4_2.jpg/v1/fill/w_493,h_329,al_c,q_80,usm_0.66_1.00_0.01,enc_auto/IMG_9599_JPG.jpg)
![IMG_9624.JPG](https://static.wixstatic.com/media/12fdfe_55ed25eba2eb4e7ca94d28ff773511e2~mv2_d_5184_3456_s_4_2.jpg/v1/fill/w_493,h_329,al_c,q_80,usm_0.66_1.00_0.01,enc_auto/IMG_9624_JPG.jpg)
Although wood cuts easily, bringing the saw down slowly gives a cleaner cut.
![IMG_9635.JPG](https://static.wixstatic.com/media/12fdfe_7724500299454871b33ca5e32be506d4~mv2_d_5184_3456_s_4_2.jpg/v1/fill/w_492,h_328,al_c,q_80,usm_0.66_1.00_0.01,enc_auto/IMG_9635_JPG.jpg)
![IMG_9634.JPG](https://static.wixstatic.com/media/12fdfe_285811f0410745bd93338705f91b5e5f~mv2_d_5184_3456_s_4_2.jpg/v1/fill/w_494,h_329,al_c,q_80,usm_0.66_1.00_0.01,enc_auto/IMG_9634_JPG.jpg)
Blocks of balsa to form the tower and the solar panel (black square).
![](https://static.wixstatic.com/media/12fdfe_fc36611be2444870b837f3d783576b64~mv2.gif)
How the servo motor would rotate the solar panel and its range of motion.
![20180909_012306_HDR.jpg](https://static.wixstatic.com/media/12fdfe_8c22fe8f473645b7bd5fe6d8f27e18e8~mv2_d_5312_2988_s_4_2.jpg/v1/fill/w_978,h_550,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/20180909_012306_HDR.jpg)
Full assembly of the Arduino-controlled solar panel.
![IMG_1219.JPG](https://static.wixstatic.com/media/12fdfe_126a7ad79e6b4704aa5c400da6b9ae90~mv2_d_5184_3456_s_4_2.jpg/v1/fill/w_962,h_641,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/IMG_1219_JPG.jpg)
My Arduino Code
Feel free to ask me to clarify any lines in the code. I would be glad to help!
//adding LDRs
const int ldrPinL = A0; // white for left
const int ldrPinR = A1; //purple for right
const int ldrPinF = A2; //yellow for front
const int ldrPinB = A3; //blue for back
// one end of ldr to power, other to ground. must add resistor or value too low
//photoresistors used are 5505 - resistance ranges between 2-6kOhm
//adding servos
#include <Servo.h>
Servo servot; //top servo
Servo servob; //bottom servo
int angle; //angle is gonna represent the angle of the servos
void setup() {
Serial.begin(9600);
pinMode(ldrPinL, INPUT);
pinMode(ldrPinR, INPUT);
pinMode(ldrPinF, INPUT);
pinMode(ldrPinB, INPUT);
servot.write(110); //set initial angle to 150
servot.attach(2); //top servo connected to port 2
servob.write(110); //set initial angle to 150
servob.attach(7); //top servo connected to port 7
}
void loop() {
int ldrStatusL = analogRead(ldrPinL);
int ldrStatusR = analogRead(ldrPinR);
int ldrStatusF = analogRead(ldrPinF);
int ldrStatusB = analogRead(ldrPinB);
int differenceLR = (ldrStatusL-ldrStatusR); //difference between left and right LDRs
int differenceFB = (ldrStatusF-ldrStatusB); //difference between front and back LDRs
int initialangle = 150; //initial servo position
/*
Serial.println("left ldr is");
Serial.println(ldrStatusL);
Serial.println("right ldr is");
Serial.println(ldrStatusR);
Serial.println("front ldr is");
Serial.println(ldrStatusF);
Serial.println("back ldr is");
Serial.println(ldrStatusB);
*/
//Serial.println(differenceLR);
Serial.println("top");
Serial.println(servot.read());
//Serial.println(differenceFB);
Serial.println("bottom");
Serial.println(servob.read());
if (differenceLR>=40) {
//Serial.println("LR NOT CENTERED");
if (servob.read()<180) {
servob.write(servob.read()-10);
}
}
else if (differenceLR<=-40) {
//Serial.println("LR NOT CENTERED");
servob.write(servob.read()+10);
}
else{
// Serial.println("LR is centered!");
}
if (differenceFB>=40){
//Serial.println("FB NOT CENTERED");
if (servot.read()<180) {
servot.write(servot.read()+10);
}
}
else if (differenceFB<=-40) {
//Serial.println("FB NOT CENTERED");
servot.write(servot.read()-10);
}
else{
//Serial.println("FB is centered!");
}
delay(1000);
}