WaterMeter and GazMeter - Reed IRQ False positive
-
Hello Team,
I have a concern
I created 2 sensors. A waterpulse counter based on Reed switch and a Gaz Counter based also on reed switch. For the waterpulse counter, the .ino is the one provided on the mysensors website. My problem is that I have some false positive.
WhenI just plug the arduino in USB on my MAC, it works. However, If I connect it from a power supply 220V ( vin or USB), I have some issues, and I have some pulse even if there is nothing. For example, I have a soleniod valve, if I switch it ON/OFF, it troubles the Reed IRQ signal and I have a false pulse taking in account...
So, my question is how to remove the interference. I use the reed switch in pullup, and I applied a 10uF capacitor on the reed switch.
Should I use a specific powersupply with a filter ???? I'm lost I made some tests during 6 hours without any good result.
please help...
-
Have a look at mine, I don't have any false positive with a reed adapted this way:
https://github.com/empierre/arduino/blob/master/WaterMeterPulseSensor2.ino
-
Hello,
You code just remove multiple pulse during a short period of time, like a push button.
My problem is different. I have to remove the first random pulse ! Each pulse is important for me as I use it for my gaz cooker.
In fact, I found the solution, I remove the IRQ interrupt. The reed switch clode around 250ms. So I test during each loop. If the switch is close, I wait 30ms and test again if switch is close. If it is still close, it means that's not a false postiive and I can count a pulse.
I have the code since 1 week, and it works properly without any false pulse.
In fact my solenoide valve is too close from arduino and it make some interference I can't remove with capacitors...
Here is my code:if (state != laststate) { delay(30); if (state != laststate) { delay(30); if (state != laststate) { if (state == HIGH) { unsigned long newBlink = micros(); unsigned long interval = newBlink-lastBlink; lastPulse = millis(); flow = (60000000.0 /interval) / ppl; lastBlink = newBlink; pulseCount++; Serial.print("pulseCount:"); Serial.println(pulseCount); Serial.print("interval:"); Serial.println(interval/1000); state = laststate; flow = (60000000.0 / interval) / ppl; alarm_flag = 1; // state1 == true; // un pulse est apparu, on demarre l'alarm lastBlink = newBlink; alarm1 = 0; alarm1_t = millis(); } if (state == LOW) { state = laststate; } } } } }```
-
@doblanch said:
if (state != laststate)
{
delay(30);
if (state != laststate)
{
delay(30);
if (state != laststate)why do you have these blocking delay()s? I would focus on non-blocking code for such a device... Are you using an interrupt?
I think you need to post your entire sketch to get good comments