Reed switch anD arduino mega

Hi,

I want to count how many times the magnet came closer to the Reed switch sensor, I'm using Reed switch sensor and Arduino Mega. The problem is when the magnet comes closer to the Reed switch sensor (impulse) increase two times, but it must increase only one time. Maybe somebody could explain where is the problem, please.

My program code:

volatile int impulse;
int sensorius = 2;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(sensorius, INPUT);
attachInterrupt(0, count, FALLING);
}

void loop() {
  // put your main code here, to run repeatedly:

}

void count()
{
impulse++;
Serial.print("impulsai = \t");
Serial.println(impulse);


}

An example of my scheme, but my boar is Arduino Mega:

You'll need to print outside of your interrupt routine.

The magnet should have its north pole near one end of the Reed switch, and its south pole near the other end. Move the magnet towards or away from the switch to get a single contact.

Reed switches bounce a lot. You need to debounce the input.
For a start try a 30mS delay after a contact closure is detected.