I want to connect a light sensor to an Arduino Uno.
Directly connected with an analog input port, the values from the light meter come in fine when testing the setup inside on my desk.
If, however, I want to operate the device outside in sunlight, I need to put an additional resistor in the analog signal wire. Else I only get a "totally bright" reading all the time with no differentiation.
Now I would prefer if I did not have to change the hardware setup depending on the location.
If I have to take the device inside for testing or debugging, I would like to simply change a parameter in the configuration of the code and be good to go.
My thought: Is it possible to connect the same wire from the sensor carrying the analog signal to two Arduino ports, one straight through (e.g. A0) and one via a 2k Ohm resistor (e.g. A1)?
Then in the code define only A0 or A1 as an input port for the reading, depending on whether I am in my study or the yard?
Or will this not work - or even destroy my Arduino?
Could you provide a link to the EXACT sensor you are using?
I THINK the extra electronics will cause you a problem as you really want to auto-range switch.
That would be easier if you used a simple LDR with a logic output switching an additional load resistor - like this
If the LDR and series resistor can be connected so that when the light is bright, the voltage at the analog input pin is low and when it is dim, the voltage is high, then the sketch can do the following:
First, set analogReference(EXTERNAL) which is 5V for Uno. Then take an analogRead() from the pin and calculate the voltage. This will have a precision of about 5/1000 = 5mV
If the calculated voltage is below 1V, the sketch will then change to analogReference(INTERNAL_1V) and use analogRead() to take a second reading from the pin and re-calculate the voltage. This second reading will have a precision of about 1/1000 = 1mV.
In reality, I think the internal reference voltage is 1.1V and the max value from analogRead() is 1023 not 1000, of course!
However, this idea may not work at all with the sensor module that @jsiebrecht has, because it may not give low voltage at high brightness. This type of sensor module is not very flexible. I was imagining use of a bare LDR and resistor, which can be connected in the required way (LDR between the analog pin and ground, fixed resistor between the pin and 5V).
I'll tell you a secret. For your purpose, the module doesn't in fact do anything. All you really need is an LDR and a resistor. They can be connected directly to the Uno's analog pin.
The module from post#6 seems to have the LDR connected to ground, with a 10k pull up resistor.
Yes, you can safely connect another digital pin to A0 via a 1k resistor for auto ranging.
Set the pin with pinMode to INPUT for indoors, and to OUTPUT/HIGH for outside.
Switching the digital pin between input and output eliminates the need for a diode.
Leo..