light sensor controlling servo motor

#include <Servo.h>

Servo servo1;
int sensorPin = 0; // light sensor is on analog in 0
int sensorValue01 = 0;

void setup() {
servo1.attach(8);
}

void loop() {
sensorValue01 = analogRead (sensorPin); //value of the light sensor, normaly between 0 ad 1023
int angle = sensorValue / 6; // to obtain angle between 0 and 170
angle = angle + 5; // to obtain value between 5 and 175
servo1.write(angle); //move the servo
Servo::refresh(); // necessary with this library
delay(10); // to cool the jitter…
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: