Hydropronic Farming: Water TDS, PH level hassio

Home Assistant automation projects, questions, etc. go here.
Post Reply
Bacardi700
LED-Curious
LED-Curious
Reactions:
Posts: 5
Joined: Sat Dec 19, 2020 11:37 am

Hi All,

Good day, nod
I am trying to add TDS and PH based sensors to hassio, i tried the analogue sensor but not much accurate and i am using the ESP32 node mcu 32s and ph analog sensor.

YAML:

Code: Select all

esphome:
  name: test_1
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: "sfsfdf"
  password: "sffsdf*"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "sdfs"
    password: "sdfsdf"


captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

sensor:
  # https://esphome.io/components/sensor/adc.html
  - platform: adc
    pin: 32
    attenuation: 11db
    id: ph
    name: "pH Sensor"
    update_interval: 1s
    unit_of_measurement: pH
    # https://esphome.io/components/sensor/index.html#sensor-filters
    filters:
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3
      # Measured voltage -> Actual pH (buffer solution)
      - calibrate_linear:
          - 0.59 -> 7.0
          - 0.71 -> 4.0

i2c:
  sda: 35
  scl: 32
  scan: true
Products used:
https://www.amazon.in/xcluma-Developmen ... r=8-1&th=1 ESP32 board

https://robu.in/product/grove-ph-sensor ... 7NEALw_wcB Grove PH Sensor Kit

the current output is not satisfactory,

kindly suggest and your coffee is on me :)
Baylos
LED-Curious
LED-Curious
Reactions:
Posts: 22
Joined: Sat Nov 07, 2020 11:49 am

Hey Barcardi,

I would assume the resolution of the ADC from the ESP32 is not high enough. You can give a separate ADC a try. I use ads1115 and it works with DFrobot SEN0169 and ESP32. Also, I have a temperature sensor on it too, it is important for calculating the correct ph.

Greetings

B
stud
LED Lover
LED Lover
Reactions:
Posts: 143
Joined: Wed Jun 03, 2020 4:19 pm
Location: Canada

or EZO sensors , working here with ESPHome : viewtopic.php?f=35&t=5771
, and now Tasmota also supports it on ver 9.2 : https://tasmota.github.io/docs/EZO/
good luck wt your project
Bacardi700
LED-Curious
LED-Curious
Reactions:
Posts: 5
Joined: Sat Dec 19, 2020 11:37 am

Baylos wrote:
Sun Dec 20, 2020 6:29 pm
Hey Barcardi,

I would assume the resolution of the ADC from the ESP32 is not high enough. You can give a separate ADC a try. I use ads1115 and it works with DFrobot SEN0169 and ESP32. Also, I have a temperature sensor on it too, it is important for calculating the correct ph.

Greetings

B
Could you please share the wiring and code used in esphome :ugeek:
Bacardi700
LED-Curious
LED-Curious
Reactions:
Posts: 5
Joined: Sat Dec 19, 2020 11:37 am

stud wrote:
Tue Dec 22, 2020 8:14 pm
or EZO sensors , working here with ESPHome : viewtopic.php?f=35&t=5771
, and now Tasmota also supports it on ver 9.2 : https://tasmota.github.io/docs/EZO/
good luck wt your project
Thank you for the links and I never knew tasmota supported this feature, could you please help me with the wiring on a esp82 or esp32.

1) Also how do i calibrate the probe ?
2) Do i need to purchase just the Atlas Scientific EZO-pH Embedded pH Circuit or along with the carrier board.

Apologies, noob here :)
stud
LED Lover
LED Lover
Reactions:
Posts: 143
Joined: Wed Jun 03, 2020 4:19 pm
Location: Canada

hello its not hard to plug the sensor , i'm also a learning noob , i'm using the i2c protocol .so you have to make sure the sensor is on i2c mode ,not uart .
the original tasmota.bin does not have EZO sensors enabled by default due to binary size limitations , you have to recompile tasmota and uncomment the EZO sensors in myuserconfig.h .
this was my fisrt time compiling a bin file ,thanks to DigiBlur's video tutorial, worked on the first try for me using Gitpod.io :


