Grace Sade
Published

Arduino Sunflower - an Electronic Sundancer

Why can't I make a electronic device inmitating this biomechanism.

BeginnerFull instructions provided83
Arduino Sunflower - an Electronic Sundancer

Things used in this project

Hardware components

Cardboard
×2
Foam board
×1
Stick
×1
3 pin crowtail cable
×6
Crowtail- Linear Potentiometer
×2
Crowtail- Light Sensor
×4
Crowtail- Pan- Tilt
×1
Crowduino With ATMega 328 V1.1
×1
Crowtail- Base Shield for Arduino x
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

sunlight_tracker.ino

ABAP
#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 ldrrd =0; 
int ldrld =1;
int ldrlt = 2; 
int ldrrt = 3; 
 


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
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

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);
} 

Credits

Grace Sade
2 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.