Hello,
i use ASURO with µC from Arduino UNO R3. It works fine. Now i want use six switches on one pin. Is there possible?
I've calculated it, this is the result:
K1 = 0,00998004 Voltage
K2 = 0,019920319 Voltage
K3 = 0,040666534 Voltage
K4 = 0,078740157 Voltage
K5 = 0,159728945 Voltage
K6 = 0,31835206 Voltage
Correct?

Why so small voltages?
Yes it is possible but you will be better off using the full 5V spread and smaller resistor values.
Note you can not detect two or more switches held down at the same time.
I used a similar method a short time ago for nine switches.
robtillaart:
R24 is not needed.
Especially when it does not appere to be connected to anything.
An alternative to a resistor tree, might be to use a MCP23008 or similar i2c expander. If you need more switches, there is a 16 input/out MCP23017 and other i2c expanders. Plus with most i2c devices, you can put multiple devices on the bus, assuming each device has a unique address. I believe you can attach 8 MCP23017's to support up to 128 switches. There is also the PCA9555 that supports 32-bit pins per chip (but it only has 2 address select pins, so you can only have 4 chips, or 128 total switches).
If you don't have any I2C right now, it would take the 2 I2C pins for SDA/SCL (A4/A5 on in UNO, 20/21 and 70/71 on Due).
This is what I used. The resistors were designed to give an even spread of readings:-
int readPlayButtons(){
int playThreshold[] = {59, 155, 233, 333, 470, 576, 671, 775, 878, 1024 }; // threshold values
int i = 0, voltage=0, voltage2=99, button=99; // value of 99 when nothing pressed
while(voltage != voltage2){ // repeat until they give the same result
voltage2 = analogRead(0); // read the playing buttons
voltage = analogRead(0);
}
while(voltage > playThreshold[i]) { // see what it is
button = i;
i++;
}
return button;
}
The resistor values and wiring are shown in the attached document.
switches.pdf (17.7 KB)