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: