One Sensor on two ports? - Possible?

Hi all,

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?

Many thanks for your help!

Cheers,
Jan

Welcome to the forum

Why not add a physical switch to change between the ranges then you only need to use a single pin

Yes it's safe. Whether it will work depends on the sensor type, what are you using?

1 Like

Maybe using the analogReference() function could enable the Arduino to measure the light level more precisely in indoor & outdoor situations?

If you connect the LDR and choose an appropriate value for a single resistor so that in indoor signal is 1V to 5V and outdoor it is 0V to 1V.

Your code could automatically switch to the most appropriate range.

1 Like

That would be possible, too if I can find an adequate switch.

Thanks for confirming I will not total my Arduino by short-circuiting A0 and A1.
The sensor is something like this:
image

I like your idea Paul.
I'll check if I can pull it off with the proper ranges.

Right :slight_smile:

If the sensor delivers 5V at most then a reduction of the signal to 1V will reduce the resolution by the same factor, making things worse not better.

Please show your circuit diagram(s).

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
image

1 Like

If you are using the light sensor shown in post #6, I don't see how that could actually reduce the voltage.

I will explain my idea in more detail.

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).

1 Like

Thank you all!
I guess I will just have to try it out and keep my fingers crossed that indeed it will not permanently damage my board.

If it will not work, I might have to get my light meters a pair of sunglasses when out in the sun...
LOL

Why do you think it might damage your board? Is there something you have not told us, or something we missed?

I assume your module looks like this?

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..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.