Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Techatronic
Published

Single axis solar tracker project tutorialUntitled

Single axis solar tracker project tutorial

IntermediateFull instructions provided3,592
Single axis solar tracker project tutorialUntitled

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

single axis solar tracker circuit

Code

single axis solar tracker code

C/C++
code
<!-- wp:code -->
<pre class="wp-block-code"><code>// Single axis solar tracker
// Techatronic.com
#include &lt;Servo.h&gt; //including the library of servo motor
Servo sg90;
int initial_position = 90;
int LDR1 = A0; //connect The LDR1 on Pin A0
int LDR2 = A1; //Connect The LDR2 on pin A1
int error = 5;
int servopin=9; //You can change servo just makesure its on arduino’s PWM pin
void setup()
{

sg90.attach(servopin);
pinMode(LDR1, INPUT);
pinMode(LDR2, INPUT);
sg90.write(initial_position); //Move servo at 90 degree
delay(2000);
}

void loop()
{
int R1 = analogRead(LDR1); // read LDR 1
int R2 = analogRead(LDR2); // read LDR 2
int diff1= abs(R1  R2);
int diff2= abs(R2  R1);

if((diff1 &lt;= error) || (diff2 &lt;= error)) {

} else {
if(R1 &gt; R2)
{
initial_position = initial_position;
}
if(R1 &lt; R2)
{
initial_position = ++initial_position;
}
}
sg90.write(initial_position);
delay(100);
}</code></pre>
<!-- /wp:code -->

Credits

Techatronic
72 projects • 127 followers
Electronic engineer

Comments