Interrupt triggering unexpectedly

Hello,
I am using the Arduino 2560 to control a number of 120VAC solendoids. I use digital pins 22,24,26,28 to trigger the dc side of dc-ac optically isolated SSRs which then power the valves. This system works great, and has been in use for months. Recently, I added an interrupt option, and that's where the trouble begins. Here's the setup portion of the code:

void setup()
{
  delay(1000); //Allow for full booting of board before operation.
  pinMode(2,INPUT); //setup pin2 for use as interrupt1, Isolation.
  pinMode(53,OUTPUT); //setup pin53 for signal to interrupt0.
  digitalWrite(53,HIGH); //setup pin53 for signal to interrupt0.
  
  attachInterrupt(1,Isolation,RISING); //Initiate Isolation procedure when int.0 is in the LOW state.
  
  pinMode(V1,OUTPUT); //SSR trigger signal for V1
  pinMode(V2,OUTPUT); //SSR trigger signal for v2
  pinMode(V3,OUTPUT); //SSR trigger signal for v2
  pinMode(V4,OUTPUT); //SSR trigger signal for v2
  
  Serial.begin(9600);
}

I wanted a switch that would interrupt the repeating valve sequence and force a particular configuration on the system. It works as expected when triggered, but unfortunately it seems to trigger unexpectedly as well. Initially the switch functioned to break the circuit between pin 53(set to HIGH) and int.1 (using 10Kohm pulldown resistor), with attachInterrupt triggering on LOW. I changed to a switch that completed the connection and had attachInterrupt trigger on RISING. The same effect was observed, an unexpected triggering of the interrupt.

I was worried about bad connections, so I bought and soldered a protoboard, which looks nice, but did not solve the issue. I checked the DC input to the SSR, and the resistance is 7kohms, so I don't think I'm drawing too much current on pins 22,24,26,28.

There are sources of mechanical vibration and electrical noise (1/8hp DC motors nearby) which seem to coincide with the interrupt triggering. Is it possible that I am getting electrical noise? If there was a DC offset travelling along the frame, then the bad behavior should only be seen in the LOW or RISING trigger options of attachInterrupt, not both. That leaves me looking for sources of AC noise or bad connections. Any tips?

If it's a mechanical switch the most likely cause is contact bounce which can cause multiple interrupts both on the make and break of the switch contacts. Some form of switch debouncing is needed, either with hardware and/or software methods, although software debounce using interrupts can be pretty complex in my opinion. Lots of information on the net about debouncing.

collin3271:
I wanted a switch that would interrupt the repeating valve sequence and force a particular configuration on the system.

Handling a switch input shouldn't need an interrupt. If you use a non-blocking design, it can slot in very simply.

Regarding the unexpected interrupt, what pin have you connected the switch to? How is it wired? You aren't enabling the internal pull-up for pin3 so you would need to use an external pull-down.

Hello,
pin 53 is set to digitalWrite HIGH, wired directly to SPST Normal Open switch. Return from the switch goes to pin2 (int.1) and also to ground via a 10kohm resistor (pulldown resistor).

collin3271:
pin 53 is set to digitalWrite HIGH, wired directly to SPST Normal Open switch. Return from the switch goes to pin2 (int.1) and also to ground via a 10kohm resistor (pulldown resistor).

First (or is it the other?) is using interrupts to read a mechanical switch. Very bad idea due to contact bounce and other problems, also indicates shoddy program design. Reading switches should be done by "polling" at the appropriate place in the main loop of the program using a debounce process which many of us are happy to explain and offer code (leading to "me too" disputes).

Second is "floating" switches. As far as possible, switches should return to ground, not to the supply line as doing that means that you are extending the 5V supply line out to places away from the MCU where you probably do not want it to be and really inviting failure (shorts) and noise pick-up. Return to ground allows you to use the internal pull-ups which you can activate or deactivate in software. If you need a "stronger" pull-up than the internal one (equivalent to approximately 10k) then you can provide that, but it (and the Vcc line) is neatly contained within the Arduino assembly.

collin3271:
pin 53 is set to digitalWrite HIGH, wired directly to SPST Normal Open switch. Return from the switch goes to pin2 (int.1) and also to ground via a 10kohm resistor (pulldown resistor).

You can avoid using pin 53 and get rid of the external resistor by enabling the internal pull-up on your input pin and connecting the switch between your input pin and ground. This will make the input active-LOW so you would need to update your code accordingly.

According to my reading of the documentation, interrupt 1 is associated with pin 3 not pin 2. If you are connecting your switch to the wrong pin and the right pin is left floating, that would trigger spurious interrupts.

The interrupt triggers without any pressing of the switch, so I don't think debouncing is the issue. If I understand the term correctly, it refers to checking the state of the switch multiple times during its normal actuation. The error I see triggers without any switch actuation.

I rewired the switch to go to ground(and made the necessary changes to the code), as was suggested to help with noise pickup. Still, no better. Simply touching the insulated leads involved in the interrupt can trigger it, making me think the board itself is already getting contaminated with ac noise in the area.

So I sidestepped the issue by using a relay to override the switching normally done by the arduino and SSR's. An external relay (24vdc power supply, maintained turn switch) provides 120VAC to the units I want on, and interrupts power to those I want off. In short, the power configuration in the code is now hardwired, and switched with a DPDT relay (2 power circuits needed to be switched on, 1 needed to be switched off). Not exactly an arduino related solution, but useful and robust none the less. Had nothing but success once it was installed. There may be electrical noise in the area, but its not sustained 24vdc offset, so the relay is unaffected.

Thanks for your replies and advice, they were helpful and very much appreciated!
Cheers

collin3271:
Simply touching the insulated leads involved in the interrupt can trigger it

That is a typical characteristic of a floating input.

...but unfortunately it seems to trigger unexpectedly as well.

On start-up or after the system has been running?

Do you ever call detachInterrupt?