Problem with button readins?

Hi,

So we have a project to demo, we are getting four input pins and printing them on the computer as 1's or 0's. Say, if you press button 1, code 0001 goes to screen. But sometimes it prints 00010001.

At first, it may look like debouncing time is not enough, but that could be fixed by increasing it. But the real problem is that sometimes, it continuously prints data onto screen even if no button is pressed.
We also tried to remove the power supply from the buttons-circuit board, but it continues to print random codes onto the screen even if the buttons aren't powered.

We have buttons connected to vdd and gnd, we also connect diodes to each button prevent code mixup.
What may be the problem, what should we do?

EDIT ..................... CODE EXAMPLE;

void loop()
{
current1 = digitalRead(firstPin);
current2 = digitalRead(secondPin);
current3 = digitalRead(thirdPin);
current4 = digitalRead(fourthPin);

delay(5);

current1 = digitalRead(firstPin);
current2 = digitalRead(secondPin);
current3 = digitalRead(thirdPin);
current4 = digitalRead(fourthPin);

if(current1 == LOW && current2 == LOW
&& current3 == LOW && current4 == HIGH)
{
Serial.println(0); // ARDUIONO prints last number at bottom of com7
Serial.println(0);
Serial.println(0);
Serial.println(1);

delay(200);
}

On the buttons, we are using pull down resistors and vdd. so when you push the button, the vdd is taken to digital input of arduino. Diodes are to give reverse bias because we only have four pins for 13 buttons, and we don't want one button turning on all the buttons connected to its pins. But I don't have a picture of it.

There's ALWAYS something at the pins. Whether they are down or not only decides WHAT to print IF and WHEN you decide to print something.

Without seeing what you have so far, it's impossible to say where you have made your mistakes.

How about showing us a schematic and code?

At first, it may look like debouncing time is not enough, but that could be fixed by increasing it. But the real problem is that sometimes, it continuously prints data onto screen even if no button is pressed.

The logic could get tricky. It looks like you only want to print when there is a state change?

We have buttons connected to vdd and gnd, we also connect diodes to each button prevent code mixup.

Typically, there would be pull-up resistors (or you can use the Arduino's built-in pull-ups) with the switch connected between the input and ground (like the [u]Input Pullup Serial Example[/u]).

Am thinking, that(static change) may be the problem. Because sometimes even if no button is pressed or no vdd supply to buttons, it keeps printing as if a high input was there at some pins.

Peter_Kula:
Am thinking, that(static change) may be the problem. Because sometimes even if no button is pressed or no vdd supply to buttons, it keeps printing as if a high input was there at some pins.

Like I say, unless we see your code, we'll just never know.