analogRead problem

Hello everyone,

I'm trying to read in which position is a rotary switch via analogRead()

This is what I do

Works just fine when taking +V directly from the board, the problem is when I take voltage from a nearby circuit, then instead to get a fixed value the reading turns in something like this:

1023
800
250
0
1023
800
250
...
and so on

I don't have a schematic :S but that circuit has some IC that I use for buttons demultiplexing, at the same time that IC has a decoupling capacitor, which I guess may be the problem (I don't fully understand how it works, I was just advised to add it to the circuit).
Is this really the problem? If so, how can I isolated it in a way it does not affect the rest of the circuit?

Thanks in advance.

Your rotary switch is a 4-Pole -6 POSITION switch.
https://www.google.com/search?q=4+pole+6+position+rotary+switch&rlz=1C1GPCK_enUS504US504&espv=2&biw=1113&bih=690&tbm=isch&imgil=35gTHpt4wgHVM%253A%253BVe2x12LG9CJz3M%253Bhttp%25253A%25252F%25252Fwww.doctronics.co.uk%25252Fgt_4.htm&source=iu&pf=m&fir=35gTHpt4wgHVM%253A%252CVe2x12LG9CJz3M%252C&usg=__RGX2gOZJSXS38PsI8bbhkMqzzTc%3D&ved=0CEIQyjc&ei=kHEwVMCuEdGzogTG9oH4CQ#facrc=&imgdii=T3vxmTu1djzyaM%3A%3Bmi5s-WwEmMMDEM%3BT3vxmTu1djzyaM%3A&imgrc=T3vxmTu1djzyaM%253A%3Bakks8r84UfqpeM%3Bhttp%253A%252F%252Fwww.neighborhost.com%252Ftemp%252Frotary_layout01.png%3Bhttp%253A%252F%252Fwww.seymourduncan.com%252Fforum%252Fshowthread.php%253F129511-Advice-Needed-Re-Wiring-5-Pos-Switch-To-Pearly-Gates-In-Telecaster%3B433%3B336

It looks like your voltage divider is mixing two different sets of contacts.

You should ohm it out with a meter and draw a schematic and take a photo of it and post it.

Hey, thanks but the image was just an example about how I wired it.

It's a 12 pos switch (I'm using only few of them) and works properly when taking voltage directly from the arduino board.

Is the ground of the nearby circuit connected to Arduino ground?

groundfungus:
Is the ground of the nearby circuit connected to Arduino ground?

Yes, it is.

but the image was just an example about how I wired it.

So the answer was just an example of the solution if the question you asked was actually related to what your real problem was.

If you are going to post anything then post what what you are asking about.

Is this really the problem?

Who knows because:-

I don't have a schematic

so get one and show us if you want real help.

Hey guys, this is getting odd, at first I thought it was something in the circuit but then realized it isn't working even with just the rotary switch without wiring anything else.

int pin = 0
int val = 0;

void setup()
{
  Serial.begin(9600);
  pinMode (pin, INPUT); 
 
}

void loop()
{
   val = analogRead(pin);
   Serial.println(val);
   delay(1000);
}

I get totally random readings from 0 to 1023 without even moving the switch
I made this before and always worked I don't know what's wrong now.

Can you please draw a schematic with resistors in straight rows ?
You can represent your rotary switch based on a continuity check from the common in the center to the contacts on the outside.
If it has one common in the center, label it COM . If there are two commons (one for each set of 6 contacts) , label them COM1 & COM2.

You haven't included the values of the resistors (if that is what those squiqly marks are).
Please include values when you post schematics.
Try again..

Hi, it has only one common as in the image.
Resistors are all 1K Ohm.

Have you calculated the voltages you should see at those contacts and then verified them with a DMM ?

raschemmel:
Have you calculated the voltages you should see at those contacts and then verified them with a DMM ?

The voltages reading matches with what arduino shows, in those pins where I get random values from 0-1023 the voltage varies from 0 to 5v.
But I also notices some pins are at fixed 0 and others fixed 1023 (5 and 0 v in the multimeter).
No idea what is going on.

You didn't answer my question. Did you , or did you not, calculate the values and verify each and every one of them with a DMM ?

raschemmel:
You didn't answer my question. Did you , or did you not, calculate the values and verify each and every one of them with a DMM ?

No, i didn't

Why not ? Are you too busy ? (or don't have a meter ?)

raschemmel:
Why not ? Are you too busy ? (or don't have a meter ?)

It's just I don't see how that would be relevant considering I'm getting any possible value from 0 to 5V

BTW, i'm trying the same with a 4pos switch and work just fine.
I don't think the 12pos can be faulty because tried 2 of them with the same result.
The only thing I can think of is I'm wiring them wrong, but how?

Why bother posting here if you think you know better than us how to troubleshoot your problem.
If you don't know what's wrong , maybe it's because you don't have any data.
If you are going to post here for help, try being more cooperative. Calculate the values so you know what you should have on each pin. Then get a meter and measure each pin. When you locate the pins with the bogus values , then you'll have something to compare the values against. I'm afraid to ask what your circuit looks like. Can you post a photo ?

raschemmel:
Why bother posting here if you think you know better than us how to troubleshoot your problem.

I think you are being rude without reason, I never said or suggested such thing, if there is something I sure about this topic is that I know almost nothing.
Anyway, we better let this thread die.

I'm not being rude, but if I were it would be with good reason. Your response should have been "Ok, I'll do that and get back to you".
But since your pride is more important that solving your problem then go ahead and give up.
You asked for help. I gave you my advice. You responded by saying you didn't think it was necessary.
I've been doing this longer than you've been alive but if you have a better way to find the problem , knock yourself out.

Let it go mate, I did it already.