"Bouncing" 5VSignal

Hi Guys,
i'm currently working on a small project and got a "bouncing" Problem.
Here is my Setup :
ATMega168 waiting on a Digital In(Pin 12) for a 5v Signal (comming from 9V with a LP2950)

void loop()  
{  
   value=digitalRead(12); // Read Status of the Input Pin
   setSignal(12,value);
}  

void setSignal(int port,int value)
{
  if(value ==HIGH) // if status is active, create protocol 
    {
     Serial.Print("High");
    }
}

Now everytime the Signal on Pin12 gets High, the Serial Output will Print out a minimum of 15 "High" :frowning:
I already tested the "bounce"-library for Arduino, but it will make thinks even worster.

Any Ideas, even electronical based ?
(already tried my luck with a 4,7µF Cap on the 5v Line)

Thanks in advance ..

What you have there is not a bounce problem, but a programming problem.

What your program is saying is, for 100% of the time (every time through loop()) test the input, and if it is high then print "HIGH".

You press the button, and the loop runs many many times before you release it, so it prints HIGH many many times, because the input is high all the time you press the button.

You need to change your program so it instead goes "If the input is HIGH now, and last time I checked it was LOW, then print HIGH.".

This is called "edge triggering" - what you have at the moment is "level triggering". You need to react to the transition between LOW and HIGH, not just if it's HIGH or not.

Here’s how you can modify your code to make it work the way you want. This will print “High” to the serial port whenever the switch is closed, and it will also “debounce” the switch, too.

Each time through the loop, it checks if the pin is HIGH. If it is, it increments a counter. If it is not, it clears the counter to zero. (It also resets the counter to 6 just before the counter overflows to prevent wraparound.) If the counter counts all the way to 5, then it prints “High” to the serial port. At the end of each loop, it waits for 1 millisecond. This delay makes the debouncing working better.

int count = 0;
int value = LOW;
void loop()  
{
  value=digitalRead(12); // Read Status of the Input Pin
  if(value==HIGH) {
    count++;
  }
  if(value==LOW) {
    count=0;
  }
  if(count==5) {
    Serial.Print("High");
  }
  if(count==32767 ) {
    count=6;
  }
  delay(1);
}