no need for schematic , its very simple to plug i2c devices , just plug SDA and SCL of sensor to the SDA and SCL of microcontroller .(make sure the sensor is on I2C mode)
i'm on a Wemos Mini D1 and the sensor is powered by 5 volts from Wemos ,also works on 3.3v .
to calibrate you can chk this post ,i can now calibrate from Tasmota or Home Assustant thx to @LEDG
you can follow this post : viewtopic.php?f=35&t=6068
i did buy the carrier isolated board ,i have the older version 1 . when i buy the EZOEC i guess i will get the v2 .

good luck

PS.: i attached my compiled tasmota bin , i only enabled EZO-PH on it to test and works amazing . i just ordered a EZO-EC , i will have to recompile again to enable EZO-EC .
Attachments
tasmota_ezoph.zip
(420.61 KiB) Downloaded 87 times
ezo tas.png
Last edited by stud on Sun Jan 03, 2021 10:15 pm, edited 5 times in total.
Baylos
LED-Curious
LED-Curious
Reactions:
Posts: 22
Joined: Sat Nov 07, 2020 11:49 am

Hi Barcardi,

for the wiring of ESP32 with ADC11x5, I found this youtube video useful: https://www.youtube.com/watch?v=XxUMc1jnI9U&t=122s.

I use DFRobot Probe and the following library helped me get it done. https://github.com/GreenPonik/DFRobot_E ... GREENPONIK.

(I use SEN0169.)

I had ordered DFR0504, which is an isolator interface. Once my EC probe will arrive I can upgrade the ESP32 with an isolator interface for ph and EC.

I do ph calibration once a month.


BR
Bacardi700
LED-Curious
LED-Curious
Reactions:
Posts: 5
Joined: Sat Dec 19, 2020 11:37 am

stud wrote:
Sun Jan 03, 2021 6:03 pm
hello its not hard to plug the sensor , i'm also a learning noob , i'm using the i2c protocol .so you have to make sure the sensor is on i2c mode ,not uart .
the original tasmota.bin does not have EZO sensors enabled by default due to binary size limitations , you have to recompile tasmota and uncomment the EZO sensors in myuserconfig.h .
this was my fisrt time compiling a bin file ,thanks to DigiBlur's video tutorial, worked on the first try for me using Gitpod.io :


no need for schematic , its very simple to plug i2c devices , just plug SDA and SCL of sensor to the SDA and SCL of microcontroller .(make sure the sensor is on I2C mode)
i'm on a Wemos Mini D1 and the sensor is powered by 5 volts from Wemos ,also works on 3.3v .
to calibrate you can chk this post ,i can now calibrate from Tasmota or Home Assustant thx to @LEDG
you can follow this post : viewtopic.php?f=35&t=6068
i did buy the carrier isolated board ,i have the older version 1 . when i buy the EZOEC i guess i will get the v2 .

good luck

PS.: i attached my compiled tasmota bin , i only enabled EZO-PH on it to test and works amazing . i just ordered a EZO-EC , i will have to recompile again to enable EZO-EC .
Wow i am trying this, any tips/ mandatory options on the tasmota configuration side ?
Bacardi700
LED-Curious
LED-Curious
Reactions:
Posts: 5
Joined: Sat Dec 19, 2020 11:37 am

Baylos wrote:
Sun Jan 03, 2021 6:16 pm
Hi Barcardi,

for the wiring of ESP32 with ADC11x5, I found this youtube video useful: https://www.youtube.com/watch?v=XxUMc1jnI9U&t=122s.

I use DFRobot Probe and the following library helped me get it done. https://github.com/GreenPonik/DFRobot_E ... GREENPONIK.

(I use SEN0169.)

I had ordered DFR0504, which is an isolator interface. Once my EC probe will arrive I can upgrade the ESP32 with an isolator interface for ph and EC.

I do ph calibration once a month.


BR
Thank you Baylos :), this is cost effective and was going through your profile and comments. Did you manage to get this integrated to hassio ?
Baylos
LED-Curious
LED-Curious
Reactions:
Posts: 22
Joined: Sat Nov 07, 2020 11:49 am

Hi,

my current code is below. They're still a working area in it! Especially the code in the field void onConnectionEstablished.

I faced later that Arduino saves the code every time I compile it, that why there some changes from last time to it. What I like to do later on is to move calibration (this is by serial at the moment) to MQTT. EspMQTTClient was used because I had in the past connecting issue with PubSubClient.

