So I made a simple voltage divider with LDR, to let some servos do work if its dark and if it's light, I need them to stop. No problem there. However, the values that my LDR gets are always lower than 90/100. Not once has it been above that. As to my understanding the analog to digital with 5V should be between 0 and 1023. What is the problem here?
Im not sure if I can post links (whether it's allowed), but this is the circuit I have built and with the same code:
https://maker[dot]pro/arduino/tutorial/how-to-use-an-ldr-sensor-with-arduino
I have tried multiple resistors from 10k ohm to 100kohm, 2 different lightsensors, but I keep getting the same value. always below 100 (dark around 20, light around 80)
my code:
#include <Servo.h>
// create servo object to control a servo
Servo servo1; //servo1 = down
Servo servo2; //servo2 = start
Servo servo3; //servo3 = select
Servo servo4; //servo4 = a
Servo servo5; //servo5 = b
int sensorPin = A4;
int sensorValue = 0;
int minLight; //Used to calibrate the readings
int maxLight; //Used to calibrate the readings
int lightLevel;
int rest = 90;
int servo1press = 155; //155
int servo1release = 35; //35
int servo2press= 90; //190
int servo2release = 90; //160
int servo4press= 90; //25 //90
int servo4release = 90; //90
int servo5press= 90; //90
int servo5release = 90; //160 //90
int pos = 0; // variable to store the servo position
void setup() {
servo1.attach(9); // attaches the servo on pin 9 to the servo object
servo4.attach(10);
servo5.attach(11);
servo2.attach(3);
minLight=15;
maxLight=20;
Serial.begin(9600);
}
void loop() {
sensorValue=analogRead(sensorPin);
//if((minLight<lightLevel) &&(maxLight>lightLevel)){
servo1.write(rest);
delay(1000);
servo1.write(servo1press);
delay(600);
servo1.write(rest);
delay(1000);
servo1.write(servo1release);
delay(600);
servo1.write(rest);
delay(300);
servo2.write(servo2press);
delay(300);
servo2.write(servo2release);
delay(300);
servo4.write(servo4press);
delay(300);
servo4.write(servo4release);
delay(300);
servo5.write(servo5press);
delay(300);
servo5.write(servo5release);
delay(300);
sensorValue = map(sensorValue,0,1023,0,100);
Serial.println(sensorValue);
//exit(0);
//}
}