# Using multiple analog pins. Setup works but not as it should.

Hello,
I am running into a small problem. I am using multiple rotary switches with 12 positions each.

Here is a datasheet http://www.tme.eu/en/Document/59c296b3263e0f07b2a427d8049c0386/sr261112p.pdf
Mine are virtually identical.

I need to get a certain value between 0 and 1023 for each of the 12 positions and I am using 12 resistors, each with a different value. The wiring to the Arduino is the same as the wiring in the photocell example (http://bildr.org/blog/wp-content/uploads/2012/11/arduino-LDR-photoresistor1.png).

I have wired it the following way:

• 5V to A.
• One resistor on each pin, all connected together.
• From the big resistor connection one wire to A0 and another to a 1K resistor and to ground.
Basically I replaced the photoresistor with a normal resistor that is selected with the rotary switch. It works exactly as it should and I get the desired values between 0 and 1023.

My problem is when I try to connect more than one rotary switch with resistors. All the switches and resistors are the same (I am replicating the first switch and resistors)

I connect them the following way:

• All wires that go to 5V are connected together to a single wire that goes to 5V.
• Analog pins are connected individually to A0, A1, A2 and so on.
• One 1K resistor and wire for each switch connected together to a single wire that goes to ground

The setup still works but this messes up all the values. It makes them more compact. The ones at the 0 end increase and the ones at the 1023 end decrease. Obviously, I am not connecting them together as I should.

Any suggestions will be greatly appreciated.

each one k should connect only to its switch and to gnd, not to other switches except at the gnd point.

Sounds like the resistance of your wiring isn't negligible enough. What range of values are
the resistors?

Hello,

Each switch has it's own 1K resistor and ground wire. Does it make a difference if I solder the ends to a single wire and that wire to ground or should I solder each wire to ground one next to each other a few millimeters apart? It sounds like it's the same thing to me.

I am using resistors from 10 Ohm to 10K. At 10K the value for a single switch is about 90. When using multiple switches it jumps to about 300. The 10 Ohm is about 1010 for the single switch and drops to about 920 for multiple switches.

How quickly are you switching from reading to reading? Could be that not enough settling time is elapsing between channels. Try adjusting your code to read each channel twice and only saving the 2nd reading.

Hi, I notice you said you connected 5V to pin A on the rotary switch…
If you are making a potential divider then A would go to the A0 of the arduino and the resistor chain across the 5V and gnd.
This may be why you have crosstalk due to loading on the 5V supply.
See the diagram I have posted and see how it compares with yours, if you can please draw the circuit and post it, even if its a picture of a hand drawn circuit.

Tom…

How quickly are you switching from reading to reading? Could be that not enough settling time is elapsing between channels. Try adjusting your code to read each channel twice and only saving the 2nd reading.

Since each input has a 1k to ground the source resistance is well below 10k so
this really should not be an issue.

If each switch has its own 5V and ground wires brought back right to the Arduino
this will minimize crosstalk due to IR voltages (and contact resistance in the
header sockets). It is vital that however the ground and 5V is wired to the switches
this is not shared with anything consuming or providing significant power - otherwise
the IR losses will be very obvious. This is called "star grounding" (and here needs to
apply to both ground and 5V)

Each LSB of the analog readings represents only 5mV, so it doesn't take much to