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?

Your rotary switch is a 4-Pole -6 POSITION switch.

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()
{
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.