Go Down

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

Qwseyvnd

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 ?


knut_ny

#2
Jun 16, 2014, 10:29 pm Last 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 A0
12 resistors,   series : 2k2, 180, 220,270,330,470,560,820,1k2,1k8,3k3 og 8k2
2k2 connects to 5V, other end til A0 and 180R. After A0 downwords connects a switch to gnd
Key 0 will  give analog reading 0
Key => 1 ca 77, Key 2: 157, Key 3: 239, Key 4:320, Ket 5: 410,
// knapp (norwegian) = key
Knapp 6: 491, Knapp 7: 577, Knapp 8: 663, Knapp 9: 743, Knapp 10: 825 og Knapp 11: 908
If no key is pressed, you will read near  1023

Key find = integer of ((analog reading+ 41) /  82.5)


********************************************************/
#define analogPin 0
void 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


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 A0
12 resistors,   series : 2k2, 180, 220,270,330,470,560,820,1k2,1k8,3k3 og 8k2
2k2 connects to 5V, other end til A0 and 180R. After A0 downwords connects a switch to gnd
Key 0 will  give analog reading 0
Key => 1 ca 77, Key 2: 157, Key 3: 239, Key 4:320, Ket 5: 410,
// knapp (norwegian) = key
Knapp 6: 491, Knapp 7: 577, Knapp 8: 663, Knapp 9: 743, Knapp 10: 825 og Knapp 11: 908
If no key is pressed, you will read near  1023

Key find = integer of ((analog reading+ 41) /  82.5)


********************************************************/
#define analogPin 0
void 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 pm Last 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

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


Grumpy_Mike

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


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

Here's attachment.
I am not sure if the resistors value is correct.

Qwseyvnd


Pelleplutt

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

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

No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Pelleplutt

Yes, a great idea.
Digital ---> analog ---> digital ;)

Pelle

Go Up