UltraSonic JSN-SR04T water proof kinda works

newplumber

Senior Member
Hi to whoever can read

Lately I ordered a UltraSonic JSN-SR04T from amazon because of faster shipping (because china uses solar canoes) and I wanted to use it to gauge the level of our diesel fuel tank since its water proof etc
and after looking all over the forums here I couldn't comprehend how to make it work I kept getting weird numbers and I used the code like

pulsout c.1,2
pulsin c.2,1,w1

If I didn't add a setfreq and running a picaxe20m2 it should be 4mhz I would see debug w1 = 0
If I added setfreq m8 I would see same w1 = 0
when I put setfreq m16 I would see w1 = 1300 to 2800
same as putting setfreq m32 w1 would be all over the place

After I studied my breadboard and made sure +5 to 5+ grd to grd echo to pin c.2 etc and ate more Tylenol
I tried this code

setfreq m16
high c.1
pause 20
low c.1
pulsin c.2,1,w1

and every stablized and was able to get good readings well they would jump like 2200 to 2203 at a wall
Of course I don't understand what i did but somehow the sensor works till about 8 inches away any closer and
the thing starts acting like my first program with out the smoke
I also blah blah but read somewhere it is not possible to read this because it need 40mhz i think from some googled forum
I tried it to read my fuel level but not stable so I will use a float with a slide pot instead
I know you picaxe wizards could make it read better but I'm just happy it kinda works
OBTW westy and others if u read this lol NO SCHEMATIC!!! cause im a newbie or ahhh umm a OLD NEWBIE!!
but what i am talking about is
http://www.ebay.com/itm/USA-Ultrasonic-Module-Distance-Measuring-Transducer-Sensor-Perfect-Waterproof-/301979143628?hash=item464f5c0dcc:g:ZC0AAOSwvg9XWDQY

your last friend
 

premelec

Senior Member
Glad it's working - re: slide pot and float... these often get tripped up with friction and such - how about just using a pressure transducer - there are lots made for automotive and such and no moving parts [or only slightly moving parts]. Just put the transducer at the tank outlet and calibrate to the density of the fluid you're measuring.
 

cravenhaven

Senior Member
I have been using one of these sensors for quite some time now to measure the water level in our house water tank, and it is surprisingly reliable and accurate though wont read less than about 10cm range. I am using an 08m2 with trig on C.1 and echo on C.2 and set the frequency to 8Mhz which I think is the default anyway. your commands in your first example are correct, so maybe it would be worth posting your complete program and a photo of your hardware setup.
Its possible that your sensor is fried.
 

newplumber

Senior Member
@ premelec Thanks for the idea I will look into that my tank is 60" tall its for one of our ground heaters which of course I am trying to make state of the art since we have been
having problems with relays and etc and of course at -20 F
@ Cravenhaven thanks thats awesome yours is working but I want to read the tank when its completely full and its a rectangle so when it gets closer then 8" it gives bad numbers
of course a person could put a float switch to tell the last 8 to 0 inches but yes I am sorry about no schematic but i quickly made one using ms paint .

I will start a new forum after I get my schematic drawn in miscellaneous projects
called ground heater control board if its ok to do
 

Attachments

Last edited:

cravenhaven

Senior Member
My point was that these units are very stable and seem quite accurate within their limits.
I think the easiest way to get it to read the top few inches is to find a way to set it up higher eg in a tube in the top of the tank. Also, if it were me, I would try with a separate 5v power supply in case the USB supply cant keep up with the peak current and definitely put a cap across the 5v/gnd lines close to the sender.
 

westaust55

Moderator
The 8 inch zone from the transducer is the blind zone. A blind zone is the norm for U/S transducers.
If you delve deeper on that Ebay site for the more detailed description it indicates the blind zone is 250 mm (= 10 inches).


