pH mètre connected to domoticz



  • Hi,

    I précise that I’m noob in programmation. That’s the raison why I post here. I need help from professional.

    I find this link on the web : https://bestengineeringprojects.com/arduino-ph-meter-using-ph-sensor/?fbclid=IwAR2c-q-eo6_WixzqXvJ7Jquw_AwNhnWwyWAUiZBnr_mNQhV5_bewe9Wg4DI

    I would like to have ph value on my domoticz.

    Do you think I can adapt this code with mysensors ?

    
    //Header declearation Start
    #include <LiquidCrystal_I2C.h> //Library for I2C lcd
    #include <OneWire.h> //One wire library
    #include <DallasTemperature.h> //Library for DS18B20 Sensor
    #include <math.h>// Library for math function 
    //Header Declearation End
    
    //Pin Assignment and declearation Start
    #define ONE_WIRE_BUS 5 //data pin  DQ pin of DS18B20 connected to digital pin D5
    LiquidCrystal_I2C lcd(0x27,20,4);  //set the LCD address to 0x27 for a 20 chars and 4 line display
    const int analogPhPin = A0; //PH module pin P0 connected to analog pin A0
    const int analogTemPin = A2; //PH module pin T1 connected to analog pin A1
    
    OneWire oneWire(ONE_WIRE_BUS); //Ste up one wire instance
    DallasTemperature sensors(&oneWire); //pass one wire reference to DS18B20 library
    
    long phTot, temTot;
    float phAvg, temAvg;
    int x;
    const float C = 21.34; //Constant of straight line (Y = mx + C)
    const float m = -5.70; // Slope of straight line (Y = mx + C)
    //Pin Assignment and declearation end
    
    // start for generate custom character
    byte customChar[] = {
      B00100,
      B00100,
      B11111,
      B00100,
      B00100,
      B00000,
      B11111,
      B00000
    };
    //End for generate custom character
    
    //Setup Function Start 
    void setup() {
      lcd.init(); //initialization the lcd
      lcd.backlight(); 
      sensors.begin(); //Start the DS18B20 Library
      lcd.setCursor(0,0);
      lcd.print("PH and Temperature");
      lcd.setCursor(0,1);
      lcd.print("Meter Using");
      lcd.setCursor(0, 2);
      lcd.print("Arduino");
      delay(3000);
      lcd.clear();
    }
    //Setup Function End
    
    //Main function Start
    void loop() {
      phTot = 0;
      temTot = 0;
      phAvg = 0;
      temAvg = 0;
    
      //taking 10 sample and adding with 10 milli second delay
      for(x=0; x<10 ; x++)
        {
            phTot += analogRead(A0);
            temTot += analogRead(A1);
            delay(10);
        }
        float temAvg = temTot/10;
        float phAvg = temTot/10;
        float temVoltage = temAvg * (5000.0 / 1023.0); //convert sensor reading into milli volt
        float phVoltage =  phAvg * (5.0 / 1023.0); //convert sensor reading into milli volt
    
        sensors.requestTemperatures(); // Send the command to get temperatures
        float Etemp = temVoltage*0.1; //convert milli volt to temperature degree Celsius
        float pHValue = phVoltage*m+C;
        float Wtemp = sensors.getTempCByIndex(0);
        float TempDif = fabs(Etemp-Wtemp); //calculating the absolute value of floating
       // lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Env.Tmp.");
        lcd.setCursor(12,0);
        lcd.print("Sol.Tmp.");
        lcd.setCursor(1,1);
        lcd.print(Etemp);
        lcd.setCursor(6,1);
        lcd.write(B11011111);
        lcd.setCursor(7,1);
        lcd.print("C");
        lcd.setCursor(13,1);
        lcd.print(Wtemp);
        lcd.setCursor(18,1);
        lcd.write(B11011111);
        lcd.setCursor(19,1);
        lcd.print("C");
        lcd.setCursor(0,2);
        lcd.print("PH Value of Solution");
        lcd.setCursor(3,3);
        lcd.print(pHValue);
        lcd.setCursor(9,3);
        lcd.print("PH");
        if (TempDif<= 5)
        {
          lcd.setCursor(11,3);
          lcd.write(customChar);
          lcd.setCursor(14,3);
          lcd.print("0.1PH");
          }
    
        if (TempDif> 5)
        {
          lcd.setCursor(11,3);
          lcd.write(customChar);
          lcd.setCursor(14,3);
          lcd.print("0.2PH");
          }
          delay(1000);
    }
    
    

    I have a gateway mysensors on my pi3b+.

    Thank you.



  • This should be fairly straight forward as long as you just want to send the values to Domoticz and don't need the LC display. MySensors supports a water quality sensor that includes temperature and pH variables.
    You would present S_WATER_QUALITY and send the temperature values as V_TEMP messages and the pH values as V_PH messages.
    See table here: https://www.mysensors.org/download/serial_api_20#variable-types

    I checked the Domoticz release notes and it says this type of meter is included for MySensors. But, I have not tried it.



  • I'm happy to read you that you think that is possible.
    But i'm a noob and I don't understand what you write.
    Does exist a program I can adapt ? Where can I find it ?
    I need some help please. Thank you.



  • There is an example in the MySensors examples.

    https://github.com/mysensors/MySensors/tree/master/examples/PHSensor



  • @Diazovitch69 Converting to mysensors is not difficult for this one reading you want to use - but whether or not domoticz will be happy I don't know as I don't use it.

    Best to go to the 'build' page (see top of this page) and look at the door/window sensor. This is fairly basic and should give you a clue to start experimenting with.

    First add my sensors to the code, then a message construct, then presentation function and then send message in code. Sounds worse that it is. Try it and post your code if it doesn't work.....



  • @nagelc Thank you for your example.
    I think that i have to customize void setup() ?


Log in to reply
 

Suggested Topics

  • 1
  • 10
  • 2
  • 5
  • 2
  • 1

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts