Wrong readings from voltage divider

Hello, I am implementing a straightforward IR emitter / receiver pair for short range rangefinding and have come across some strange behaviour.

I power the receiver from the board's 5V line, grounding it via a resistor to the board's GND, forming a voltage divider. I measure the voltage between the receiver and resistor to get the receiver's response. When measuring via multimeter, I get wonderfully variable readings, covering most of the 5V range.

So far so good. However, when I connect the board's analog pin, things get weird. I get beautiful readings as long as the multimeter is connected. The moment I disconnect the probes, the reading goes close to 1000+ and hovers there.

What is happening here? One theory I have is that the overall resistance of the divider is too big. I have measured that the receiver's resistance drops from astronomical values to around 50k at its low end. I have used a 530k resistor so that I get a nice range of values (receiver completely dominates when its resistance is high, resistor mostly dominates when it is low). However, it might be that the trickle of current going through the divider can't hold the voltage once the nasty ADC line joins the party.

I would think that I 'll have to compromise and lower the overall resistance of my divider, even if it means losing my excellent value range. However, why do things work so beautifully when the multimeter is connected? Obviously it does something wonderful and I 'd like to replicate that without having to tape the multimeter to the board. Any ideas what that something might be?

The ADC circuit in an Arduino charges a sample-and-hold capacitor to perform a read. If your source impedance is greater than about 10k ohms the sampling circuit can't charge up in time to get a good reading. This is probably the cause of your problem -- even if it doesn't exactly explain it. :slight_smile:

My very first (read kludgy) idea was, since most DMMs input impedance is about 10M ohms, you might just place a 10M ohm resistor in parallel or go down to 500k.

However, maybe your best bet is to isolate the Vdivider by using an op-amp voltage follower.

Unless you have a need to attach the IR sensor to +5V, I would swap the voltage divider so that I am reading the voltage across the sensor instead of the big R.

Let me know if this helps.

BTW, a lot of IR distance detectors (like the Sharp GP2Y0A21YK0F IR Range Sensor) output a voltage proportional to the range, that can be read easily by the Arduino without the voltage divider.

Thanks MaJiG. I didn't reply earlier because I wanted the sun to set so I could have identical conditions. I don't have an op amp and getting new hardware is a pain that I 'm going to avoid for the time being.

The emitter / receiver are not one unit, they are a pair I got on a whim when I saw them at a local shop and thought I could play with. Now, some more cool stuff happened. I swapped the resistor and receiver so I could read across the receiver like you suggested. Measuring via DMM, I was only getting about half the value range I was getting last night. Weird, I d' have thought the only difference would be that the high and low values would have swapped. I swapped them back to the original position and again, I only get half the range. The emitting LED seems OK, I can see it glowing when I look at it through a digital camera and the current going through it is the same. When the sensor is at the GND side of the divider, I get a rough range of 4.5V to 2.2V (46% of the value range).

Now, the funny thing is that the measurement has started working when only the board is connected. With the DMM connected, I get a rough range of 970 to 470 from the ADC (49% of the value range). With the DMM disconnected, I get roughly 1010 to 500 (again, 49%).

Thinking about this makes even less sense. These measurements are with the receiver on the GND side of the divider. This implies that the high values happen when the receiver has a high impedance and the low ones when it has a low one. Which implies that overall, the value of my divider is higher than yesterday. Which implies that the ADC should be tripping things up even more brutally. However, all that happens when I disconnect the DMM is that the measurements shift up a tiny bit.

One more thing that I observed is that the range of the sensor seems to have dropped. I didn't really make any measurements, but judging by eye, I am certain I was getting a noticeable value change at a greater distance. I thought maybe the emitter has a problem but I changed it and still got the same results.

Anyway, it's not particularly important if I make this work or not (I 'm just fooling around with random components), I 'm mostly stumped by what I 'm observing which is why I 'm posting here from academic curiosity. If you have any ideas don't hesitate to share.

