Hello to everyone!
I write this post, as a last chance, after days and hours of struggling with a problem I can't find a solution for, and I don't know how to fix it (even if I found similar problems on this forum, none of them works, or fits to my particular situation.
I've attached a rain gauge (bassicaly a reed relay) to an Arduino pin2, to detect rain, using interrupts.
The problem is that, all this setup, is near (30-40 cm) to a watterpump (hydrofore) and when this pumps turns on or off, sometimes (but not all the times) false interrupts triggers.
Now, I will write the test that I've made:
- First of all to eliminate the possibility of noisy power supply, I powered the arduino from a 5V externall battery pack.
- With cable from rain gauge, disconnected, the problem dissapear. (Even if i put the PCB with the arduino directly on the chasis of that waterpump. This means that, the rain gauge wire gets some sort of noise that triggers the interrupt.
- After this, I changed the unshielded cable from rain gauge, to a shielded one (not twisted pair), grounded the shield to earth, but the problem still remains.
- Tried lots of other position of the arduino / and the wire from rain gauge, as far as I can from waterpump, some with better results, some not, but the problem its still there.
- Tried to wire pullups resistors of many values, and a 0,01uF capacitor to pin2 but none of them helped.
I will show you the two schematics I've tryed so far, and the code for the interrupt routine.
I even try this with an ESP32 dev board, interrupt pin 34, but with the same results.
I found a sketch here, that basically "filters" the noise from software...but, it runs very fast in the loop, and the MCU should listen to that all the time.... not applicable to me, sincer I run other things in the loop (I use Blynk app, and the loop has about 1.5 sec). Thats why interrupts are for..no?
Bellow I will show you the code (the ISR routine, I I need to, I can show all the code, but I think it is irelevant) and the rain gauge schematics.
#define Bucket_Size 0.3 // rain bucket size (0.3mm)
#define RainSensorPin 2
void setup()
{
attachInterrupt(digitalPinToInterrupt(RainSensorPin), isr_rg, FALLING);
}
void isr_rg() {
if((millis() - contactTime) > 30 ) { // debounce of sensor signal - I also tryed here many values from 30 to 800.
tipCount1h++;
tipCount24h++;
contactTime = millis();
}
}
Thanks in advance for any help.
Adrian.