I have a project to make a light sensor which will measure the level of transmitted light via a glass with different coatings on it .
So far i managed to get the LED switching, light sensor wiring and even the display working.
BUT i am not able to read out the sensor data from A0 in the state "no" and "off" correctly. Somehow the seem to be reversed. Meaning i get higher values for led off then on...
Is your LDR connected to ground an A0, and with a resistor from A0 to 5V ?
With more light the resistance of the LDR gets lower, so the voltage at A0 gets lower.
I think everything is working as it should.
I think everything is connected as supposed to. If i just write a code without the LED switching ON and OFF and i just read the A0 where the light sensor is connected and close the black box i read low values (about 10), if i open the black box i read higher values (700-800) as it should. I even tried to use an external LED and have the right response... So i must assume it is the code what is wrong..
My point is in the code:
Void Loop ()
{
Read A0 value at no light state
Switch on a LED
Read A0 vale at a lit state
}
I am thinking that i cannot read twice A0 in the loop.. But that is strange to my mind...
It might be the 5V power. Can you try a seperate power supply for the Arduino ?
You power everything from the usb ? That is less than 5V.
The backlight of the display needs current, and that led in the box seems to be pretty bright.
The 5V is used as the reference voltage for the analog inputs.
You can read analogRead() as many times as you like. Just once, or thousand times, that's okay.
When you goal is to measure coatings, I would recommand a RGB sensor, and even beyond the vissible: UV and IR leds and sensors.
This is just one sensor, there are so many:
You might even want to measure deep IR: heat waves. That is what HR++ glass will block. I don't know if that can be measured with a contact-less temperature sensor pointing to the glass.
It is not the power supply... I have now connected the uno to an external power source and it seems the readings are still lower when the LED is ON. I really don't think the board cannot handle the stock LED and light sensor in the same time, so must be the code itself...
I read the posts once again, and finally I think I have something that makes sense
You read the LDR directly after the LED is turned on or off. The led is fast, but the LDR is very slow, about 100ms response time.
Can you have delay of 200ms or 500ms before you read A0 ?