My project is to make an automatic window blinds. I want to adjust the blinds according to the light level, but the LDR sensor module giving output of 1023 or 32 only depending upon the light. I want the mid values (values in between 1023 to 32) to rotate the window blinds slightly. I can only open or close them. Earlier, the sensor was working fine, detecting all the values, but now with the same connections its not giving correct values.
Here's my code below :
#define ldr A0
void setup() {
// put your setup code here, to run once
pinMode(ldr, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int val = analogRead(ldr);
if(val >= 30 && val <= 50)
{
Serial.println("VERY BRIGHT");
}
else if(val >= 100 && val <= 150)
{
Serial.println("BRIGHT");
}
else if(val >= 200 && val <= 500)
{
Serial.println("DIM");
}
else if(val >= 500 && val <= 600)
{
Serial.println("LOW LIGHT");
}
else if(val >= 600 && val <= 900)
{
Serial.println("VERY LESS LIGHT");
}
else if(val >= 900 && val < 1023)
{
Serial.println("DARKER THAN BLACK HOLE");
}
//delay(1000);
}
If Vcc changes sensor values will likely change. Link to the datasheet please.
What is "correct value"? What values are coming?
Why check for values being between 30 and 50? Why not go for just below 50? Why is 29 exckuded?
1023 likely means a bad connection. Either the signal line is shorted to Vcc or the pull-down side of the voltage divider is open-circuit. Try a new light sensor module.
"DO" means "Digital Output". You need the other pin.
I just noticed that there are many cheap modules with only a digital output and not a analog output. What else do you have ? Resistors, LDR, multimeter ?
@Koepel I saw a setup video from YouTube. I have done all the connections according to it. Thanks for giving your time. I am using LDR for the first time.
Video links :
I really need all the values from 32. - 1023
I tried using the digital pin, but they show 0 in absense of light or 1 in presence of light.
The module that you have has only a digital output. There is a link under that Youtube video to the sketch on Github. That shows that a digital pin is used.