As mentioned you will need to mount that distance above the full level to have accuracy and working in the top part of the tank. A tubular pipe extension like a submarine conning tower would be needed.
The Ultrasonic beam angle is 50 degrees so location will also need to be central to the tank foot print to minimize reflections from the tank walls.
 

newplumber

Senior Member
@ cravenhaven/ westaust55 Thanks for the info and I will need to test more on a different tank because my tank is 5/8 full and the fill cap and old level indicator are close to the edge
so when i tested the U/S to be at stable reading I had to drop it in the tank past the tube welded to it. Now I know with your knowledge I could make it work but I think I will just put
a pressure transducer after the valve at the bottom to make it simple. I could drill a hole in the center of the tank but I love my shop and plan on keeping all 4 walls and the roof as is
I am making a schematic of the first chip to read important sensors to run everything (burner/pump etc the other two picaxe 20m2 chips I will use is just for info
fuel sensor level is not important it is just for convenience so I don't have to drop a stick to measure fuel

@ premelec thanks I order a 0 - 15 psi and will test it and I forget whats its called but it seems simple enough for a plumber to use it
if it doesn't work and our heater runs out of fuel it will only be the 200th time it happened :)
 

premelec

Senior Member
i think the 5psi unit would give you even better resolution if you need it - fuel oil about 80% as dense as water - i think the units are ratiometric - in short the output at any pressure will be proportional to the excitation voltage - these are 3 terminal devices with V+ and V- and output terminal- if you use the same voltage on the PICAXE as the pressure unit the READADC reading should track if the PICAXE voltage varies some. One thing you need to consider is pressure variation from fluid flow - if you are near the tank base and have large fitting that will be negligible... The 100psi unit I use just drives a d'arsonval meter directly with the meter being offset with a zero voltage for my static pressure [I'm along way downhill from my storage tanks]. Should work fine... [Murphy sleeps all winter in ND... ;-0 ]
 

edmunds

Senior Member
Dear all,

Slightly off topic, but about the same device - I have one on the 'solar canoes' coming my way, because I could not find anything better (=price/potential) to play with for learning how measuring water depth would/could work. I'm interested in measuring depth of water of minimum 0.40m and up to max it would work with the sensor submerged under the boat. I have been looking around as much as time allows, but I cannot find any reference to a diy project that would work with submerged sensors. Everybody seems to just measure tank levels with sensor clear and above the liquid and the hundreds of euros worth purpose-built units remain black boxes. Quite possibly there is a good reason for it, but until I can see what the reason is, I cannot give up, can I? :)

What I have gathered (and now off my head, since it was a few weeks back I looked at it) the speed of sound travelling in water is about 4 times slower than that in the atmosphere. For a slow moving boat, it should still be plenty of time for the sound to come back and be received. Faster I would be worried about, but slower should be good, as there will be enough time to process for whatever is doing the processing on that board. If the only thing I have to do is to multiply the result with 4, this simple (and lets be honest - impossibly cheap) unit could be all it takes.

Any thoughts?

Edmunds
 

newplumber

Senior Member
@ premelec again your right should of could of ordered a 5 psi max pressure for 60" tall water 1.5 psi so diesel about 1.2 psi I will try this 0-15 tho and if it isn't giving me some kind of level reading
I will order your 0-5 its funny every time I type something in here with my 2 cents someone here makes even a better simpler way I love it (one day I am going to be right tho I dream)
@ edmunds in water sounds travel way faster then air < but westaust55 or etc will come up with some genius one wired one coded line I bet to help with ur sonar there is really smart poeple here :)
and i am just glad they break it down to simple words so 1st graded level brain like me can understand some of it.
 

premelec

Senior Member
FVRSETUP & ADCCONFIG can get you better resolution on READADC if you need it - I'm not sure where you are going with the unit - alarms? Lights? As I've mentioned you can use a simple d'arsonval meter if level readout is all you want - 5v plug in unit & TL431 to make an offset voltage... + a few resistors... However playing with PICAXEs is more fun... ;-0
 

edmunds

Senior Member
Yeah, I must have been very tired last night writing...

