Go Down

Topic: Help on momentary push switches in series. (Read 1 time) previous topic - next topic

be80be

Here a simple way to add 13 buttons all resistors are 220 ohm you'll only need Ground  and a A0 pin
and there code that works with the idea in the Playground

Thot

That's an interesting idea!

The node on top is connected to +5, right?
Then the circuit acts as a voltage divider with each switch press bypassing a resistor and decreasing the total resistance.
But if the resistors have all the same value, can the program tell which button is pressed or only how many are pressed?
What's the value of the capacitor?

And, can you post the link to the playground article?

Thanks

There are three kind of people in the world: Those who can count, and those who can't

dhenry

You should think of R2R type networks and imaging your buttons are pins outputing to that R2R network.

This can uniquely determine which buttons are pushed.

be80be

Here some code to test 13 button wired up as I posted 

Code: [Select]
const int keyMin = 0;      // Keymin, discovered through experiment
const int keyMax = 1023;    // keymax, discovered through experiment
void setup() {
  Serial.begin(9600);
}
void loop() {
  // read the sensor:
  int key = analogRead(A0);
  // map the sensor range to a range of four options:
  int keyValue = map(key, keyMin, keyMax, 0, 3);

  // do something different depending on the
  // range value:
  switch (keyValue) {
  case 0:    // your hand is on the sensor
    Serial.println("button1");
    break;
  case 1:    // your hand is close to the sensor
    Serial.println("button2");
    break;
  case 2:    // your hand is a few inches from the sensor
    Serial.println("button3");
    break;
  case 3:    // your hand is nowhere near the sensor
    Serial.println("button4t");
    break;
    case 4:    // your hand is nowhere near the sensor
    Serial.println("button5");
    break;
case 5:    // your hand is nowhere near the sensor
    Serial.println("button6");
    break;
case 6:    // your hand is nowhere near the sensor
    Serial.println("button7");
    break;
case 7:    // your hand is nowhere near the sensor
    Serial.println("button8");
    break;
case 8:    // your hand is nowhere near the sensor
    Serial.println("button9");
    break;
case 9:    // your hand is nowhere near the sensor
    Serial.println("button10");
    break;
case 10:    // your hand is nowhere near the sensor
    Serial.println("button11");
    break;
case 11:    // your hand is nowhere near the sensor
    Serial.println("button12");
    break;
case 12:    // your hand is nowhere near the sensor
    Serial.println("button13");
    break;

  }
  delay(1);        // delay in between reads for stability
}



MarkT


You should think of R2R type networks and imaging your buttons are pins outputing to that R2R network.

This can uniquely determine which buttons are pushed.



Doesn't work - R-2R networks only work with SPDT switches, not SPST push buttons.
[ I won't respond to messages, use the forum please ]

Go Up