more analog inputs

I have read about a multi-plexer or something and it says that i can read many analog inputs but only one at a time, is there any way of say turning two pots at the same time and reading them both through some mashed up bit of code? if not is there a way i can ask the arduino people to put 20 or 30 analog inputs on a board? 6 isn't enough, or do we start to encounter like whether the board will be able to handle it?
cheers,
rich

As far as I am aware (someone with more experience here can jump in), you normally read one input right after the other and the time delay between each is less than a millisecond...so to a human it's just like reading both at the same time.

What difference does nothing and 50us make to your project? Taking thee 50us as a guess there btw.

so for instance if i turned two pots at the same time the arduino would know from the time delay where it's coming from? or am i not getting what you just said?

All microprocessors can only do one thing at a time, but they can do it very fast.

I made a setup wit 16 (slide) pots read by two 4051 multiplexor IC's

I was able to read all 16 pots and format the read values and send them over serial to a PC program in 10 ms. That translates to reading 16 pots 100 times a second. Enough ? :slight_smile:

Here's a link to a zipfile on my website with schematics, PCB layout and Arduino code.

http://mikmo.dk/misc/arduinomux.zip

thank you so much but still i am a little confused - so i can using a multiplexer turn two pots at the same time and i can separate the data to to two different identifiers say a and b?

so for instance if i turned two pots at the same time the arduino would know from the time delay where it's coming from? or am i not getting what you just said?

It always knows that you have Pot 0 connected to Analog Pin 0 and Pot 1 connected to Analog Pin 1.

In your program, if you loop over and over, reading the pins...it will read both pots a ridiculous number of times per second...about 800 times per second (as per MikMo's post).

So realistically, yep, you're reading both simultaneously. If you consider thousands of times per second simultaneous! I know I do...

[edit]Deleted my post after this one, I was confused. Or foncused as I like to say...[/edit]

You would read the values from the 2 (or more) pots into separate variables. Check the code in the zip file i posted above.

I read the 16 values into an array of 16 integers´.

"so i can using a multiplexer turn two pots at the same time"

sorry about the lack of articulation in that statement, it probably meant me being the physical turner and the multiplexer just sending the data to the arduino

so for instance it would be like lighting up and down an array of LEDs like in the knight rider example in the playground, the values would be stored individually based on the way the delay? is sent to each pin for it to be read? I am really sorry for my lack of comprehension trying to see if this idea would be contemplating in future projects. thanks for the help so far

Here's some pseudocode:

loop

read the value of pot 1 into variable A
read the value of pot 2 into variable B
read the value of pot 3 into variable C

Do whatever you want to do with the values in the variables

go back to the top and do it all again

although you are not reading the values from the pots at the same time, it is going so fast that you won't notice.

Here's a cheap and nasty technique that addresses 8 LDRs over 3 digital outs and an analogue in. You should be able to adapt it:

And here's some poor quality code to run it:

void select_sensor(int sensor) {
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  digitalWrite(4,LOW);
  if (sensor & 1) {
    digitalWrite(2,HIGH);
  } 
  if (sensor & 2) {
    digitalWrite(3,HIGH);
  } 
  if (sensor & 4) {
    digitalWrite(4,HIGH);
  } 
}

You'll need to set pins 2, 3 and 4 to outputs in setup().

Pass a sensor number (0-7) to select_sensor() and perform an analogue read on analogue pin 0 to get a value back from the selected sensor.

Tomo,
Have you actually tried this circuit? As I see it you have 8 1K resistors all in parallel. That will give you a very low resistance and I would be surprised if it worked at all.
You could replace all the 1Ks with a single resistor.

However the question arises as to what happens to the LDRs that are not selected. These have a logic zero on them so you have all the LDRs (but one) connected in parallel to ground giving you a variable low pull down. This means that the light indecent on an LDR that is not selected will affect the reading of one that is.

I can't see this working at all.

Yes, one resistor would stop the pull down problem, but then again I did say it was cheap and nasty. :slight_smile: