Ivan RamosDaniel Law
Created April 5, 2021

Arduino Sun Tracker

simple code with simple wiring to roughly track sun movement

48
Arduino Sun Tracker

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Photo resistor
Photo resistor
×2
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Hand tools and fabrication machines

Scissors, Free Fall
Scissors, Free Fall

Story

Read more

Schematics

Sun Tracker Schematic

Positioning of components on schematic is not accurate to positioning of components in project. Refer to instructions above.

Code

Tracker Code

C/C++
Entire simple code for project
// Servo - Version: Latest 
#include <Servo.h>

Servo spinnyboi;

int left = 0;
int right = 0;
int offset = 0;

void setup() {
  Serial.begin(9600);
  
  spinnyboi.attach(6);
  spinnyboi.write(90);
  
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
}

void loop() {
  left = analogRead(A0);
  right = analogRead(A1);
  
  Serial.println(right);
  Serial.println(left);
  Serial.println("\n");
  
  offset = int(right) - int(left);
  
  if (offset >= 30)
  {
    spinnyboi.write(150);
  }
  if (offset <= -30)
  {
    spinnyboi.write(30);
  }
  
  spinnyboi.write(90 - offset*2); //2 for angle difference
  
  delay(2000); //seconds you want delayed * 1000
}

Credits

Ivan Ramos
3 projects • 1 follower
Daniel Law
47 projects • 10 followers
Teacher. Maker. Citizen of the planet.

Comments