I need help with an ESP32 project involving a water pulse meter, I've encountered a puzzling issue.
My setup consists of an ESP32 development board connected to a water meter with three pins: Red, Black, and White. I'm utilizing the Red and Black pins, with the Red pin set to PULL-DOWN using a 10K resistor and connected to 3.3V, while the Black pin is grounded.
This is the PULL-UP circuit I followed, instead of 5V, its 3.3 V on ESP32
Here is code
#include <EEPROM.h> #define PULSE_ADDRESS 200 #define pin35 35 #define pin25 25 #define pin26 26 #define pin27 27 const int Pulse1 = pin25; const int Pulse2 = pin26; const int Pulse3 = pin27; const int Pulse4 = pin35; int PulseHit = 1; const int debounceDelay = 5000; // Adjust this value based on your requirements volatile unsigned long lastDebounceTimePulse1 = 0; volatile unsigned long lastDebounceTimePulse2 = 0; volatile unsigned long lastDebounceTimePulse3 = 0; volatile unsigned long lastDebounceTimePulse4 = 0; volatile unsigned long pulse1Count = 0; volatile unsigned long pulse2Count = 0; volatile unsigned long pulse3Count = 0; volatile unsigned long pulse4Count = 0; void IRAM_ATTR handlePulse1() { if ((millis() - lastDebounceTimePulse1) > debounceDelay) { PulseHit = 1; lastDebounceTimePulse1 = millis(); pulse1Count++; } } void IRAM_ATTR handlePulse2() { if ((millis() - lastDebounceTimePulse2) > debounceDelay) { PulseHit = 1; lastDebounceTimePulse2 = millis(); pulse2Count++; } } void IRAM_ATTR handlePulse3() { if ((millis() - lastDebounceTimePulse3) > debounceDelay) { PulseHit = 1; lastDebounceTimePulse3 = millis(); pulse3Count++; } } void IRAM_ATTR handlePulse4() { if ((millis() - lastDebounceTimePulse4) > debounceDelay) { PulseHit = 1; lastDebounceTimePulse4 = millis(); pulse4Count++; } } void setup() { Serial.begin(115200); pinMode(Pulse1, INPUT); pinMode(Pulse2, INPUT); pinMode(Pulse3, INPUT); pinMode(Pulse4, INPUT); attachInterrupt(digitalPinToInterrupt(Pulse1), handlePulse1, RISING); attachInterrupt(digitalPinToInterrupt(Pulse2), handlePulse2, RISING); attachInterrupt(digitalPinToInterrupt(Pulse3), handlePulse3, RISING); attachInterrupt(digitalPinToInterrupt(Pulse4), handlePulse4, RISING); lastDebounceTimePulse1 = millis(); lastDebounceTimePulse2 = millis(); lastDebounceTimePulse3 = millis(); lastDebounceTimePulse4 = millis(); EEPROM.begin(512); EEPROM.get(PULSE_ADDRESS, pulse1Count); EEPROM.get(PULSE_ADDRESS + sizeof(pulse1Count), pulse2Count); EEPROM.get(PULSE_ADDRESS + 2 * sizeof(pulse1Count), pulse3Count); EEPROM.get(PULSE_ADDRESS + 3 * sizeof(pulse1Count), pulse4Count); EEPROM.end(); } void loop() { // Print the results if (PulseHit == 1) { Serial.print("RISING Pulse on pin 25: "); Serial.println(pulse1Count); Serial.print("RISING Pulse on pin 26: "); Serial.println(pulse2Count); Serial.print("RISING Pulse on pin 27: "); Serial.println(pulse3Count); Serial.print("RISING Pulse on pin 35: "); Serial.println(pulse4Count); Serial.println(" "); PulseHit = 0; // Save pulse counts to EEPROM EEPROM.begin(512); EEPROM.put(PULSE_ADDRESS, pulse1Count); EEPROM.put(PULSE_ADDRESS + sizeof(pulse1Count), pulse2Count); EEPROM.put(PULSE_ADDRESS + 2 * sizeof(pulse1Count), pulse3Count); EEPROM.put(PULSE_ADDRESS + 3 * sizeof(pulse1Count), pulse4Count); EEPROM.commit(); EEPROM.end(); } }
However, I've noticed an unexpected behavior: when I power the ESP32 via an external 5V adapter plugged into a socket, the connected meter wire begins to register signals from the surroundings or some other interference source. Consequently, the pulse counter associated with the GPIO pin (to which the meter's Red-Black wire is connected) starts incrementing
When I power the ESP32 using my laptop, everything functions perfectly fine.
There is no such high signal around the ESP32 either, it just when the powered with socket directly, pulse interrupt doesn't work as required only when power with laptop.
Any suggestion to overcome this self triggering or stop signal interference from external sources.
Things I have tried so far.
Instead of PULL-UP to Red wire and GND to black, I have tried PULL-DOWN to Red wire and 3.3V to Black as well but same response.
I have tried 2596 DC-Dc converter 12v-5v to ESP32, still Same response.
I Have tried lower resistor for PULL-UP 330 ohm, it seem to be working for a while, but when I increased the wire length (Red-black) about 1-2 ft more, it started pulse counter again.
I can't use the stock? wire of the meter, I need to extend to safe place for ESP32 PCB to install.