Swimming Pool Chemical Dispenser

I calibrated the sensors using an Arduino UNO, using the Atlas Scientific sample code.

But here is my ESPHome code. We also need to call C code to unable the sensors:

ESPHome code:


esphome:
  name: pool_management
  platform: ESP8266
  board: huzzah
  includes:
    - my_custom_component.h


wifi:
  ssid: "XXXXXXX"
  password: "XXXXXXXX"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Pool Management Fallback Hotspot"
    password: "XXXXXXXX"

captive_portal:

logger:

api:
  password: "XXXXXXXX"

ota:
  password: "XXXXXXXX"
  
sensor:
  - platform: ezo
    id: orp_ezo
    name: "orp"
    address: 0x62
    accuracy_decimals: 3
    unit_of_measurement: "mV"
    update_interval: 15s
  - platform: ezo
    id: ph_ezo
    name: "pH"
    address: 0x63
    accuracy_decimals: 3
    unit_of_measurement: "pH"
    update_interval: 15s

i2c:
    sda: D4
    scl: D5
    scan: True

custom_component:
- lambda: |-
    auto my_custom = new MyCustomComponent();
    return {my_custom};

And create a file called my_custom_component.h in the root of your ESPHome folder


#include "esphome.h"

class MyCustomComponent : public Component {
 public:
  void setup() override {
    // This will be called once to set up the component
    // think of it as the setup() call in Arduino
  pinMode(14, OUTPUT);                                                         //set enable pins as outputs
  pinMode(12, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(13, OUTPUT);
  }
  void loop() override {
    // This will be called very often after setup time.
    // think of it as the loop() call in Arduino
                digitalWrite(14, LOW);                                                       //set enable pins to enable the circuits
                digitalWrite(12, LOW);
                digitalWrite(15, HIGH);
                digitalWrite(13, LOW);

  }
};

1 Like