0

I have a project that has a photoresistor wired into a voltage divider and connected through a 3.5mm “stereo mini plug”. When nothing is in the mini plug, the analog line is an open circuit, and floats, creating jittery spurious readings.

I’d like to wire a pull-down resistor into the project box to tie it to ground so I get a zero reading when the light sensor is not connected, but want to alter the voltage reading from my photo sensor voltage divider circuit as little as possible.

If I connect a 100KΩ resistor between my analog input and ground, that would give me zero readings on the analog pin when the photo sensor is not plugged in, wouldn’t it? I can’t see how < 20 CM of 26 gauge wire would pick up enough interference to pull my analog pin up from 0 through a 100kΩ resistor.

What is the effective range of an analog pin on an Arduino? (A Mega 2560, if that matters) What’s the lowest voltage that will register above 0?

(The project box is getting crowded, so experimenting is getting tricky. I’d like to make a single change rather than trying different resistor values.)

2
  • To whoever voted to close as not being about Arduino, how is this not about Arduino? My question is about the behavior of the analog pins on an Arduino Mega.
    – Duncan C
    Feb 9, 2019 at 15:04
  • Sound fine to me. I'd probably even go with a higher value. You'd have to do the calculations as to how it would affect the readings of the photoresistor. PS. A lot of 3.5mm sockets have switches in them to detect if there is something plugged in. You could use one of those switches to connect the analog pin directly to ground if nothing is connected. Or you could connect it to a digital pin, and have the software ignore the analog input.
    – Gerben
    Feb 9, 2019 at 15:36

2 Answers 2

1

I would expect a 100K pulldown to quiet the A/D, but I'd have to actually try it. I'd think testing it on the bare board, outside of your project box would still give you useful information. But I would sketch up the schematic of the proposed voltage divider with the parallel pulldown and run the numbers to convince yourself of what effect it will have on your measurement. You may be able to ignore it, or you may want to correct for it.

What is the effective range of an analog pin on an Arduino?

0 - (1023/1024)*Vref, whichever reference, 1.1v, 2.56v, or Vcc applied to the Vref pin, you have selected.

(A Mega 2560, if that matters) What’s the lowest voltage that will register above 0?

Appx (Vref * 2^-11), i.e., 1/2 an LSB of the 10-bit A/D range.

Update:

Is that a jumper selection?

No, it's programmable; the external Vref is reset default. See ch. 25 of the 2560 datasheet for the low-level details; Arduino.cc's function-reference, for the analogReference() function for the quick & dirty how-to. Remember to take and discard a measurement whenever you change the reference.

2
  • Is that a jumper selection? (I haven’t changed anything on the factory settings on my Arduino.) Based on the testing I did when I was building the voltage divider, it seemed to treat 5V as max, which is what I expected.
    – Duncan C
    Feb 9, 2019 at 15:12
  • Thanks for the thorough answer. (Voted). I do have a 4 channel 5V (optically isolated) relay inside the box that switches 120VAC outlets at up to 10a, and will also be driving a pulsed 9V electromagnet (which will be outside the case) with about 200 mA of current, but the Arduino and it’s low power components, the relay, and the electromagnet all have separate power supplies. So there may be a fair amount of electromagnetic noise inside the box.
    – Duncan C
    Feb 9, 2019 at 18:20
1

With a 100 kΩ resistor to GND, it is not guaranteed that the value will be zero. If a (servo)motor is connected, it might get some noise.

The pull down resistor can be any value, because it is possible to calculate the value of the photoresistor.

There is an alternative solution. I think that all the analog pins of the Arduino Mega 2560 are digital pins as well. You can do a pinMode(A0,INPUT_PULLUP); to pull the input high. When a photoresistor is connected, you can turn the internal pullup resistor off with pinMode(A0,INPUT);.

5
  • To repeat my comment on JRobert's answer: I do have a 4 channel 5V (optically isolated) relay inside the box that switches 120VAC outlets at up to 10a, and will also be driving a pulsed 9V electromagnet (which will be outside the case) with about 200 mA of current, but the Arduino and it’s low power components, the relay, and the electromagnet all have separate power supplies. So there may be a fair amount of electromagnetic noise inside the box.
    – Duncan C
    Feb 10, 2019 at 12:05
  • I tried it with a 100K resistor, and sure enough, when the relays are active and driving AC loads, the analog input still picks up noise. In fact it looks a lot like 60 Hz noise. I guess I need lower value resistor, and to just adjust for the lower voltage into my analog input.
    – Duncan C
    Feb 10, 2019 at 12:07
  • @DuncanC do you use the average of a number of samples? That is often done to reduce noise. However, noise around zero volt will not average to zero, but it will average to the positive part of the noise above zero.
    – Jot
    Feb 10, 2019 at 15:15
  • I don't do averaging yet. I like that idea (a software change) better than opening up the box and swapping out the resistor.
    – Duncan C
    Feb 10, 2019 at 15:21
  • Averaging was a good idea. It works well. Thanks for the suggestion. I should have thought of that.
    – Duncan C
    Feb 11, 2019 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.