The speed of sound in water is about 4.3 times more than it is in the air. However weird, the conclusion stands, because this should give me about 4.3 times the range the sensor has in atmosphere. Also if the minimum you can detect in atmosphere is 10cm, it should become 10cm x 4.3 = 43cm - spot on. Of course, I have no idea what happens with things like echoes etc...

With the speed of sound in water being 1'484m/s, to measure 0.43m distance the sound would travel 0.86m which would take roughly 570us. Does not sound too bad for some micro on that board to cope with.

Edmunds
 

newplumber

Senior Member
@ premelec I am planning on rebuilding this unit with your knowledge :) except I couldn't understand (the fvrsetup/adcconfig for better resolution) all I know is this (0)
I would use something like
readadc Pressuresensor, b1
b1 = b1 * some kind of this forums genius code to fuel height of tank then code to gallons
I believe it can be done even with the small voltage I will see and I have been wrong
then I would throw it at a 2x16 display of course that would be the easy part (because I borrowed forgets code)
@ edmunds I love the sentence "I have no idea what happens with things like echoes" and I think maybe some one is in this boat i'm in
if you get it figure it out (good idea tho) .. please post a forum of it in simple words so maybe even me can catch on
 

premelec

Senior Member
You need to read up on the commands... the config and setup can change the voltage that is used to measure the READADC value... to start simply just do what you have in straight READADC... if the resolution is good enough for your purpose you are all set. with actual tank and actual readings you may need to go with an empirical table... depending on the tank cross section estimating gallons volume from height [which is what you are measuring] is not simple unless the tank is rectangular or cylinder is standing vertical... there are places to get volume for cylinders on their side - a common situation - I've seen them on the Internet and in old time Chemistry Handbooks... and of course analytic geometry which i am no longer good at... ;-0
 

newplumber

Senior Member
So basically your telling me to read more forums and picaxe manuals which of course i do (so helpful) and found this forum
http://www.picaxeforum.co.uk/showthread.php?24166-Converting-ADC-Value-to-Voltage-Readout-On-a-Picaxe&highlight=fvrsetup
thanks to goeytex I think he made it simple enough (but simple enough for me is always a question)
so to be sure im riding the right train since my pressure sensor should never reach over 2 volts
I could in theory use this program code
Code:
'20m2
FVRSETUP FVR2048   'Set Fixed Voltage Reference = 2.048 Volts 
ADCCONFIG %011     'Set ADC to FVR 
readadc10 pressureSen,w1 ' according to goeytex ".002v per step" which is cool for my setup
      w1 = w1  * 6 / 10          'Scale/MAP 
      bintoascii w5,b0,b0,b1,b2,b3
      sertxd (b0,b1,".",b2,b3," Volts DC",cr,lf)  'again I wont use this line but would have b0 b1 etc values to play with
and make a test pipe thats 4"diameter 60"tall vertical with pressure sensor at bottom and measure bottom pressure like 1" from bottom to full top
yes the fuel wont be exact because temp/space but exact for me :)
I think my tank is 24" wide 16" deep and 60" tall rectangle
its easy to figure the rest 231 cube inches to a gallon
well so I think, but if I am wrong (nah I am never wrong :) jk)
 
Last edited:

newplumber

Senior Member
Okay I have my pressure sensor 0-15
and read it with volt meter just by blowing into it ( almost blew a brain cell)
and the volts are .54 to .80 volts
but when I hook it to the picaxe 20m2
it reads nothing on volts with this code even when my face expands twice the size as i blow into the sensor
Code:
'20m2
FVRSETUP FVR2048   'Set Fixed Voltage Reference = 2.048 Volts 
ADCCONFIG %011     'Set ADC to FVR 

START:
readadc10 c.1,w1 ' 
      w1 = w1  * 6 / 10          'Scale/MAP 
      
      'debug 
      'pause 500
      bintoascii w5,b0,b0,b1,b2,b3
      sertxd (b0,b1,".",b2,b3," Volts DC",cr,lf)  
      pause 100
