ESP32 Schematic Modification
NODE_12VDC, 12V_PROTECTED, ONEWIRE_GPIO4, DOOR_GPIO18, etc.Table
| Function | GPIO | Schematic Net | Direction | Notes |
|---|---|---|---|---|
| DS18B20 OneWire bus | 4 | ONEWIRE_DQ_GPIO4 | bidirectional | R1 4.7k pull-up to 3V3; multiple sensors allowed |
| Door sensor | 18 | FRIDGE_DOOR_GPIO18 | input | R7 10k pull-up, active-low dry contact/open collector |
| Water leak sensor | 21 | LEAK_WATER_GPIO21 | input | R8 10k pull-up, active-low |
| Water level sensor | 19 | WATER_LEVEL_GPIO19 | input | R9 10k pull-up, optional future input |
| Flow sensor | 23 | FLOW_PULSE_GPIO23 | interrupt input | R6 10k pull-up, active-low/open collector pulses |
| Pump current | 32 | ADC_PUMP_GPIO32 | ADC input | 1k + 100nF RC filter, 0-3.3V isolated transducer |
| Compressor current | 34 | ADC_COMPRESSOR_GPIO34 | ADC input | input-only ADC, 0-3.3V isolated transducer |
| Heater current | 35 | ADC_HEATER_GPIO35 | ADC input | input-only ADC, 0-3.3V isolated transducer |
| Status LED | 2 | LED_STATUS_GPIO2 | output | GPIO2 strapping pin; avoid forcing state at boot |
Ini
[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 lib_deps = paulstoffregen/OneWire@^2.3.8 milesburton/DallasTemperature@^3.11.0
Cpp
#include <Arduino.h> #include <WiFi.h> #include <OneWire.h> #include <DallasTemperature.h> #define PIN_ONEWIRE 4 #define PIN_DOOR 18 #define PIN_LEAK 21 #define PIN_WATER_LEVEL 19 #define PIN_FLOW 23 #define PIN_ADC_PUMP 32 #define PIN_ADC_COMPRESSOR 34 #define PIN_ADC_HEATER 35 #define PIN_STATUS_LED 2 const char* WIFI_SSID = "YOUR_SSID"; const char* WIFI_PASSWORD = "YOUR_PASSWORD"; OneWire oneWire(PIN_ONEWIRE); DallasTemperature ds18b20(&oneWire); volatile uint32_t flowPulseCount = 0; unsigned long lastSampleMs = 0; const unsigned long SAMPLE_INTERVAL_MS = 2000; void IRAM_ATTR onFlowPulse() { flowPulseCount++; } float adcToVolts(int raw) { return (float)raw * 3.3f / 4095.0f; } void connectWiFi() { WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); for (int i = 0; i < 20 && WiFi.status() != WL_CONNECTED; i++) { digitalWrite(PIN_STATUS_LED, !digitalRead(PIN_STATUS_LED)); delay(250); } digitalWrite(PIN_STATUS_LED, WiFi.status() == WL_CONNECTED ? HIGH : LOW); } void setup() { Serial.begin(115200); delay(200); pinMode(PIN_STATUS_LED, OUTPUT); pinMode(PIN_DOOR, INPUT); // external pull-ups are present in schematic pinMode(PIN_LEAK, INPUT); pinMode(PIN_WATER_LEVEL, INPUT); pinMode(PIN_FLOW, INPUT); attachInterrupt(digitalPinToInterrupt(PIN_FLOW), onFlowPulse, FALLING); analogReadResolution(12); analogSetPinAttenuation(PIN_ADC_PUMP, ADC_11db); analogSetPinAttenuation(PIN_ADC_COMPRESSOR, ADC_11db); analogSetPinAttenuation(PIN_ADC_HEATER, ADC_11db); ds18b20.begin(); connectWiFi(); Serial.println("Industrial ESP32 monitor started"); } void loop() { unsigned long now = millis(); if (now - lastSampleMs < SAMPLE_INTERVAL_MS) return; lastSampleMs = now; bool doorClosedOrInactive = digitalRead(PIN_DOOR); bool leakInactive = digitalRead(PIN_LEAK); bool waterLevelInactive = digitalRead(PIN_WATER_LEVEL); noInterrupts(); uint32_t flowPulses = flowPulseCount; flowPulseCount = 0; interrupts(); int rawPump = analogRead(PIN_ADC_PUMP); int rawCompressor = analogRead(PIN_ADC_COMPRESSOR); int rawHeater = analogRead(PIN_ADC_HEATER); ds18b20.requestTemperatures(); int sensorCount = ds18b20.getDeviceCount(); Serial.println("--- sample ---"); Serial.printf("Door active-low raw: %d\n", !doorClosedOrInactive); Serial.printf("Leak active-low raw: %d\n", !leakInactive); Serial.printf("Water level active-low raw: %d\n", !waterLevelInactive); Serial.printf("Flow pulses/%.1fs: %lu\n", SAMPLE_INTERVAL_MS / 1000.0, (unsigned long)flowPulses); Serial.printf("Pump ADC: %.3f V\n", adcToVolts(rawPump)); Serial.printf("Compressor ADC: %.3f V\n", adcToVolts(rawCompressor)); Serial.printf("Heater ADC: %.3f V\n", adcToVolts(rawHeater)); for (int i = 0; i < sensorCount; i++) { Serial.printf("DS18B20[%d]: %.2f C\n", i, ds18b20.getTempCByIndex(i)); } if (WiFi.status() != WL_CONNECTED) connectWiFi(); }
Bash
pio run pio run -t upload pio device monitor
Platform & Toolchain
Pin Mapping
platformio.ini
Complete Firmware Source
Build & Flash