i done it a few days ago without knowledge of this post..
It looks like this: Arduino + Cheapservo + ldr = Servo dj - YouTube
The code that i used was a little bit botched.. and it can be easy improved making that to do a high light mesurement and a low light mesurement.. it has been modified so many times thats why there are a lot of variables and is too long ![]()
I'm newbie on programming and it works so i'm happy with the result.
#include <Servo.h>
Servo servo1;
int valoranalogic;
int Pinanalogic = 4;
int marje = 800;
int led = 13;
int marje1;
int marje2;
int marje3;
void setup() {
pinMode(1,OUTPUT);
servo1.attach(14);
servo1.setMaximumPulse(2200);
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(200);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
marje1 = analogRead(Pinanalogic);
delay(100);
marje2 = analogRead(Pinanalogic);
delay(100);
marje3 = analogRead(Pinanalogic);
delay(100);
marje = (marje1 + marje2 + marje3) / 3;
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
}
void loop() {
static int angle = 0;
valoranalogic = analogRead(Pinanalogic);
angle = (valoranalogic - marje) * 2 ;
servo1.write(angle);
Servo::refresh();
}
I'm working now in a servo robot arm controlled with arduino..
I doesn't have the final desing decided.. i will be similar as lynxmotion arm.. but with the cheapest servos that i could find, the dynam 34g.