Photo or LDR and being able to get a usable input regardless of presence

Sorry for the wording of the question, I couldn't articulate it in such a short space.

I am developing a prototype board that utilises a LDR to set the backlight PWM value, so if the room is dark, so too is the LCD backlight. And if the room is bright, again, so too is the LCD. It works well.

I have a number of these boxes, and some have the LDR and some do not. Now I know that I could just code each box independently (a bit of a pain, but a #define could do the trick), alternatively, I could set an EEPROM value to indicate the presence of the LDR and code around that, although neither solution helps if the situation changes, ie a suitable LDR (via a grove connector) is plugged in or removed.

The LDR I am using is attached via a grove connector and I got it from Seeedstudio ( http://www.seeedstudio.com/depot/Grove-Light-Sensor-p-746.html ) so it has a resistor already in the connection.

But if the connector is removed the input floats, and it can do so quite substantially, causing the LCD backlight to constantly be changing. My immediate thought was to turn the pull up resistor on, but I've come to realise that this is counter productive because it's a pull-UP resistor and would in theory be across the LDR if it was present, so I would probably need a pull-down resistor. Alternatively (and now this is where I really show my electronics skills), I put the LDR between the analog pin and ground, and the resistor to 5v, and then have the pull up activated so that if on some boxes it's not present, then it's pulled high anyway (obviously I have to reverse my code regarding the reversal of LDR).

However, it hasn't quite gone as expected, and nor is it practical since the grove connectors are hard wired and unless I chop and change them, it's not going to happen.

So my next train of though revolves around having TWO resistors between the analog pin and ground. One that is a part of the grove connector, and one to pull the input low if there's nothing connected (and as I typed that I can already see that's not going to work since I need the pin to be pulled HIGH, not low).

Is there a resistor of suitable value I could put across the LDR that would allow it to function as required when it is present, that would also allow the circuit to function as desired when it's not?

As I said earlier, I can always incorporate a setting saved to eeprom to get around it, and it's easy enough to do, I just thought I would canvass this avenue first.

Thanks

You can not determine something with a floating input. A floating input can give a steady voltage or noise or 50Hz/60Hz mains noise or something else. So you need to do something.
If nothing is connected you would like to have something that does not influence if a sensor is connected.

The most common way to solve this in an Arduino is to use a second Arduino pin.
A pin can have a big influence when it is set as output, and have no influence at all if it is set as input.
So you could connect the analog input to a 10k resistor to a digital pin. Toggle that output high and low and see what happens at the analog input pin. Set that digital pin as input, to avoid any influence.

As far as I understand, the grove light sensor has an opamp that is set as voltage follower. It only makes the output signal low impedance. I assume you use an analog input for that signal. If my assumptions are right, a 10k resistor to a digital pin would work fine.
However, if you use a LDR sensor + resistor without the opamp, the signal is high impedance. In that case you might need a 100k resistor to the digital pin.

Caltoa:
If nothing is connected you would like to have something that does not influence if a sensor is connected.

You've understood me perfectly :slight_smile:

As far as I understand, the grove light sensor has an opamp that is set as voltage follower. It only makes the output signal low impedance. I assume you use an analog input for that signal. If my assumptions are right, a 10k resistor to a digital pin would work fine.

You are correct, it is a grove and it does have an opamp, but...

However, if you use a LDR sensor + resistor without the opamp, the signal is high impedance. In that case you might need a 100k resistor to the digital pin.

One unit is done this way. ie, I had a spare LDR floating around and so I've popped it onto the board. Since this one is now wired in, I don't need to test it. Any removable ones will in fact be grove connectors.

Thanks very much for your help here.

If only the grove modules are used, it can be very simple

Connect an extra digital pin via 10k to the analog input.
Test it for example with 5% upper and lower limit.

  • Set digital pin to output and HIGH
  • Wait 1ms to let voltage settle
  • Measure analog input : wADC_high
  • Set digital pin to output and LOW
  • Wait 1ms to let voltage settle
  • Measure analog input : wADC_low
  • Set digital pin to input, to stop any influence
  • If wADC_high > 972 and wADC_low < 51 the input is floating