Water pressure sensor



  • Hello,

    I need your help to write my first "My sensor" sketch.
    I use this 5V sensor (link below) and pro-mini arduino to mesure water pressure inside my home water pipe.
    https://fr.aliexpress.com/item/0-0-5-Mpa-Water-Gas-Pressure-Sensor-G1-4-DC-5V-Air-Compressor-Pressure-Transmitter/32660132491.html?spm=a2g0s.9042311.0.0.KxZ6lv

    I used this simple sketch to read water pressure in Bar. I can read a pressure around 2.20 Bar

    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
    int lecture_adc;
    float pression;
    
    lecture_adc = analogRead(A0);
    Serial.print("Sensor Value: ");
    Serial.println(lecture_adc);
    pression = (((lecture_adc*5/1024.0)-0.52)/1.7); //read pressure in Bar, remove 1.7 to read Voltage, divide 0.17 to read in  MPa        
    Serial.print("Pression: ");
    Serial.println(pression);
    
    delay(1000);
    

    Now, I tried to monitore my water pressure with my sensor and domoticz, that's why I wrote this sketch

    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    
    #define MY_NODE_ID 7
    
    #include <MySensors.h>
    
    #define BARO_CHILD 0
    #define BAR_SENSOR_ANALOG_PIN 0
    
    unsigned long SLEEP_TIME = 60000;
    
    MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
    void setup(){
      
    }
    
    void presentation() {
      sendSketchInfo("pressure Sensor", "1.0");
      present(BARO_CHILD, S_BARO);
    }
    
    void loop() {
      int lecture_adc;
      float pression;
    
      lecture_adc = BAR_SENSOR_ANALOG_PIN;
      pression = ((lecture_adc*5/1024.0)-0.52)/1.7;
      Serial.println(pression);        
      send(pressureMsg.set(pression, 2));
            
      sleep(SLEEP_TIME);
    }
    

    But with this code, my node send as value -0.21 (check in DEBUG). I don't understand why.
    Could you help me to understand what is wrong?

    Thanks


  • Mod

    Welcome to the MySensors community @lekeb Congratulations on your first node 🙂

    Do you mean that

    Serial.println(pression); 
    

    prints the correct value, but

    send(pressureMsg.set(pression, 2));
    

    results in .0.21?

    Could you post the full debug output?



  • Thanks for your answer.

    Exactly, I don't get the same value

    Here my full debug

    0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
    3 TSM:INIT
    4 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    12 TSM:INIT:STATID=7
    14 TSF:SID:OK,ID=7
    16 TSM:FPAR
    35 TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2042 !TSM:FPAR:NO REPLY
    2044 TSM:FPAR
    2063 TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2071 TSF:MSG:READ,0-0-7,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    2076 TSF:MSG:FPAR OK,ID=0,D=1
    4071 TSM:FPAR:OK
    4072 TSM:ID
    4073 TSM:ID:OK
    4075 TSM:UPL
    4077 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    4083 TSF:MSG:READ,0-0-7,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    4088 TSF:MSG:PONG RECV,HP=1
    4091 TSM:UPL:OK
    4092 TSM:READY:ID=7,PAR=0,DIS=1
    4097 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    4104 TSF:MSG:READ,0-0-7,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    4110 TSF:MSG:SEND,7-7-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
    4118 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    4128 TSF:MSG:READ,0-0-7,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    4134 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=11,pt=0,l=15,sg=0,ft=0,st=OK:pressure Sensor
    4144 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
    4151 TSF:MSG:SEND,7-7-0-0,s=0,c=0,t=8,pt=0,l=0,sg=0,ft=0,st=OK:
    4157 MCO:REG:REQ
    4160 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    4166 TSF:MSG:READ,0-0-7,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    4171 MCO:PIM:NODE REG=1
    4173 MCO:BGN:STP
    4175 MCO:BGN:INIT OK,TSP=1
    -0.29
    4178 TSF:MSG:SEND,7-7-0-0,s=0,c=1,t=4,pt=7,l=5,sg=0,ft=0,st=OK:-0.29
    4186 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255
    4191 MCO:SLP:TPD
    4192 MCO:SLP:WUP=-1
    -0.29
    4196 TSF:MSG:SEND,7-7-0-0,s=0,c=1,t=4,pt=7,l=5,sg=0,ft=0,st=OK:-0.29
    4202 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255
    4207 MCO:SLP:TPD```

  • Mod

    @lekeb looks like you've forgotten analogRead 👻



  • Makes sense! My value didn't change over time
    But what means this ligne

    #define BAR_SENSOR_ANALOG_PIN 0
    

    I guessed it was to declare AnalogRead on pin 0?



  • Change

    lecture_adc = BAR_SENSOR_ANALOG_PIN;
    

    To

    lecture_adc = analogRead(BAR_SENSOR_ANALOG_PIN);
    


  • Thanks a lot, It works!!!

    Here my code updated

    
    // Enable debug prints to serial monitor
    //#define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    
    //#define MY_NODE_ID 7
    
    #include <MySensors.h>
    
    #define BARO_CHILD 0
    #define BAR_SENSOR_ANALOG_PIN 0
    
    unsigned long SLEEP_TIME = 60000;
    
    MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
    void setup(){
      
    }
    
    void presentation() {
      sendSketchInfo("pressure Sensor", "1.0");
      present(BARO_CHILD, S_BARO);
    }
    
    void loop() {
        
      int lecture_adc = analogRead(BAR_SENSOR_ANALOG_PIN);
      float pression = ((lecture_adc*5/1024.0)-0.50)/1.7;
      Serial.println(pression);        
      send(pressureMsg.set(pression, 2));
            
      sleep(SLEEP_TIME);
    }
    


  • @lekeb

    How is your pressure sensor working out? are you getting accurate reading? I'm looking to hook up something similar to vera


Log in to reply
 

Suggested Topics

  • 8
  • 29
  • 1
  • 2
  • 2
  • 2

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts