Is this calculation correct ?

Initially, I will connect three resistors to four rotary encoder switch in serial way. So it requires just one pin to programming. But how do I give the correct watt and voltage to the rotary encoder? The pin can receive up to 40 milliamper.

What wrong have I done ?

… pardon?

What calculation?

I see that I missed some informations. The pin on arduino receives up to 40 mA. This Arduino MEGA2560 operates at 5 Volt. I shall use 1/4 Watt resistor or more if necessary. In final edition, it shall has 39 resistors in serial connection. How much Ohm in each resistor does it need ?

Qwseyvnd: I see that I missed some informations. The pin on arduino receives up to 40 mA. This Arduino MEGA2560 operates at 5 Volt. I shall use 1/4 Watt resistor or more if necessary. In final edition, it shall has 39 resistors in serial connection. How much Ohm in each resistor does it need ?

Still confusing. An arduino digital or analog pin is in in input mode it 'receives' (or requires, or demands, or draws) almost no current, they are very high impedance inputs.

When an arduino digital pin is in output pin mode one can draw a maximum current from the pin at 40ma, and if more current is attempted to be drawn from the output pin, pin damage can result.

Hmm... I do not want to use 39 pins. What to do ?

If I understand correctly, you want to discriminate up to 39 values in a chain resistor. Can you present a diagram of how you intend to connect these via a switch system to the single arduino input. Also where is the calculation that you want verified. Might I suggest you google R/2R resistor chain.

That's the R/2R resistor chain, but how do the Vout receive in arduino pin ?

You will some combination of resistor/switches that create an equivalent circuit of: 5V - resistor - arduino input - resistor - Gnd.

I would suggest a part like this instead: http://www.digikey.com/product-detail/en/AD5228BUJZ10-RL7/AD5228BUJZ10RL7CT-ND/751238 You click thru the values, they will be repeatable, and the output forms a simple voltage divider that you read with analog input.

This item you suggested me… I do not understand how to have this item.
Now I have attached a screen dump.
Here’s it how I thinking to attach pins.

The part I suggested, see the datasheet. http://www.analog.com/static/imported-files/data_sheets/AD5228.pdf Connect two buttons, Connect VDD TO +5 Connect A to +5 Connect W to Analog pin A0 Connect B to Arduino GND Connect PRE & GND to Arduino Gnd

Then int value = analogRead (A0); // returns 1/32 of 1023, 2/32 of 1023, 3/32 of 1023, etc. Approx 32,64,96,128, etc.

But what with 19 other rotary encoder switch? It seems that you thinking just ONE piece of rotary encoder.

How many inputs to the Mega do you want? There are 16 analog inputs - you can have 16 of those chips with 2 buttons each. After that, you need to multiplex the inputs. You can use an analog multiplexer, or analog switch, such as 74HC4051 http://www.digikey.com/product-detail/en/CD74HC4051E/296-12810-5-ND/475938 Or you can use an ADC converter with 8 inputs, such as MCP3208 http://www.digikey.com/product-detail/en/MCP3208-CI%2FP/MCP3208-CI%2FP-ND/305928

It seems that you do not understood the picture that I have attached. If you see, I will just use one rotary encoder each time when I will turn. Here's the explanation: This is a part of navigation panel in a old airplane that I will make a copy home cockpit. The airplane is made in between 1963 and 1994, and a few after 1994.

They are NOT buttons but rotary encoder switch!!!

It seems it is simpler to have this setup as I made prototype in Fritzing. Do you and you have better solution than to have additional chip ?

I don't think we understand what YOU mean by a "rotary encoder switch". Most rotary encoder switches have quadrature A and B outputs. Post a link to the data sheet or to the product page describing the exact switch you plan to use.

https://www.sparkfun.com/products/9117 I have roughly same as this. The pins is exact same.

Why CAN'T I use the serial connector from rotary encoder #1 to #20 ? It is simpler and easier to understanding. Is it possible with external power supply ? Or whatever ?

Excuse me, this Google search of "rotary switch" and resistors shows perfect result of what I mean: https://www.google.no/search?q=rotary+switch+resistors&source=lnms&tbm=isch&sa=X&ei=W81uU-HUKsnjPJbQgYgE&ved=0CAYQ_AUoAQ&biw=1119&bih=551#imgdii=_ http://smtp.letsmakerobots.com/content/reading-rotary-switch?page=1