Hmmm. Is the IR receiver a photoresistor (LDR), a photodiode, or a phototransistor? Give me a part # and I'll poke around.

Just for fun, swap the the resistor from +5 to the input pin to a 10k or 20k ohm resistor and see what happens.

My understanding is that most of these detectors are phototransistors which begin to conduct when (ir) light hits it.

Thus, this isn't really a voltage divider -- it just acts like one. What is happening is that light strikes the base, the transistor begins to conduct. The collector of a transistor closely approximates a current source. The current flows through the resistor and Ohm's law dictates a voltage drop across it, which lowers the voltage at the connection of the R and T.

No, no, it's a photodiode (my best guess). Both emitter and receiver look exactly like LEDs. In fact, poking around the net a bit, they look exactly like these on the right:

The resistance of the receiver goes from crazy high (many M, hard to measure as it jumps around a lot) to about 50k when put head on and touching the emitter. I initially powered the emitter with around 10 mA, then changed it to 100mA daring it die. So far it hasn't, although it's hard to tell with IR (I look at it through a phone camera but it's not an exact science :P). It doesn't get particularly hot (though I only let it run a few seconds at a time to take measurements) and occasionally swap with a new one (I have three) to see if I get any differences. So far it handles the crazy high current quite well, although I don't think it makes such a huge difference to the overall performance as a sensor (if I understand correctly, LED efficiency drops a lot as current goes up so there's not much point pushing them after a point. I have no idea where that point is for IR LEDs but I 'll probably find out).

OK. Try a 47k in place of the 530k to +V and see what you get.

OK, repeating yesterday's measurements, initially with the original 530K I get 970-450 on the ADC and 4.45V - 1.90V on the DMM. With the DMM disconnected I get 1010 - 370 (very roughly, numbers jump a lot).

Replacing the 530K with a 47K I get 4.70V - 4.13V and 1010-910 on the ADC. Disconnecting the DMM has no noticeable effect.

Both these measurements imply that the lowest impedance of the receiver when working as a sensor (detecting IR reflected off a body as opposed to being stuck head on against the emitter) is around the 200K region. For some reason, I was getting much lower values on the first day of testing, along with an increased detection range (when I had the problem when disconnecting the DMM) but not any more. Oh well, still, it 's good enough and useable.

You haven't discussed your test environment.
Even though they're "IR", those devices are highly susceptible to ambient, visible light.
They need to be placed inside an optically-isolated, "light-sealed", box or tube.

I am taking all measurements at night, always at the same spot, under the light of a compact fluorescent bulb (because I have seen that the sunlight does make a measurable difference, although not a very big one). Whatever contribution the bulb makes is a constant and barely noticeable. With the emitter turned off, voltage changes from 4.76V to 4.77V when cupping the receiver with my hands.

I think that you should use digitalRead.
analogRead would be better with a photocell.

You should rig these up in a box, use tape to position them right, so the IRED is "shining" right on the phototransistor. Once you get the on/off (digital) right then maybe you can try spreading them apart for a proportional output.

I 'm sorry Runaway Pancake but I don't understand what you mean. I 'm measuring range to an object so the emitter can't be pointing at the receiver. It has to point outwards and the receiver gets reflected, not direct light.

Anyway, sorry for staying quiet but I had put this on the back burner. I tried some more measurements in a somewhat more methodical manner, see pic below:

The top (red) section shows raw ADC readings, the bottom (green) a 50 point smoothed average. The three "windows", labelled 5cm, 10cm and 15 cm show some very rough estimates of the range of the object I used for reference (a spare breadboard) from the receiver.

Each window has two depressions, one labelled 100mA and one 30mA. These correspond to the current being fed to the transmitter at the time of measurement. I wanted to see how much worse things get if I limit current to under 40mA so I can power the transmitter from a pin (so I can turn it off when not measuring).

The results don't look too bad, when considering roughly where the limits of detection are. Looking at the smoothed signal, it is not inconceivable that the 15 cm @ 30mA could be picked up by a simple static trigger, although it would be a stretch (and changing ambient light would destroy this). At 10cm and closer, things are quite a bit better. I 'll have a look at using more than one emitter to see what effects I can get.

Two points:

  1. IR LEDs and photodiodes are available with various beam widths. If you go to http://uk.farnell.com/jsp/search/browse.jsp?N=2031+202996&Ntk=gensearch&Ntt=ir+emitter&Ntx=mode+matchallpartial you will see that you can select viewing angle from 3 to 200 degrees. The narrower the viewing angle, the higher the radiant intensity in most cases A narrow viewing angle (hence high radiant intensity) will work best for your application, provided you align the transmitter and receiver well. Typical IR emitters intended for remote controls have quite a wide viewing angle so that you don't have to point the remote in exactly the right direction.

  2. If you feed the ADC from a source resistance of more than 10K, then you need to take precautions to prevent the increased source resistance affecting the reading. There are two simple ways of doing this. One is to connect a capacitor of 0.01uF or greater between the analog pin and ground. This has the side effect of slowing down the rate of change of the signal, but this is acceptable in some applications. The other is to introduce a delay in the code for analogRead() between selecting the input channel and starting the conversion. The delay needed is about 1us per additional 10K source resistance.

Thanks for the capacitor tip. I tried it out and here are the results.

Three emitting LEDs were always on, drawing around 30mA each, placed around the receiver. The ADC was sampling the receiver and dumping out the raw signal (red) and the 5 point average (green).

I tried to guesstimate what happens at the far limit of detection, around 15 cm (closer than 10cm it's ridiculously easy). The AIR refers to nothing above the receiver. The OBJECT@~15cm refers to a chunk of veroboard placed roughly 15cm above the receiver. I tried increasing the overall resistance to see how far I could push the ADC (and hopefully, the detection). As it turns outthe ADC was surprisingly cooperative. The 1R / 2R refer to one or two series resistors of about 500k? before the receiver. The No Capacitor / Capacitor refers to having a round ceramic cap (561 J | B1 (I think) 64, whatever that means, I don't have another one I 'm afraid) attached between GND and the analog pin as suggested.

Looking at the top (red) window, it is not very apparent if the cap helps, but perhaps it's not an adequate cap. However, software smoothing does quite a neat job. As for detection, the 2R case yields a slightly bigger difference, but nothing to write home about. We are looking at a very tiny range, 1008-952 (ADC units) at the top window and 1004-961 at the bottom. Still, interesting results, I hadn't played with IR before.

By the way, I have no idea what kind of beam my IR LEDs have, but by a very rough approximation, looking at the size of the visible spot they make against an object when seen through a digital camera I 'd say they have a cone of ~60 degrees (give or take a hundred :~).

Those things are not "resistors" and the "voltage divider" scenario is probably not the best
way to approach the problem.

I 'm sorry michinyon, I don't understand what you mean by: Those things are not "resistors"

Which things? The schematic for the circuit I took the measurements on is this:

As for the voltage divider not being the best way to approach the problem, I 'm all ears, as long as you bear in mind that I have very limited kit at my disposal (resistor kit, handful of ceramic caps and NPN transistors, couple of MOSFETs, DMM, some zeners, IR and normal LEDs, breadboards, veroboard, wires, soldering stuff, Seeeduino Mega 1280, laptop, um, that's about it).

I forgot to mention that this point:

dc42:
2. If you feed the ADC from a source resistance of more than 10K, then you need to take precautions to prevent the increased source resistance affecting the reading. There are two simple ways of doing this. One is to connect a capacitor of 0.01uF or greater between the analog pin and ground. This has the side effect of slowing down the rate of change of the signal, but this is acceptable in some applications. The other is to introduce a delay in the code for analogRead() between selecting the input channel and starting the conversion. The delay needed is about 1us per additional 10K source resistance.

is most relevant if you are using 2 or more analog input pins. If you only ever read from one analog pin, then after the first reading the internal multiplexer is always set to that pin, in which case the effects of using a high source resistance are much reduced.