I try to control the rotation of the servo(0-120 degrees) with a photoresistor. When I connect a 470-ohm resistor in series with the photoresistor, the range of motion of the arm is usually between (0-15 degrees) unless I shine a really bright light. However, when I use a 2.2k resistor the arm can rotate in full motion without I shine other light. I wonder why analog in Pin doesn't measure a high voltage when I use a small resistor.
#include <Servo.h>
Servo myServo;
int const photSenserPin = A0;
int photVal;
int angle;
void setup() {
myServo.attach(9);
Serial.begin(9600);
}
void loop() {
photVal = analogRead(photSenserPin);
Serial.print("photVal: ");
Serial.print(photVal);
angle = map(photVal, 0, 1023, 0, 120);
Serial.print(", angle: ");
Serial.println(angle);
myServo.write(angle);
delay(15);
}
Untitled document.pdf (446 KB)