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.KxZ6lvI 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
-
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.KxZ6lvI 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
-
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``` -
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``` -
Makes sense! My value didn't change over time
But what means this ligne#define BAR_SENSOR_ANALOG_PIN 0I 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); } -
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); }
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