Need More Analog Inputs


I need to read several photoresistors at once and I am now out of analog inputs on the Arduino Uno....I've read alot about the 74hc4051 as well as the MP3208 and read alot on the multiplexing etc. however I am unsure which to use as I need to poll each sensor at once. Any solutions would be helpful thanks!

The Arduinos that I know of only have one ADC so the 6 or n channels are time multiplexed into that one ADC. To do true simultaneous sampling you need a n channel sample and hold that feeds an ADC (beware droop) or n ADCs that can be triggered in sync and read in sequence.

I guess my question is this: how should I go about adding more analog inputs?

A 4051 feeding each analog input will give you 48 channels. You need 3 digital outputs for channel select. You can only read one of the 48 channels at a time though, so the data will be time skewed.

The choice between the 4052 and MCP3208 would require a close look at the data sheets to see which has the best specs for your application.

Here's a solution to your problem. You have a max of 432 channels using 27 chips on unique I2C addresses. A global address for all chips allows you to fire them synchronously.

PilotinControl, tell us how many photoresistors you want to read. Tell us which photoresistors they are (you can give a link to them). Tell us what you mean by "at once", how fast should they all be read (during a microsecond or during a minute) ? Tell us how many times per second you need the data. Tell us what your project is about.

If you have LDR resistors, they are slow anyway, and it would be okay to read them one by one during a millisecond.
If you would need a maximum of 12 analog inputs, then you can use a Arduino Leonardo.
If your project is to measure some kind of laser-doppler-interference pattern, then ... then I don't know.
If you ... and so on.

They are LDRs....which is fine they are working quite well for my application....this is model railroad related I am tracking the location of the model train....and my "blocks" are quite long ( 4 per block ) so several per block are needed....and I have used all the analog inputs on the Uno. Now if there is a chip I can use that can branch off each analog input on the UNO then I will have enough for my demo setup.

How many analog inputs do you need ?

An LDR can have a rise time and fall time of about 50ms and 20ms. That is slow. That means almost every solution is possible. My personal preference would be to keep A4 and A5 for the I2C bus, use the other 4 analog inputs each with their own mux, and if more more is needed, start putting muxes in front of those 4 muxes.

Would this be a suitable solution? Low cost Digital and Analog IO Expander Shield | Numato Lab or should I stick to something like the 4051 or the 3208? The simple solution is what I am after....plug-n-play.

H o w m a n y a n a l o g i n p u t s d o y o u n e e d ?

The CD4052 will allow you to branch two analogue pins into eight inputs. The expander will work as will the MCP3008. However, all of the solutions are going to add complexity. At this point, I would opt for the CD4052(s) and fan out as many of the Arduino analogue pin pairs through the MUX chips as you need. Wire the address pins in parallel for all MUX chips. Read each analogue pin that's been fanned out, advance all MUX chips to the next address then read the analogue pins again. Continue on four times for all MUX channels. Using A0 - A3 and two MUX chips, you can sample 16 analogue signals.

There are so many more possibilities. For example using a single analog input and digital pins to power the LDRs one by one. It might require a little extra delay. About 16 LDRs could be connected to a single Arduino Uno without extra hardware, and still use the serial monitor.

The digital inputs on the UNO I cannot use the analogRead or analogWrite I would need to use the digitalWrite and digitalRead correct? Didn't know if the LDRs were able to be used as digital? Thought it was only analog?

I was talking about a digital pin as output to power a LDR. That would require a single analog input (and a single resistor). The LDRs can be powered one by one. The digital pin for the unpowered LDRs would default be set to INPUT, and that will have no influence on the circuit.

I don't know the amount of (analog) LDRs that you want to read, therefor all my thoughts are useless. It makes a big difference if you need 8 or 8000 analog inputs. I really tried, but I have to give up on this topic.

I need about 48+ analog inputs....I am using the 5v+ side of the arduino and using the analog side with a 10k resistor and using the analog inputs to read the values

You're going to have to fan out something to select that many objects. You can use six digital lines through data decoder chips to power 64 sensors as Loepel suggested or the same six lines to steer MUXers to the appropriate analogue input. You could quickly run out of digital pins if your project expands in the future so you might as well switch to a Mega2560. With more analogue inputs, your MUXer needs will be reduced. With eight analogue pins, eight CD4051 chips, and three digital pins, you have 64 inputs. I've had many projects that jumped from an Uno to a Mega2560, and glad they did.

yes I’ve decided thats what I am going to have to do…I did think about connecting 2 UNOs as a master slave setup as described in Simon Monks book

I just received a bunch of 74hc4051 chips and I found this tutorial I will let you know how it goes

Hi PilotinControl,
I realise this topic is quite an old one, but thought I’d give it a chance shot.
I’m in the same situation where I’m wanting to use some (15 actually) LDR’s to detect the location of wagons on a small layout.
Fortunately, I’m planning on using an Arduino Mega, which has 16 analogue channels so don’t need to do any multiplexing.
Hence, what I am asking is if you would be happy to point me the right direction for the Arduino code sketch .... I’m in the ‘learning’ phase of Arduino, and have done (and understand SOME) of the example sketches, so am hopefully able to de-cypher and modify code .... I’m just not at the point of being able to write from scratch yet.
If you would help out a fellow model railwayist and let me have a copy of the section of your Arduino code that deals with the LDR’s, I would be very grateful, but will completely understand if you would rather not disclose your hard work, but maybe a description guider on what to do to make use of them.
Best regards.

In case that pilotinControl does not respond, if you do a Google search for "arduino ldr" you will get over 1 million hits. If you still have questions we can help, but it would be best, I think, if you start your own thread.