I have a concrete, in-ground water tank for my domestic water storage. There's no easy way to monitor the water level so I have started to put together an ultrasonic depth sensor with the intention of viewing a graph of the depth across a couple of months, measured once each day. I plan to drill through the top of the tank and mo9un t the sensor vertically pointing straight down at the water surface. Someone has previously done this using an Arduino but I wanted to use the ESP8266.
I have the ESP8266 powered from my laptop (usb) but communicating across wifi - webrepl. I have jumper wires from the ESP8266 to a breadboard and from there to the four pins of the JSN-SR04T-2.0 board. The sensor is pointing at a plaster wall 112cm away.
With all the hardware static and as few connections as possible I get readings from 77cm to 108cm.
I'm hoping for insights about possible causes for the inaccuracy. My code is pretty primitive as I'm very green
Code: Select all
import machine #Nominate a trigger pin on ESP8266 and declare it as an output pin trigger = machine.Pin((14), machine.Pin.OUT) #Nominate an echo pin and declare it as an input pin echo = machine.Pin((12), machine.Pin.IN) #Set the trigger high for 10 microseconds import utime trigger.value(0) utime.sleep_us(10) trigger.value(1) #Set a timer to monitor the echo pin for a couple of seconds pulse = machine.time_pulse_us(echo,1) #Return the duration of the echo pulse print ('Echo duration:', pulse) #Calculate the distance to the surface based on the speed of sound. distance = (pulse/1000000)*34000/2 print('Distance:', distance,'cm') #Write the distance to the surface to a file water_level = open("water_level.txt","a") print('Distance:', distance,'cm', file = water_level) water_level.close()
Thanks for any help you can offer.