Mako
Published

Arduino Sunflower

The sunflower follows the light using a servo motor and two photoresistors.

BeginnerFull instructions provided6 minutes79,204
Arduino Sunflower

Things used in this project

Story

Read more

Schematics

Sunflower Schematics

Code

Solar Tracker Code

C/C++
#include <Servo.h>

int sensorPin = A0;
int servoPin  = 9;

int sensorValue = 0;
int servoGrad = 90;
int tolerance = 40;

Servo myservo;

void setup() {
  pinMode( sensorPin, INPUT);
  myservo.attach( servoPin );
  myservo.write( servoGrad );
}

void loop() {
  sensorValue = analogRead(sensorPin);
  if ( sensorValue < (512-tolerance) )
  {
    if (servoGrad < 180) servoGrad++;
  }

  if ( sensorValue > (512+tolerance) )
  {
    if (servoGrad > 0) servoGrad--;
  }

  myservo.write( servoGrad ); 

  delay(100);
}

Credits

Mako

Mako

4 projects • 49 followers
Welcome to Mako! Visit the website for complete projects

Comments