Help with logic level shifter

Hi, I have a hydrostatic pressure sensor that outputs 0 - 5v, im using the ADC on a wt32-eth01 esp32.

I have wiring the logic shifter as follows,

Esp32 | sensor
3v3 >>>> LV
5v >>>> HV
L1 >>>> GPIO15
H1 >>>> Sensor Signal

Yes, still my sensor only reads static 1v.

I have measured the high side of the sensor, it’s reading about 3.4 volts,

Any ideas what I’m doing wrong here?

sensor:
  - platform: adc
    pin: GPIO15
    name: "Tank Level"
    update_interval: 60s

image

Im unaware of any logic shifters that will pass through variable voltages. They convert 3.3v to 5v and 5v to 3.3v.

That sensor outputs a voltage from 0-5v based on pressure so, only being able to read 5v or 3.3v isnt going to be very useful.

You need a voltage divider instead and use that to reduce the 5v to 3.3. Then you can measure the entire range of voltages instead of only 2 voltage levels.

https://learn.sparkfun.com/tutorials/voltage-dividers/all

Oh ok, I must have misunderstood how logic level shifters work, Have never actually used them before to be honest.

So, basically they just convert a static 5v to 3v3?

Ok, I will explore with a Voltage Divider.

Thanks

Without knowing exactly which one your specifically using there is a slim possibility Im wrong but, all the ones im aware of are a static voltage back and forth.

Which one are you using BTW?

Luckily for you voltage shifters are something youll need from time to time and they’re good to have around in your spare parts. Considering they’re pretty cheap I wouldn’t suggest returning them, instead keep them because, you’ll need them elsewhere sooner or later.

You can find these calculators all over the internet but, they are very handy. Just input starting voltage(5.0v) and 2 resistor values and it will show you the output voltage.

I did one for you as an example. Here if R1 -100ohm and R2 - 200ohm it will then turn 5v into 3.333v.

A couple tips ill mention is to pay attention to whether your using ohm, kilohms, or megaohms because it matters big time and secondly, when installing R1 and R2 where 5v would go to R1 first then R2. If you mix those up R1-R2 it will have a completely different voltage output and could potentially damage your esp32 so, be mindful of keeping them in order and dont ask me how I came to learn that little detail…:sleepy:

Thanks, I am using this one.

So, this is good information to know and i was unaware of this feature that this logic shifter has but, its also capable of doing 1.8v and 2.8v in addition to the 3.3v and 5v shifting. That still isnt all that helpful in your situation unless you only want 4 possible sensor levels.

You can find this information by clicking on “description” or often labeled “specifications” and pretty much every component online and from any website will have this detailed information that explains what exactly the device does and its limitations just like this.

Ah ok thanks, nah I want more values then that Ill go down the Voltage Divider route.

On the SparkFun post you linked me in your first post, it states

1700ohm and 3300 ohm for 3v3.

image

Or you could use R1 - 1000ohm and R2 - 2000ohm…

There’s more than one way to skin a cat, ya dig?

Resistors are also used for limiting how much current can pass through as well as reducing voltage so, there may be a situation where you need a 3.3v and need to limit the maximum current(mAh) then this is where it would matter more which values you use because your needing specific voltage and current now. For what your doing here with this sensor, it shouldn’t matter which values you use.

As far as they are not too low or high.
I wouldn’t go below 100, not above 100k.
100 would heat up that resistor a lot and 1M wouldn’t necessary work or at least would have very long sampling time.
1k and 2k would work well.

Another option to tackle this is to use for example ADS 1115 and measure voltage there.

The ESP32 ADC analog input pins are 3.3v tolerant with a peak input voltage of 3.3v.
Here is another website for calculating resistor values for a simple voltage divider. The article is for Arduino but applies to any analog input- ESP, Raspberry, Arduino. The principle is the same for all of them

Voltage Divider calculator

In their example, Vin is the highest voltage you will get from the sensor and Vout should be 3.0V - slightly less than the maximum that the ESP can tolerate. This is because you will not easily find exactly the resistance values you need and at the tolerance that exact values would require. You will correct for any offset in your code.

Find any resistor in your junk box that is 4k7 to 47k- it is not at all critical. Calculate R2 and select the next lower standard value.

Do we need websites to calculate voltage divider? 3.3/5= 2/3 (0.66), so divider has to be 1:2. For example 1k:2k or 5k:10k or 10k:20k and so on…

Why to add an extra component if you have full ADC voltage range in your hands.

Why use a 4 channel ADC for a single analog input and essentially waste the ADS1115?

How many voltage divider calculator websites does someone need? The one i gave them has a calculator, an identical example to yours and explains it all in detail so, whats the point in repeating all the things already mentioned?

So, 1k amd 2k would work also?

image

Does the output say 3.3v? There’s your answer.

FYI. You know you can also input starting voltage, desired voltage output, and then input a value for either R1 or R2 and then hit Calculate. It will calculate the value for the second resistor instead of doing numerous trial and error inputting R1,R2 trying to get the desired output.

3.333, i take it thats close enough

Are there any downsides to doing it like this? To using a Voltage Divider, say istrad of measuring the mW voltage if my sensor outputs 20 - 200mW

I only briefly looked at that sensor online and it looked like you could choose from multiple output selections and they had one that output a variable voltage and another that used variable current…

Seeing how you didnt provide the link for the one you purchased, everyone was assuming you atleast knew how your sensor operated and you were asking about voltage… This is why its so important to provide actual details/facts instead of typing a subjective story explaining the problem. If you leave holes all over in your information then people are going to fill them with facts that may or may not be accurate and the answers to your question will reflect the quality of data you provided.

No I purchased the 0-5 v version. Nothing is incorrect with the information provided :slight_smile:

This one I saw for example, it will do either variable voltage or variable current. Now, whether you set them up the same way or different based on which output you want, im not sure. Thats the type of information that should come in your product manual or its listed where you bought it from. Idk if yours is only voltage or can do voltage and current but, thats a detail hopefully you know already.

https://www.amazon.com/LUISAS-Transmitter-Pressure-hydrostatic-Converter/dp/B0CQFY9GPL/ref=mp_s_a_1_1?crid=K3F1Q066OCMJ&dib=eyJ2IjoiMSJ9.dGcrQG0aVbDKCbaSDnKsDz92wfRp1k6CDVBtd3QMzoPSiQKc-ngXVyLCkNFWNJjkLv_Cgj7PeqL8gcutB42f7gxRGo73YX73ORIyarhb09S8cBiYVMWFP7uMnzegQgRHE--wRosIXrO-EAiN1VDyYCPnTAlXsivnVoQz0zD3_yFAb3OWvJiXaJKTfSgBYWDfCadLezg1R3Z8UUUWW6zc6w.nlj7ZvDEzb2EVc4yxiJB9xWM80ldFVB38uBnfusjhek&dib_tag=se&keywords=hydrostatic+liquid+level+sensor+0-5v&qid=1724620585&sprefix=hydrostatic+liquid+level+sensor+0-5v%2Caps%2C171&sr=8-1

If your model doesn’t have other output, jus go with 1k:2k, no need to get mad with all of this.
If you have, there is even i2c. Not that it changes anything, after all analog might be the most simple setup anyway.

1 Like