Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Water pressure sensor

Water pressure sensor

Scheduled Pinned Locked Moved My Project
8 Posts 4 Posters 4.4k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lekeb
    wrote on last edited by
    #1

    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

    mfalkviddM 1 Reply Last reply
    0
    • L lekeb

      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

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lekeb
        wrote on last edited by
        #3

        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```
        mfalkviddM 1 Reply Last reply
        0
        • L lekeb

          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```
          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by mfalkvidd
          #4

          @lekeb looks like you've forgotten analogRead :ghost:

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lekeb
            wrote on last edited by
            #5

            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?

            M 1 Reply Last reply
            0
            • L lekeb

              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?

              M Offline
              M Offline
              mickecarlsson
              wrote on last edited by
              #6

              Change

              lecture_adc = BAR_SENSOR_ANALOG_PIN;
              

              To

              lecture_adc = analogRead(BAR_SENSOR_ANALOG_PIN);
              
              1 Reply Last reply
              1
              • L Offline
                L Offline
                lekeb
                wrote on last edited by
                #7

                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);
                }
                
                D 1 Reply Last reply
                1
                • L lekeb

                  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);
                  }
                  
                  D Offline
                  D Offline
                  dpancer
                  wrote on last edited by
                  #8

                  @lekeb

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

                  1 Reply Last reply
                  0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  19

                  Online

                  12.0k

                  Users

                  11.2k

                  Topics

                  113.4k

                  Posts


                  Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • MySensors
                  • OpenHardware.io
                  • Categories
                  • Recent
                  • Tags
                  • Popular