Hi,
I am having a weird issue with an interrupt.
I have an external power (12V) source that runs through a voltage regulator (5V) then to two Arduinos.
Arduino 1 is the one with an issue.
The interrupt is a simple momentary button for travel limiting.
It is wired from Pin5 which supplies power through the switch then to Pin 2 which is the interrupt.
When I connect the external power via Vin, the interrupt stops working.
If I disconnect the Vin, it begins working again.
Also, when i connect a resistor (1K) to pin 2 and dangle an alligator connect from it, with the interrupt still attached, it starts working again.
The other end of the alligator clip is connected to nothing it is just dangling there.
If I take away the alligator clip and just have one side of the resistor in there is does not work either.
Any Ideas about what is going on or a solution that does not involve the alligator clip?
Code Below:
//Swtich Interupt
const int LimitSwitch = 5; //Sets Swtich Interupt Output Pin to 5;
void setup() {
pinMode(LimitSwitch, OUTPUT); //Initializes Switch Pin to Output
digitalWrite(LimitSwitch, HIGH); //Pin 5 HIGH
Serial.begin(115200);
attachInterrupt(0, StrokeLimit, FALLING);
}
void loop() {
}
//###############################################################
//############################ Stroke Limit #####################
//###############################################################
//Detected Interaction
void StrokeLimit(){
Serial.println("Stroke Limit Detected"); //Print Interation Detected in Serial Monitor
}
Why are you using an interrupt to detect a mechanical switch?
That's like driving a car instead of walking 10 yards.
Switch bounce will mean that it will call your interrupt routine several (maybe hundreds of) times for every switch closure and opening. Instead, poll the state of the switch in loop() and use a debounce routine.