// Control a servo motor with a photoresistor
int servoPin = 2; // Control pin for servo motor
int minPulse = 500; // Minimum servo position
int maxPulse = 2000; // Maximum servo position
int pulse = 0;
int analogValue = 0; // the value returned from the analog sensor
int analogPin = 0; // the analog pin that the sensor's on
void setup() {
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pulse = minPulse; // Set the motor position value to the minimum
Serial.begin(9600);
}
void loop() {
analogValue = analogRead(analogPin);
pulse = map(analogValue,600,1023,minPulse,maxPulse);
analogWrite(servoPin, pulse);
Comments
You can follow this conversation by subscribing to the comment feed for this post.