GOTO start
maybe I am doing something wrong (like always)
well before anyone will/or want to comment
I want to thank you and everyone for helping me especially you pros that keep it simple kinda
it means alot maybe some century later I can/will do the same
I am going to order 0-5 psi or maybe a 0- 2.5 psi hoping to do it right the first time :) like premelec does
 

Attachments

newplumber

Senior Member
ohh just cuase i thought it was cool JK
lol my total mistake very simple but glad you caught it thanks (i'm light headed)
now it works awesome time for some testing (if I wasn't a plumber and some kind of upper smart person I would be embarrassed)
I will let you or anyone that cares of the results of my testing which should be soon
I'm still going to try a 0-5 like premelec suggested but for now sticking to the 0-15
 

newplumber

Senior Member
thanks premelec I have a few 0-5 psi ordered from USA seller so hopefully they will be sooner then
china does and before 4th of july

I added a picture of my million dollar test kit and the results are cool
as you might see I just used a breadboard with a digital display + PTS
the pressure sensor didn't start adding voltage till water ( i will use diesel when 0-5 is here) level reached 23.5" above PTS
I marked every spot in increments of .10 of volt till I reached my maximum height of 60 inches
at the start of the test the voltage was 1.25/1.26
when pipe was full the voltage was 2.48/2.46
I was really impressed how almost every 4" up the pipe it increased .10 volt higher
Now I am really hoping the 0-5 pressure transducer will have a lower start sensing height
because after 23.5 it was pretty accurate.
I will put here the test results of the 0-5 sensor when it is here
 

Attachments

premelec

Senior Member
That's not right - at least with the unit I have... there's an offset at 0 psi but then linear increase in output afterward... did the seller of your unit show a volts vs pressure graph? Does it all of a sudden jump at 23" to a large proportionate voltage?

i just looked at the ebay place I mentioned above and it appears it may have a dead zone as it states correct v to psi after a certain amount of pressure... I guess you could put a drop leg on the tank - if there's room - to raise the initial pressure.... I'll see if I can find the unit I got years ago still on ebay.. it cost $25.

Can't find the seller I bought from - did notice that some units go from vacuum to pressure so if there was a dead zone it would be in the vacuum end... ;-0 Now I'm wondering if my unit reads like yours - but since I'm reading a 6' change in a 70psi head it doesn't show up - I just recalled seeing a graph of linear increase with pressure with .5v offset at 0psi...
 
Last edited:

newplumber

Senior Member
"did the seller of your unit show a volts vs pressure graph?"

no it was from ebay this item and it doesn't say anything about dead zone that i can see just .5v at 0 psi
http://www.ebay.com/itm/Pressure-transducer-or-sender-stainless-steel-for-oil-fuel-air-water-Multichoice-/391715952051?var=&hash=item5b341715b3:m:mLpvgLGWQbsDfw2VbyJMPag

if its true what you are saying at 0 psi that would be great i'll test my 0-5 if they show up soon
I thought about that too good idea tho on the drop leg but it would be dragging the ground no warranty for that
When I tested it with a meter with out chip it took a little pressure to read .05 volts to .06 volts
Also it says red wire is +5 black wire is ground and green is sensor
when i got it I had a black wire /purple wire/green wire
so I was a "already confused confused circuit installer" and took a chance purple was +5v and it worked
 
Last edited:

newplumber

Senior Member
Hi premelec /everyone

My 0-5 psi PT arrived and the test results were little different
@water level 60" above PT my adc reading was 4.41 on average it jumps a little +/- .08 (example 4.38 - 4.46)
@water level 42 1/2 " above PT adc reading was 2.82
@lowest water level reading before exact 0 was 10.5" above PT
My code for reading the PT is here and showing only the voltage \/
Code:
' this program is for testing voltage with a 0-5 psi pressure tranducer / 7seg display
'input c.1
input c.2  ' PT input

symbol sclk     = b.1 '&#8216; clock for tofd-5465
symbol sdata    = b.0 '&#8216; data for tofd-5465
symbol cs       = b.2 '&#8216; enable for tofd-5465
pause 500

symbol dist         = w0
'                     b1
symbol dig1         = b2
symbol dig2         = b3  'w1
symbol dig3         = b4
symbol dig4         = b5  'w2
symbol con1         = b6
symbol con2         = b7  'w3
symbol con3         = b8
symbol con4         = b9  'w4
symbol counter      = b10 
                   '= b11
symbol mask         = w6 'b12-b13 bit masking variable
                 '  = b13
symbol var_out      = w7 'b14-b15&#8216; data
                   '= b15
symbol adcvolt                    

FVRSETUP FVR2048   'Set Fixed Voltage Reference = 2.048 Volts 
ADCCONFIG %011     'Set ADC to FVR 



symbol MSBvalue = 128 ' LSBvalue  
symbol bits = 8 ' number of bits


 
START:
gosub clearr  ' I am using a 7seg display  TOFD-5465ggh  bought off ebay while ago 
readadc10 c.2,adcvolt ' 
      adcvolt = adcvolt  * 6 / 10          'Scale/MAP 

      bintoascii adcvolt,dig4,con4,con3,con2,con1
 
con1 = con1 - 48
con2 = con2 - 48
con3 = con3 - 48

dig4 = 119 ' makes letter A on display 
LOOKUP  con3, (63, 6, 91, 79,102, 109, 125,7,127,111),dig3  
LOOKUP  con2, (63, 6, 91, 79,102, 109, 125,7,127,111),dig2  
LOOKUP  con1, (63, 6, 91, 79,102, 109, 125,7,127,111),dig1
     low cs
        var_out = $C0      'digit 1       
      gosub shiftout1
        var_out = dig4  'displays num 1         
      gosub shiftout1
        var_out = $C2      'digit 2       
      gosub shiftout1
        var_out = dig3    'displays num 2         
      gosub shiftout1
        var_out = $C4      'digit 3       
      gosub shiftout1
        var_out = dig2   'displays num 3         
      gosub shiftout1
        var_out = $C6      'digit 4       
      gosub shiftout1
        var_out = dig1      'displays num 4         
      gosub shiftout1
    high cs
GOTO START  


SHIFTOUT1:
for counter = 1 to bits '&#8216; number of bits
mask = var_out & 1  '&#8216; mask LSB
low sdata '&#8216; data low
if mask = 0 then skipLSB
high sdata '&#8216; data high
skipLSB: pulsout sclk,1 '&#8216; pulse clock for 10us
var_out = var_out/2 '&#8216; shift variable right for LSB
next counter
RETURN

CLEARR:
     low cs
       pause 50
     var_out =  $8d ' brightness $88 - $8f         
    gosub shiftout1 
     var_out =  $c0         
    gosub shiftout1 
     var_out =  $00         
    gosub shiftout1 
  high cs
RETURN
So after measuring the voltage from different heights I came up with a formula for each inch about of water level
but of course I have to start at 10.5 " above the PT
If I divide .0887 into my average voltage then I see my height into inches plus 10.5
the =<10.5" according to myself is a dead zone which is perfect because if I have only =< 10.5 in my fuel tank
someone gets fired unless its me :) or asap add fuel
maybe this don't make sense but im trying to make it clear I will add my code later to show fuel height in tank / inches or gallons
if i can code it right (challenge #504030)
 

premelec

Senior Member
I'm not sure you understand that the 0psi reading is about .5 volts and then adding pressure from there should increase linearly. At least that's how mine works - you can test by putting multimeter on output and then blowing into it - it should start increasing the reading from zero value with even small pressure on it. The zero value should be subtracted from the READADC10 reading BEFORE you you further manipulate that reading value to scale it and such. I'm not sure what your dead zone is about unless it's the zero pressure offset.

Code:
readadc10 c.2,adcvolt ' 
     
ADCVOLT = ADCVOLT - ZEROVOLT ; determine what zerovolt is and define this symbol

 adcvolt = adcvolt  * 6 / 10          'Scale/MAP
 
Last edited:

newplumber

Senior Member
@ premelec yes you are right I am not understanding alot but i do understand at 0psi my meter on dc volts should be .5
but i think both 0-5 psi are bad I don't have the one i tested with but the one I do have here doesn't read anything on my meter at all
I tried 2 different meters and shows 4.99 volts to red and black is to ground and on the green wire it shows 0 even if I switch to MV on the meter
I even soldered all the wires to make sure I don't have some funny ends and tested all wires for resistance which all read 0 but now I am curious to see why my
other one would read 0 psi then go up now that you mentioned it when it should read .5 my luck is i have two bad sensors which would be normal for me :)
I will order 2 more (hopefully) good ones and if you can remember where you got yours it would be a good help
thanks
 

premelec

Senior Member
Is it possible you are buying on/off sorts of units [such as are used to turn on your oil pressure light on dashboard] rather than continuous pressure reading devices? Please give ref to your source - it's unlikely that they are all defective...

Looking on ebay it seems "pressure switch" is the on/off type and "pressure transducer or sensor" the other type... not sure about the 3 wires - in the old days on/off was just 2 wires...

Looking around more on ebay I see some spec'd as 4-20ma OR 0-5v etc and some spec'd as linear out but with data that indicates an offset etc - so there is some unclarity in these lower priced units. BTW 4-20ma means current and is used for remote reading so that the lead resistance doesn't give you problems as the current is regulated...
 
Last edited:

newplumber

Senior Member
I don't think so I contacted the seller asking for more information which im still waiting on but I bought this unit
http://www.ebay.com/itm/191568998190?_trksid=p2057872.m2749.l2649&var=490804889800&ssPageName=STRK:MEBIDX:IT
it says linear and not much more information but both of them will not show .5 volts at 0 psi
And if you follow me around for a hour or two ..lol you will see yes it is possible for me that all are defective.
Anyway I will order some better ones with data sheets etc I will let you know what i found
thanks again tho
 

newplumber

Senior Member
I just ordered a Barksdale 423T4-25 info can be found here
http://www.barksdale.com/en/products/section/pressure-switches/transducer/
now you have way more experience in PTs and I have more then enough experience in BRPTs (bad reading pressure tranducers)
when it appears I will test it with 12 volt on the excitation voltage which hopefully 3rd time the charm it will work awesome
and all my problems will go away and the trees start growing here :)
I will test it again and show my right/wrong results
 

newplumber

Senior Member
@ premelec Okay my Barksdale 423T4-25 arrived and of course since I bought it used off ebay ...it came with out a wire connector.
so after contacting barksdale and found out what (four) pins are what I made my own connector
Now after I tested it .. it all makes sense what you were telling me with no black out
I was very impressed by seeing it read almost by yawning into it.
Thanks premelec/others for all the help/info
the other ones I bought are useless for using for my application.
Only thing I need to change is grab 12 volt power for the exciter/+ 9 -30vdc wire probably use a pc power supply
I have alot of them (pc power supplys) because people around here don't want older computers and you can buy them for $.50 cents each at auctions.

@ myself/everyone If you buy pressure transducers off ebay (the cheap ones/no namers) they just might work
and most of the sellers don't even know what a PT is and you will/could get 0 response of info (well maybe its just me)
.your most expensive plumber/least experienced picaxe friend
 

premelec

Senior Member
Great that the Barksdale unit works for you and still mysterious why the other units which are supposed to work pretty much like the Barksdale [though less fancy casing etc] DIDN'T work! The $25 i bought years ago from Ebay is still working here and I use a 5vdc plug in phone charger supply to run it. On to the next project! ;-0
 
Top