Go Down

### Topic: on/off switches in resistor voltage divider (Read 12535 times)previous topic - next topic

#### Qwseyvnd

##### Jun 16, 2014, 10:00 pm
I thinking this:
Switch #1 1
Switch #2 2
Switch #3 4
Switch #4 8
Switch #5 13
Switch #6 29
So, the Arduino card can detect which switches are activated, for example #1 to #5 give me 28 as a value which the Arduino card can read.
#1 to #6 is 57 as the value if I activated all together. If #2 and #5 and #6 are activated, I get 44 as one value to the Arduino card.

I am doing this to save pins. If I am using each pins; that would be need maybe 400 pins, so I am using maybe 30 pins.

So, which resistors do I need ?

#### steinie44

#1
##### Jun 16, 2014, 10:27 pm
Look it up in Learning. Here is one example:
http://forum.arduino.cc/index.php/topic,20125.0.html

#### knut_ny

#2
##### Jun 16, 2014, 10:29 pmLast Edit: Jun 16, 2014, 10:31 pm by knut_ny Reason: 1
This example can detect 1 of 12 (only one switch at a time) on an analog input

Code: [Select]
`/*******************************************************Defines 12 switch resistornet connected til A012 resistors,   series : 2k2, 180, 220,270,330,470,560,820,1k2,1k8,3k3 og 8k22k2 connects to 5V, other end til A0 and 180R. After A0 downwords connects a switch to gndKey 0 will  give analog reading 0Key => 1 ca 77, Key 2: 157, Key 3: 239, Key 4:320, Ket 5: 410, // knapp (norwegian) = keyKnapp 6: 491, Knapp 7: 577, Knapp 8: 663, Knapp 9: 743, Knapp 10: 825 og Knapp 11: 908If no key is pressed, you will read near  1023Key find = integer of ((analog reading+ 41) /  82.5)********************************************************/#define analogPin 0void setup(){ Serial.begin(9600);        // start seriell kommunikasjon Serial.println("Trykk en knapp");} void loop(){  while (knapp()<0); // vent til det er trykket på en knapp  Serial.println(knapp()); // skriv knappenummer på skjermen  delay(500); // ent 1/2 sek før du leser om igjen}int knapp() // returnerer knappenummer 0..11 eller -1 dersom ingen knapp er trykket ned{  int lestAnalogVerdi = analogRead(analogPin);      // les verdi fra sensoren  int nummer=int((41.0+lestAnalogVerdi)/82.5);  if (nummer<12) return(nummer);  return(-1);}`
Ny

#### Qwseyvnd

#3
##### Jun 16, 2014, 10:31 pm

This example can detect 1 of 12 (only one switch at a time) an an analog input

Code: [Select]
`/*******************************************************Defines 12 switch resistornet connected til A012 resistors,   series : 2k2, 180, 220,270,330,470,560,820,1k2,1k8,3k3 og 8k22k2 connects to 5V, other end til A0 and 180R. After A0 downwords connects a switch to gndKey 0 will  give analog reading 0Key => 1 ca 77, Key 2: 157, Key 3: 239, Key 4:320, Ket 5: 410, // knapp (norwegian) = keyKnapp 6: 491, Knapp 7: 577, Knapp 8: 663, Knapp 9: 743, Knapp 10: 825 og Knapp 11: 908If no key is pressed, you will read near  1023Key find = integer of ((analog reading+ 41) /  82.5)********************************************************/#define analogPin 0void setup(){ Serial.begin(9600);        // start seriell kommunikasjon Serial.println("Trykk en knapp");} void loop(){  while (knapp()<0); // vent til det er trykket på en knapp  Serial.println(knapp()); // skriv knappenummer på skjermen  delay(500); // ent 1/2 sek før du leser om igjen}int knapp() // returnerer knappenummer 0..11 eller -1 dersom ingen knapp er trykket ned{  int lestAnalogVerdi = analogRead(analogPin);      // les verdi fra sensoren  int nummer=int((41.0+lestAnalogVerdi)/82.5);  if (nummer<12) return(nummer);  return(-1);}`

I see that
Jeg ser det.
Now I am reading the example who Steinie44 posted.

#### Qwseyvnd

#4
##### Jun 16, 2014, 10:58 pmLast Edit: Jun 16, 2014, 11:14 pm by Qwseyvnd Reason: 1
I have been read the topic that Steinie44 posted which is a good proposal; but, it requires more than one pin and a lot of time to get it working.

To Knut: That's I am not asking for and I have had same issue as you might thinking. Then I asked in earlier topic for help and I got the help to draw a correct schematic.
So, now I am asking for which resistors do I need. My idea is finished but I don't know which resistors I need.

#### steinie44

#5
##### Jun 16, 2014, 11:29 pm
Depends on how you do it. Some require each one to be doubled, and some you can use the same value for all of them. I like all the same value.

#### Qwseyvnd

#6
##### Jun 16, 2014, 11:58 pm
I need double values.

#### Grumpy_Mike

#7
##### Jun 17, 2014, 12:04 am
Post a schematic of how you propose to use the resistors, the. We can help with the values.
Basically you can do this technique with all the same resistors or different ones.
Do you need to detect multiple presses?

#### Qwseyvnd

#8
##### Jun 17, 2014, 12:08 am

Post a schematic of how you propose to use the resistors, the. We can help with the values.
Basically you can do this technique with all the same resistors or different ones.
Do you need to detect multiple presses?

How do I this technicqye with all the same resistors ?
Yes, I need to detect multiple presses.

#### Qwseyvnd

#9
##### Jun 17, 2014, 12:21 am
Here's attachment.
I am not sure if the resistors value is correct.

#### Qwseyvnd

#10
##### Jun 18, 2014, 12:39 am
Quiet here... bump.

#### Pelleplutt

#11
##### Jun 18, 2014, 05:48 am
400 pins?
Do you try to have 400 input values?

You start an binary series  1, 2, 4, 8. But next become 13 not 16? Then 28 not 32?

With a digital binary input you need 9 pins to represent 512 values

With 3 binary coded decimal thumbwheel switches you can have 1000 values of your input (0-999) using 12 pins.
With multiplexing you can reduce it to  7 pins but then it needs 12 diodes instead.

Can't understand why you are afraid of using pins?

Pelle

#### Grumpy_Mike

#12
##### Jun 18, 2014, 06:33 am
You are not going to do what you want with that circuit., that sort of circuit is only good for a single button detection. It is impossible to work out resistor values to do what you want.

To acheave multiple pressing detection the circuit you need is known as a R2R ladder. It has only two values of resistor one with a value R and one with a value twice that 2R. In fact you can make it with only one value of resistor and have two in seriese for the 2R.

#### larryd

#13
##### Jun 18, 2014, 06:43 am
No technical PMs.