How to read from more than six analog sensors?

Hi all,

I am working on a project where I would like to read the values from many resistance-changing sensors. The more the better, but preferably at least eight.

It's pretty clear how to read the values of up to six resistances by using a voltage splitting circuit (like my diagram below) with the probe wire connected to each of the six analog input pins (pins 0-5).

Is there any way to read more than six values?

One possibility that I was thinking of was that instead of connecting all the resistors up to the +5V pin, I could instead connect them to the digital-out pins. Then I could turn one pin on, read the sensor reading, then turn the next pin on and read the sensors reading, and so on. Does that make sense? It seems like it's a lot more complicated, though. Is there a simpler option?

Any thoughts greatly appreciated, thanks!

Sam

Regular ol' voltage splitting circuit connected to four analog pins:

Does that make sense?

No because you would have unpowered sensors affecting the reading from your powered ones.

Is there any way to read more than six values?

yes use multiplexing on the input.
See:-http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html for an example of how to read up to 16 analogue inputs.

No because you would have unpowered sensors affecting the reading from your powered ones.

Ah, yes. I actually diagrammed out the circuit I was describing (image here), and saw that I wasn't getting the right readings because some of the current was traveling back up through the sensor resistors, just like you said.

So then I was thinking I could do something complicated with voltage-controlled switches, but now I see that that's basically what the multiplexer is, right?

So it looks like a 4051 mux is pretty much the way to go -- is that the simplest, cheapest one? Trouble is, I'm having trouble working out where to buy one. Sparkfun doesn't list anything for the search "4051," and when I search on Google I mostly get a bunch of datasheets. Any leads?

Can you put a number on "many"? Does it mean 8? Does it mean 73? Does it mean 3847?

Like I said, "the more the better, but preferably at least eight." :slight_smile: 8-20 would be ideal. It looks like I could get that many with three 4051 muxs if I needed to, right?

How quickly do you need to read these values?

It doesn't need to be fast. Reading all the sensors within 500 ms would be fine.

What kind of sensors are these?

Resistance-changing sensors. LDRs, pressure sensors, thermistors.

I don't really understand your diagram? It looks like a bunch of fixed resistors in which case you wouldn't need to read anything.

Sorry that it wasn't clear. I often use a circuit simulator to diagram out my circuits. I thought it would be clear that a set of parallel voltage-splitting circuits with the same resistor always on the right and a bunch of different resistors on the left would make it clear that the resistors on the left were the ones I was measuring, but I really ought to have labeled it. Sorry!

No because you would have unpowered sensors affecting the reading from your powered ones.

Actually, wait, couldn't I just eliminate their effect by using diodes?

Here's an example circuit:

On the far left I have digital output pins, which I can set to HIGH or LOW one after another. Then I have all my sensors. They are all connected to diodes, so the current can't travel back through them. Then I have my known resistance, and my voltage-splitting wire between them connected to one analog input pin.

Would that work? I'd have to take into account the voltage drop caused by the diodes, but it seem to me that I could measure each sensor independently fairly easily that way.

Of course, that requires using up a bunch of digital pins instead, so it might not be better than a mux in most situations. But in my project I don't need the digital pins. So at least for the short-term, if this works I'd go for it, since it seems simpler at first blush.

So would that work? I'm probably overlooking something obvious, of course...

What is sometimes done is switching the Ardiuino pins between HIGH OUTPUT and (LOW) INPUT. The latter setting will be a sort of unconnect, and it will remove most of the sensors' impact on the rest of the circuit.

In case the resistance is high however (>10k), those unconnected resistors act as small antennas for any kind of noise, which will reduce the accuracy of your readings.

Speaking of noise, you should add a cap in parallel to your 100R resistor; best much higher than 100nF, but not an electrolyte...

What is sometimes done is switching the Ardiuino pins between HIGH OUTPUT and (LOW) INPUT. The latter setting will be a sort of unconnect, and it will remove most of the sensors' impact on the rest of the circuit.

