Cheaper alternative to Atlas Scientific?

Home Assistant automation projects, questions, etc. go here.
Baylos
LED-Curious
LED-Curious
Reactions:
Posts: 22
Joined: Sat Nov 07, 2020 11:49 am

Hello,

I set up an ESP32 with the ADS1115, PH, and Temperature probe. Works find and calibration too. I used the greenponik code on Github.

Code: Select all

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

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

DFRobot_ESP_PH_WITH_ADC ph;
Adafruit_ADS1115 ads;

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 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();
}

void loop()
{
	static unsigned long timepoint = millis();
	if (millis() - timepoint > 1000U) //time interval: 1s
	{
		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);
	}
	ph.calibration(voltage, temperature); // calibration process by Serail CMD
}

Now I need to understand how to implement MQTT to it. Does anyone has a idea?


Best Regards
Shimbob
LED Wizard
LED Wizard
Reactions:
Posts: 642
Joined: Mon Nov 27, 2017 11:29 pm

For MQTT, you can pick apart my sketch in this post.
Baylos
LED-Curious
LED-Curious
Reactions:
Posts: 22
Joined: Sat Nov 07, 2020 11:49 am

Thanks a lot!

I was experimenting with some code, so step by step.

I will try next weekend.


Best Regards

B
Ebdirtrider
LED-Curious
LED-Curious
Reactions:
Posts: 2
Joined: Fri Dec 04, 2020 2:15 am

Did you set up in HA? If so how did you set up if you don't mind sharing.
Baylos
LED-Curious
LED-Curious
Reactions:
Posts: 22
Joined: Sat Nov 07, 2020 11:49 am

Hi,

Thanks for the post above. This was helping me to understand the System interactions.

I was playing last week a bit around. I found "mysensor" and this was very interesting to me. But not was I searching for.

My last programming was BASIC. After getting some understanding of C I change the code. MQTT publishing looks to be done now. It would be easier if the unit is behind the value, I have to check it.

Now I have to understand how to integrate it to HomeServer.

The Code is (at the moment) as follow:

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(
  "YOUR SSID",
  "YOUR PASSWORT",
  "IP of Broker",  // MQTT Broker server ip
  "MQTTUSER",   // Can be omitted if not needed
  "MQTTpassword",   // Can be omitted if not needed
  "DEVICE",     // 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: 1s
  {
    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/test", volt); // You can activate the retain flag by setting the third parameter to true
    client.publish("mytopic/test", phwert); // You can activate the retain flag by setting the third parameter to true
    client.publish("mytopic/test", temp); // You can activate the retain flag by setting the third parameter to true
    //loop delay ms
const int interval = 500; 
  }
  ph.calibration(voltage, temperature); // calibration process by Serail CMD


  client.loop();
}
jaysal
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 75
Joined: Sat May 30, 2020 7:49 am

I am looking into this exact implementation.

Could you go over how you connected the ADC to the ESP32 as well as the Dallas Temp Probe?

EDIT:
Nevermind I just found your post here which is helpful. viewtopic.php?f=35&t=6066
Baylos
LED-Curious
LED-Curious
Reactions:
Posts: 22
Joined: Sat Nov 07, 2020 11:49 am

Hi,

I try to create a picture for it. My wiring is shown there.
Unbenannt - Kopie.JPG

BR
jaysal
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 75
Joined: Sat May 30, 2020 7:49 am

Baylos wrote:
Wed Jan 06, 2021 5:30 pm
Hi,

I try to create a picture for it. My wiring is shown there.

Unbenannt - Kopie.JPG


BR
Awesome! Thanks. Any plans on adding the DFRobot TDS Meter, I am trying to find out if the Code will work on ESP32 or only Arduino Uno.

https://github.com/DFRobot/GravityTDS/b ... avityTDS.h
Baylos
LED-Curious
LED-Curious
Reactions:
Posts: 22
Joined: Sat Nov 07, 2020 11:49 am

Hi,

I ordered an EC probe too, but there is a difference. PH probe SEN0169 is industrial standard and EC not. There are no EC probes with industrial standard from DFRobot available.


BR
saitama
LED-Curious
LED-Curious
Reactions:
Posts: 19
Joined: Fri May 29, 2020 6:02 pm

jaysal wrote:
Thu Oct 01, 2020 4:00 am
Hey saitama,
How is the PH Meter holding up, I just read on their website that a user has been using this in their aquarium 24/7 for over a year now with great results.

Can you give us an update please?

Thanks
Sorry for the late reply. PH meter still going strong. My only complaint is that it doesn't compensate for temp, but I'm fine with it as I'm able to monitor PH using a regular pen to make sure I'm always within range. It's not perfect, but it does the job and it has stayed in calibration for quite some time as well.
Post Reply