Interrupt problems on Arduino


Not sure if it is the best place to post this… I am sorry If not.
My problems is with arduino interrupts.

(Mainboard used is Arduino UNO. (I will switch to mega, since the sketch is getting too big for a UNO))

I made a weather station … all good and working great, except the rain sensor (who has a reed relay) and it’s working with interrupts to count rain. (on Pin 2)

Problem is, that sometimes, it counts even if the switch in the rain gauge is not activated. There is not a general rule for this. Yesterday for example, it passed 1 hour without any count, then it started to count.

I will attach the code, since it is too big to post it here. The problematic part is the one that handles the RainSensorPin intrerrupt, and isr_rg void.

Intrerrupt Is used also in win sensor speed (on pin 3), and it is working great.
Attached, you see the schematic of the rain gauge connection.

It has a contact bounce time in the sketch… this value was 15, but I changed this to 1400, because it counts 3 to 4 times at a single relay switch.

The rain sensor is wired with approx. 10 m of speaker cable (red and black cable 2 x 0.35 mm ) If this matters… I even tried to put a smaller resistor instead of 10k… but no effect. Can this be a problem? I need some shielded cable? Does it pick up interference? Don’t know what to think anymore.

Even more, this morning I disconnect the rain gauge totally…and it started to count like crazy.
I did not understand why… because nothing is now connected to RainSensorPin D2. Why it detects intrerupt now?

Thank you! (5.55 KB)

Use a 1K pull up resistor not a pull down one. This will invert the logic but will provide a bit of screening. Also put a 0.1uF capacitor across the switch.


Thank you for your reply. I’ve attach a schematic with your sugestion. Please confirm if it’s OK.


Yes that looks fine to start with. See how it goes.

Wired everything! After 10-15 minutes of silence… I got 2 false counters… :frowning:
I’ve changed the arduino board… but nothing happens. It’s not a board problem.

I am getting crazy… it is such a small and easy task to do… and I am unable to resolve this problem.
What else should I try?

Next logical step is to completely disconnect the wires from the gauge…leaving just the resistor and capacitor… this way I will eliminate the possibility of interference from those 10m of cable, and the gauge itself.

Keep in touch with the news, meanwhile if you have other ideas…feel free to write!


@adiculiniute, post your program - and not in a ZIP file.


Ok, here I can’t because the message exceeds the maximum characters. I will attach it as it is… “.ino” file.


pws-wunder.ino (18.4 KB)

How long are the wires between the Arduino and the rain sensor ?

Change the 1K to 240R and see if that makes a difference. The thing is that interference suppression is more of an art than a science.

If you still get trouble you can try putting it back to 1K and then add a series resistor of 100R into the line going out to the switch.

The point is you are getting rapid pulses being picked up so you have to slow them down. Another trick is to put a small inductor in the signal line, use twisted pair cable or even screened cable.

Finally you can always use a differential line driver / receiver to send the signal. I use a AM26LS31A and AM26LS32A for going long distances.

How long are the wires between the Arduino and the rain sensor ?

10 meters.

Ok… I have a good news. With rain gauge disconnected I have no counter. It’s been 3 hours since I have 0 counts. That means the arduino and the code is fine.

The problem is with the cable and or rain gauge. With that in mind… I am thinking about something.

The rain gauge I founded in a store with weather station spare parts. It is the spare part from a Ventus Weather Station. It has a PCB with some electronic parts, it has wifi that communicates with the Ventus Station Base. I am not interested at all what this does, I just soldered my 2 wires at the reed relay contacts… but, I did not isolate this from the rest of the rain gauge PCB. Maybe some electronics part in this… gives me those false intrerupts.

I made some pictures with the gauge…

So, right now I am scratching the original PCB from the gauge, to isolate the reed relay contacts.



It passed a night without precipitations :slight_smile: Until now, I have 0 counts, and I guess it will remain like this until real rain drops. Hope it is not a false conclusion!

Seems that the problem is solved. Unbelievable! In conclusion: the PCB from the rain gauge caused those false interrupts. Maybe when I give power to one of the relay contact, it powered the entire PCB and maybe the Wifi module gave some interference or something.

I will leave the pull up resistor and the 0.1 capacitor, since it is not a bad thing.

Thank you very much!

Best regards,

It might be the voltage from the pull up resistor was causing parasitic powering on the rest of the device.