Water level in TANK

Hello Guys,
we install JSN-SR04T in a water tank with 120cm height .
and below is the code but my problem is that the tank now is empty but it gives me 80% when pressing the button

[
    {
        "id": "2a29abc4.be4324",
        "type": "exec",
        "z": "e86239c2.ac7248",
        "command": "sudo python /home/pi/ultrasonic.py",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 400,
        "y": 180,
        "wires": [
            [
                "9971de04.727c6"
            ],
            [],
            []
        ]
    },
    {
        "id": "9971de04.727c6",
        "type": "function",
        "z": "e86239c2.ac7248",
        "name": "",
        "func": "var distance = parseInt(msg.payload);\nvar EmptyDist = 120 - distance;\nmsg.payload = parseInt((EmptyDist/120)*100);\n//msg.payload =(100- parseInt((temp/125)*100));\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 180,
        "wires": [
            [
                "b1617d6f.12bf9"
            ]
        ]
    },
    {
        "id": "b1617d6f.12bf9",
        "type": "ui_gauge",
        "z": "e86239c2.ac7248",
        "name": "",
        "group": "99602dee.56223",
        "order": 1,
        "width": 0,
        "height": 0,
        "gtype": "wave",
        "title": "",
        "label": "%",
        "format": "{{value}}",
        "min": 0,
        "max": "100",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "diff": false,
        "className": "",
        "x": 900,
        "y": 180,
        "wires": []
    },
    {
        "id": "a8b70e6a.6305",
        "type": "ui_button",
        "z": "e86239c2.ac7248",
        "name": "",
        "group": "99602dee.56223",
        "order": 2,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "button",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "topic",
        "topicType": "msg",
        "x": 160,
        "y": 240,
        "wires": [
            [
                "2a29abc4.be4324"
            ]
        ]
    },
    {
        "id": "99602dee.56223",
        "type": "ui_group",
        "name": "Fuel Tank",
        "tab": "94549.2567dab8",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "94549.2567dab8",
        "type": "ui_tab",
        "name": "Fuel Level",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

ultrasonic.py

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

TRIG = 23

ECHO = 24

#print "Distance Measurement In Progress"
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
GPIO.output(TRIG, False)
#print "Waiting For Sensor To Settle"
time.sleep(2)

GPIO.output(TRIG, True)

time.sleep(0.00001)
GPIO.output(TRIG, False)

while GPIO.input(ECHO)==0:
  pulse_start = time.time()
while GPIO.input(ECHO)==1:
  pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration * 17150
distance = round(distance, 2)
print distance
GPIO.cleanup()

When you run ultrasonic.py from the command line it reports 80% ?
If so, you might get better support at the Raspberry Pi forum, without mentioning Node-red.

If not, can you show us what it does report - debug nodes to show output of the exec and function?

no when i run the ultrasonic.py command the value is 23

Maybe there will be something useful here .

the issue was the long distance between the rpi and tank .
do you know how far can we install the sensor from the rpi ?

No idea!

Use an arduino/ESP32 at the tank to read the sensor and MQTT over ethernet/wifi to communicate to Node-red on the Pi.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.