Create keyboard

Hi,

First of all, thanks for reading this thread. I just started playing around with a arduino. I’ve created a traffic light and used a speaker ect. But now I want to create something serious, so I tought let’s create my own keyboard!

I want to have 25 soft buttons, but not use 25 wires because that would be to sloppy. So I want to use foil to make kind of a grid structure like in the image. (sorry for the typo in the image)

But now i’ve created this, but how do I know what button is pressed?

I set all the ground pins as “OUTPUT” and “LOW” and the other pins on “INPUT” and “HIGH”. I need to know what ground pin is used in order to know what button is pressed. But the ground pin is always on “LOW”.

So my main question is: How do I know what ground wire is used?

My current code:

const int ledPin = 5; // Set led + at pin 5
const int ledGND = 7; // Set led - at pin 7

// Set pin 0, 1, 2, 3, 4 as - pin
const int buttonsGND[] = {
 0,1,2,3,4 
};

// Set pin 8, 9, 10, 11, 12 as + pin
const int buttonsPin[] = {
  8,9,10,11,12
};

// Variable to remember button press
int buttonPressed = 0;
int buttonState = 0;

void setup() {
  
  // Set the led + and - as output 
  pinMode(ledPin, OUTPUT);
  pinMode(ledGND, OUTPUT);
 
  
  // Foreach button
  for(int i = 0; i < 5; i++)
  {
   
   // Set the - pin as output
   pinMode(buttonsGND[i], OUTPUT);
   // Set the - pin off
   digitalWrite(buttonsGND[i], LOW);
   
  }
  
  for(int i = 0; i < 5; i++)
  {
   // Set the + pin as input
   pinMode(buttonsPin[i], INPUT);
   
   // Set the + pin on
   digitalWrite(buttonsPin[i], HIGH);
  }
  
  Serial.begin(9600); 
}

void loop() {
  
//  for(int i = 0; i < 5; i++)
//  {
//      if(digitalRead(buttonsGND[i]) == HIGH)
 //     {
 //          digitalWrite(ledPin, HIGH); 
 //     }
 //     else
 //     {
//           digitalWrite(ledPin, LOW);
//      }
//  }
  
  Serial.print("Ground pin value: ");
  Serial.println(digitalRead(buttonsGND[1]));
  Serial.print("Plus pin value: ");
  Serial.println(digitalRead(buttonsPin[0));
  
  delay(100);
}

Sorry for my bad english but, can someone help me out?

Kind reguards,

Feonx

Dont connect both layers of your "foil" to the pins , connect one layer say the bottom layer to ground (all of them) and then connect your individual top layers to the digital pins .. use the standard button method to detect the keypresses .. see http://www.arduino.cc/en/Tutorial/Button using a resistor to make sure the button inputs are in a constant state is also good practice.

if you want to get fancy or are running out of digital inputs check out http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267115381

zx

I set all the ground pins as "OUTPUT" and "LOW" and the other pins on "INPUT" and "HIGH". I need to know what ground pin is used in order to know what button is pressed. But the ground pin is always on "LOW".

No you only set one row to ground and the rest should be high. The the columns should be set as inputs with the internal pull up resistors enabled. If you see a low on any of the column inputs you know that key on that column is being held low. If nothing is read as low then make the low row high and set the next row to low. Repeat this until you scan the whole matrix.

The problem with this setup is that if you ever press two buttons at the same time it will look like four have been pressed. This is because the ground shorts through the buttons. To prevent this you should have diodes in line with each push button. This project has the correct form of a keypad along with some LEDs which you can ignore. http://www.thebox.myzen.co.uk/Hardware/Econo_Monome.html