You are on page 1of 4

Arduino Solar Tracker

Explore

Create

Contests

Community

let's make

Login

Sign Up Log In

share what you make >

Arduino Solar Tracker by geo bruce


Download 5 Steps + Collection Favorite

Step 5: The Code


you can download the code down this page /* this code is written by geobruce for more info check my site http://xprobe.net */ #include <Servo.h> // include Servo library Servo horizontal; // horizontal servo int servoh = 90; // stand horizontal servo Servo vertical; // vertical servo int servov = 90; // stand vertical servo // LDR pin connections // name = analogpin; int ldrlt = 0; //LDR top left int ldrrt = 1; //LDR top rigt int ldrld = 2; //LDR down left int ldrrd = 3; //ldr down rigt void setup() { Serial.begin(9600); // servo connections // name.attacht(pin); horizontal.attach(9); vertical.attach(10); } void loop() { int lt = analogRead(ldrlt); // top left int rt = analogRead(ldrrt); // top right int ld = analogRead(ldrld); // down left int rd = analogRead(ldrrd); // down rigt int dtime = analogRead(4)/20; // read potentiometers int tol = analogRead(5)/4; int avt = (lt + rt) / 2; // average value top int avd = (ld + rd) / 2; // average value down int avl = (lt + ld) / 2; // average value left

About This Instructable

66,855 views 170 favorites

Posted: Jul 3, 2011 License:

geo bruce
Follow 101

Bio: Hello, I'm Bruce. I'm a student at Don Bosco Hoboken in Belgium. I have a wide variety of interests: electronics, computers, technology, ... In my spare time I spend a lot of time on: projects, explor...read more

More by geo bruce

Tags: Arduino Solar light servo cool energy

http://www.instructables.com/id/Arduino-Solar-Tracker/step5/The-Code/[25-Sep-2013 1:20:26 AM]

Arduino Solar Tracker

int avr = (rt + rd) / 2; // average value right int dvert = avt - avd; // check the diffirence of up and down int dhoriz = avl - avr;// check the diffirence og left and rigt

sun tracking following sensor

Related
if (-1*tol > dvert || dvert > tol) // check if the diffirence is in the tolerance else change vertical angle { if (avt > avd) { servov = ++servov; if (servov > 180) { servov = 180; } } else if (avt < avd) { servov= --servov; if (servov < 0) { servov = 0; } } vertical.write(servov); } if (-1*tol > dhoriz || dhoriz > tol) // check if the diffirence is in the tolerance else change horizontal angle { if (avl > avr) { servoh = --servoh; if (servoh < 0) { servoh = 0; } } else if (avl < avr) { servoh = ++servoh; if (servoh > 180) { servoh = 180; } } else if (avl == avr) { // nothing } horizontal.write(servoh); } delay(dtime); }
Boe Bot/Arduino line following robot by red_green

Arduino Solar Tracking Robot by Bot1398

Arduino 2-axis servo solar tracker by aplavins

light detection + data logging white arduino by DKN

DIY Arduino PIR Motion Sensor Lighting & Security by sspence

See More

solar_tracker__english_.pde

1 KB

http://www.instructables.com/id/Arduino-Solar-Tracker/step5/The-Code/[25-Sep-2013 1:20:26 AM]

Arduino Solar Tracker

Remove these ads by Signing Up

Previous

View All Steps Next

Post Comment

Yasesu says: Could you add a parts list to the instructions? Thanks

Dec 14, 2012. 9:11 AM

Reply

geo bruce (author) in reply to Yasesu done ;)


5

Dec 14, 2012. 9:22 AM

Reply

Yasesu in reply to geo bruce

Dec 14, 2012. 11:59 AM

Reply

Thank you. That is great. I have a 3 panel 45W solar panel from Harbor Freight. I've been looking at ideas to keep the panels facing the sun. Now I just need to take your idea, and make it bigger. I need to find some large servo motors.

geo bruce (author) in reply to Yasesu if you want to go big you can better go for stepper motors and change the code a little bit
5

Dec 14, 2012. 1:30 PM

Reply

tolstoyan in reply to geo bruce

Jan 24, 2013. 2:56 AM

Reply

hello geo bruce im a beginner here at the arduino so im not really a code jockey, can you please tell me which part of the code do i have to modified and what exactly to replace if any, thanks because im planning to build this its just that i bought stepper motor instead of servo

http://www.instructables.com/id/Arduino-Solar-Tracker/step5/The-Code/[25-Sep-2013 1:20:26 AM]

Arduino Solar Tracker

Rene Artois in reply to tolstoyan

Jul 27, 2013. 2:01 AM

Reply

You can't drive stepper motors directly with arduino. It will burn. Use arduino stepper motor shield insted. It can handle bigger loads.

About Us
Who We Are Advertise Contact Jobs Help

Find Us
Facebook Youtube Twitter Pinterest

Resources
For Teachers Artists in Residence Forums Answers

Mobile
Visit Our Store Download our new apps for iOS and android! Go Pro Today Android iOS

Join our newsletter:


Join! Join!

Copyright 2013 Autodesk Inc. All rights reserved Terms of service | Privacy | Legal Notices & Trademarks | Mobile Site

http://www.instructables.com/id/Arduino-Solar-Tracker/step5/The-Code/[25-Sep-2013 1:20:26 AM]

You might also like