The probe SEN0169 is connected with ADS1115 at PIN A1.
The Temperature Sensor is connected to PIN15 of the ESP32.

You can find the core code and library at GitHub under Greenponik. They are the writer of the core code and library.

Code: Select all

#include "EspMQTTClient.h"
#include <Arduino.h>
#include "DFRobot_ESP_PH_WITH_ADC.h"
#include "OneWire.h"
#include "DallasTemperature.h"
#include "Adafruit_ADS1015.h"
#include "EEPROM.h"


DFRobot_ESP_PH_WITH_ADC ph;
Adafruit_ADS1115 ads;

#define ONE_WIRE_BUS 15
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

EspMQTTClient client(
  "MY-Network",
  "The Network Password",
  "xxx.xxx.x.xxx",  // MQTT Broker server ip
  "MQTTClientName",   // Can be omitted if not needed
  "MQTTpassword",   // Can be omitted if not needed
  "Client Name",     // Client name that uniquely identify your device
  1883              // The MQTT port, default to 1883. this line can be omitted
);

void setup()
{
  Serial.begin(115200);
  EEPROM.begin(32);//needed EEPROM.begin to store calibration k in eeprom
  ph.begin();
  sensors.begin();
  ads.setGain(GAIN_ONE);
  ads.begin();

  // Optionnal functionnalities of EspMQTTClient : 
  client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
  client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overrited with enableHTTPWebUpdater("user", "password").
  client.enableLastWillMessage("TestClient/lastwill", "I am going offline");  // You can activate the retain flag by setting the third parameter to true
}

// This function is called once everything is connected (Wifi and MQTT)
// WARNING: YOU MUST IMPLEMENT IT IF YOU USE EspMQTTClient
void onConnectionEstablished()
{
  // Subscribe to "mytopic/test" and display received message to Serial
  client.subscribe("mytopic/test", [](const String & payload) {
    Serial.println(payload);
  });

  // Subscribe to "mytopic/wildcardtest/#" and display received message to Serial
  client.subscribe("mytopic/wildcardtest/#", [](const String & topic, const String & payload) {
    Serial.println("(From wildcard) topic: " + topic + ", payload: " + payload);
  });

  // Publish a message to "mytopic/test"
  client.publish("mytopic/test", "This is a message"); // You can activate the retain flag by setting the third parameter to true
  
  // Execute delayed instructions
  client.executeDelayed(5 * 1000, []() {
    client.publish("mytopic/wildcardtest/test123", "This is a message sent 5 seconds later");
  });
}



float voltage, phValue, temperature = 25;

float readTemperature()
{
  //add your code here to get the temperature from your temperature sensor
  sensors.requestTemperatures();
  return sensors.getTempCByIndex(0);
}

void loop()
{
  static unsigned long timepoint = millis();
  if (millis() - timepoint > 5000U) //time interval: 5s
  {
    timepoint = millis();
    /**
     * index 0 for adc's pin A0
     * index 1 for adc's pin A1
     * index 2 for adc's pin A2
     * index 3 for adc's pin A3
    */
    voltage = ads.readADC_SingleEnded(1) / 10; // read the voltage
    Serial.print("voltage:");
    Serial.println(voltage, 4);
      

    temperature = readTemperature(); // read your temperature sensor to execute temperature compensation
    Serial.print("temperature:");
    Serial.print(temperature, 1);
    Serial.println("^C");

    
    phValue = ph.readPH(voltage, temperature); // convert voltage to pH with temperature compensation
    Serial.print("pH:");
    Serial.println(phValue, 4);
    char phwert[8];
    dtostrf(phValue, 1, 2, phwert);
    char volt[8];
    dtostrf(voltage, 1, 2, volt);      
    char temp[8];
    dtostrf(temperature, 1, 2, temp);
    client.publish("mytopic/volt", volt); // You can activate the retain flag by setting the third parameter to true
    client.publish("mytopic/ph", phwert); // You can activate the retain flag by setting the third parameter to true
    client.publish("mytopic/temp", temp); // You can activate the retain flag by setting the third parameter to true
    
  }
  ph.calibration(voltage, temperature); // calibration process by Serail CMD


  client.loop();
}
Post Reply