So is that basically the same as adding the diodes as I did in my last diagram above?

If I understand you, when I switch a pin to LOW INPUT then, instead of just being at zero volts, it's actually acting more like it's been disconnected, is that right?

I'm guessing, if I've understood right, that the diode solution might be safer, because you don't want to accidentally apply a high voltage to an input pin, right? So if I didn't have diodes and I had a very low resistance on the sensor attached to +5V, and a very low resistance on the sensor connected to a LOW INPUT pin, might I damage the pin?

SparkFun sells the 4067 which is a 16-input version...

Thanks! I haven't yet worked out if it makes more sense to go the multiplex route or the route I posted in my diagram above. To ask again to be absolutely sure: does the circuit in my second diagram make logical sense?

Basically your design makes sense. You however have introduced the voltage drop of around 0.6 at the diodes. This also is a little bit dependant on the current...
However this can be handled in your non-linear calibration.

When an Arduino pin is set to INPUT this is similar to a TRI-STATE in standard chips: It is a (limited) high impedance state of many megohms.
When I said (LOW) INPUT I was referring to the setting of NO PULL-UPs. This might have been a little bit cryptic, sorry.

This means that a Software Multiplex would work as this:
write(currentPin, LOW)
mode(currentPin, INPUT)
mode(newPin, OUTPUT)
write(newPin, HIGH)

You can get rid of these mode changes if you connect the 100R to +5V and switch the sensors to ground.

You can get rid of these mode changes if you connect the 100R to +5V and switch the sensors to ground.

Hmmm, I'm struggling to understand this, because it sounds like what you're suggesting is the simplest solution yet, but I don't quite get it.

It sounds like what you're saying is that if I make the right side +5V, and then make one digital pin LOW to read from it and keep the others HIGH, then I could read from just one sensor at a time.

The diagram below is how I'm interpreting what you're saying:

Then I would say

write(pin1, LOW)
read(analogPin) // value of first sensor
write(pin1, HIGH)
write(pin2, LOW)
read(analogPin) // value of second sensor
etc..

But that doesn't quite make sense to me, because the other HIGH pins are feeding into my ground pin as well, changing the reading.

Unless somehow the pins are acting in the way you were saying before, that they were somehow acting like a disconnect?

Sorry if I'm being foolish!

Did you miss this critical line?

I didn't miss that, but neither did I miss when he said

You can get rid of these mode changes if you connect the 100R to +5V and switch the sensors to ground.

That was the part that I was trying to understand (which I why I quoted it).

You can get rid of these mode changes if you connect the 100R to +5V and switch the sensors to ground.

Problem with that is that you then connect the sensors in parallel across the 100R pull up which is going to mean that the reading of one sensor will be affected by the reading of all the others.
Best stick with the mode change which looks a promising although unconventional way of going about things.

cap in parallel to your 100R resistor; best much higher than 100nF, but not an electrolyte

Well I would say use a 100nF (0.1uF) capacitor but not much higher. Although you cut down on noise you make the response more sluggish.

I was sloppy. I said "mode changes" but I meant the sequence of the four calls...

They can be simplified to
digitalMode(currentPin, INPUT)
digitalMode(currentPin, OUTPUT)
without any worse impact than the first solution. However we have a feeling it is more safe to connect things to ground than to some voltage. Which is most likely a quite useful prejudice...

As he said 500ms cycle time the cap value is not really relevant; 100nF is good comprimes as it has to stabilize between power switch and analog reading. 100R*100n = 10 us

Best stick with the mode change which looks a promising although unconventional way of going about things.

Ok, I think I'm going to try first with the mode-changing and no diodes. If that works, I'll report my results. If it doesn't I'll try using diodes, and see if the impedance and voltage drop cause problems. If they do, then I'll finally go for the multiplex.

I'm guessing I should spring for a mux eventually, though. They seem like handy chips!

Thanks so much for all your replies!