False interrupts when not in my office. (noise?)

My first big Arduino project has hit its first major problem that I cannot seem to solve by myself.

In short it's a data logger that (among other things) counts revolutions on an axle via an interrupt on INT5 (D18) via "Slot-type Optocoupler". It runs on a Arduino Mega 2560 with a TFT/SD shield

When testing in the office it all works fine. Each time I breach the slot sensor it will count 1 up. As soon I place the Setup in the boiler room and make real readings then I get a lot of false interrupts.

I have tried to shield the setup in a metal box. I tried 1uF from my DO on the sensor to 0V to try and "eat" small spikes

Can noise enter through the VCC that gets it power from a transformer plugged to 220V?

I know my code might not be perfect, but I'm new to Arduino and C++ and first goal is to make it work.....perfect comes later :)

Background info:

What is the distance from sensor to Arduino input?

Try a 0.1uF on the input to Arduino.

Weedpharma

At the moment its all monted on a Breadbord and the wires from the bord to sensor is aprox. 20 cm. I might want to try and twist the wires to se if it helps. I thought that a clean digital signal from an optocoupler was hard to mess up, but I guess not :)

I have now done further testing. Even if I do not activate the sensor I get false readings with 9 volt transformer supply. The problem seems to go away after I tried with battery supply.

It seems the noise comes trough the wall power outlet. The boiler runs on the same phase, so it might make sense after all.

Now....how do I remove the noise from VCC? I will try different transformers. There might be a difference there.

I’m not sure how long a valid pulse from the opto lasts but could you check it more than once for each pulse to make sure it is not just noise?

int counter = 0;
while ((feedInt) && (counter < 5) // check feedInt has triggered for a valid time 5ms?
{
delay(1);
counter ++;
}
if (feedInt)
{
// valid signal
}

To help remove noise on Vcc you could put one large (470uF) and one small (100nF) capacitor on the supply to help suppress noise, it could be noise induced on the signal wires though so you could try a shielded cable with one end of the shield connected to ground.