Voltage divider to seperate 5V into 6 analog values

Hi!

I am using the Sainsmart Display Shield that uses a voltage divider and 5 buttons to transform the 5V voltage into 6 analog values. But I need 6 buttons and now I am too stupid to select the correct resistor values. :frowning:

This is the

My problem is, that I don’t find a formula/rule to the select the resistors in a way, that the voltage at AD0 is spread evenly between 0V and 5V.

I did find a solution with valid E96 values. But then I recognized that +/-1% at 3.01K is not the same as at 332 ohm. So the gaps between the resistor values must be higher the more switches I use.

My current solutions is:

R2 = 2.2k
R3 = 332 ohm
R4 = 665 ohm
R5 = 1k21
R6 = 2k15
R7 = 3k01

This results into the following voltages:

3.850V
3.322V
2.504V
1.560V
0.656V
0.000V

But there must be a better solution with steps of 0.700V. O.O
How can I calculate this kind of voltage dividers?

You could use 1k for all resistors, even for R2.
Write down the values from analogRead() for every button and set the tipping points nicely in between in the sketch.

Do you want to detect pressing of multiple buttons ? I don’t know if that is possible. Perhaps it is.

Are you sure you don’t have 5 or 6 pins ? With a 2x3 matrix you need 5 pins.

If you really want to calculate them, if your really really want that, then start with the evenly spread voltages:
Button 1 : 0/6 * 5V ‘right’
Button 2 : 1/6 * 5V ‘up’
Button 3 : 2/6 * 5V
Button 4 : 3/6 * 5V
Button 5 : 4/6 * 5V
Button 6 : 5/6 * 5V
no button pressed : 6/6 * 5V

Let’s say R2 = 1k
Let’s call the resistor to GND Rtotal, that is the total value of all resistors down the ladder.
If it is battery operated, then R2 of 1k might be low and a higher value for the resistors is better.

Formula for voltage divider : AD0 = VCC * Rtotal / ( Rtotal + 1k )

Or : Rtotal = 1k * ( 1 / (VCC/AD0 - 1 ) )
Use google for the calculation : 1000*1/((6/1)-1 - Google Search)

Button 1 : that results in 0V.
Button 2 must result in 1/6 * 5V, R3 = 1k * (1/(6/1-1)) = 200 ohm
R4 = 1k*(1/(6/2-1)) - R3 = 500 - 200 = 300 ohm
R5 = 1k*(1/(6/3-1)) - R4 - R3 = 1k - 300 - 200 = 500 ohm
R6 = 1k*(1/(6/4-1)) - R5 - R4 - R3 = 2k - 500 - 300 - 200 = 1k
R7 = 1k*(1/(6/5-1)) - R6 - R5 - R4 - R3 = 5k - 2k - 500 - 300 - 200 = 2k
(Rtotal is bold, the value of the resistor in the circuit is in red).

I would use 220, 330, 560, 1k, 2k2 resistors and still measure the result with analogRead() and put the tipping points in between.

This is your project, not mine, but it cringe when people use analog when they really want digital...

This totemple circuit is used because it only uses one pin of the Arduino. You can use any resistor value you like, as long as the resulting voltages are more than a few A/D values apart. This button-read system was used in the eighties in consumer electronics, and quickly abandoned. Very unreliable long term because of oxidising switch contacts. Leo..

Wawa:
This button-read system was used in the eighties in consumer electronics, and quickly abandoned.
Very unreliable long term because of oxidising switch contacts.

They must have been using extremely unreliable switches in the eighties!

Archibald: They must have been using extremely unreliable switches in the eighties!

The front of those cheap all-in-one stereos was full of little tact switches. Volume +/- and power buttons had the most problems. Leo..

@DVDdoug: I am using the UNO and I need the digital pins for my LCD and for some LEDs. So I'd like to save as much pins as possible.

@Peter_n: Thank you very much! I built the circuit with the calculated values and I am getting 0V, 0.51V, 1.00V, 1.68V, 2.45V and 3.32V (measured with my multimeter).

@Wawa: I know that this kind of "digital" input is prone to external influences like heat, the contact resistance... for that reason I need sufficiently large gaps between the individual voltages. Maybe there will be also a problem with chattering switches. I'll see :)

Wawa: The front of those cheap all-in-one stereos was full of little tact switches. Volume +/- and power buttons had the most problems.

I guess they were using membrane switch technology, where the switch contacts were printed conductive ink. Ikarisan should have no problem with ordinary push buttons with metal-to-metal contacts (except perhaps needing to cater for switch bounce in the code).

I used a slightly different arrangement in a recent project for nine inputs. Attached is the schematic. The OP was also asking about how to calculate it, well the formula is simply ohms law, attached also is a spread sheet I used to calculate the required resistors, the real resistors and what threshold values you have to apply in the software to detect each key.

Resiator input.jpg

Resistor values.zip (486 KB)

Wawa: This button-read system was used in the eighties in consumer electronics, and quickly abandoned.

I would love to imagine that happened - but it most certainly did not!

Wawa: Very unreliable long term because of oxidising switch contacts.

Actually, moisture in the lubricant included in the switches is I believe the main problem. The resistance goes down, not up, eventually leading to a "cipher" - a switch that spontaneously actuates, or appears to.

The other symptom is "function migration" where the function of the buttons moves from one to the next!

I have a whole collection of devices that have failed through this process - because I tend to use them beyond their 18-month expected "Moore's Law" lifetime. Many MP3 players (suffer from being carried in a sweaty pocket), computer monitors, a GPS and an Android "tablet". The latter is illustrative - the On/Off switch simply refuses to work, first intermittently and now completely. More to the point (well, before the failure of the On/ Off button), first the Volume Down button would not work, then the Volume Up button became the Volume Down button.

An alternate failure mode of interest, demonstrated by disconnecting the switch chain, is that the ADC input of the main control chip itself develops leakage.

For this reason, I strenuously advise against this form of analog switch multiplexing. Whilst membrane switches are capable only of a few milliamps, I suspect it is important that they are subject to that milliamp or so in the act of switching. Of course if you propose to use properly made full-size switches, it may be a different matter.

Archibald: They must have been using extremely unreliable switches in the eighties!

Most likely far better than those used now, sad to say!

Do you need multiple switches to always read the highest priority? Is it going to be a one of or a large production run? If a one of, you can use two resistors in parallel to fine adjust. This is not practical in a production environment. If your reading them in an analog input, it is better to have the steps nonlinear. As the voltage gets larger, the it becomes more of a percentage of range. As the voltage is smaller, the resolution of the A/D becomes a bigger factor. So, not having nice equal steps may not be as big an issue. You are going the set thresholds in the code anyway. In any case, a spread sheet might be useful. Dwight