Non linear scale node?

Hi all,
I have a sensor that varies it's resistance in response to position. It varies between 0 ohms and 190 ohms in a reasonably straight curve, however the device I'm using to read the resistance is using a voltage divider to derive a voltage from the moving resistance.


This part of the project is working well (Note the Wemos has an internal divider hense the multiplication to get a variance of 0-3.3v on the result.

The problem I need some help with is the resulting reading.


The bottom graph above shows the problem. The voltage read curve is not linear and as such I'm having problems mapping the output to a smooth 0-100.
I've tried playing with the scale node to map the voltage read to a 1-100 scale but the bulk of the movement accounts for a very small part of the resulting display.

The device is a tank level sensor, so mapping the output to a 0% to 100% reading is the goal.

I'm guessing applying an exponential curve would resolve this, but I'm at a loss as to how to implement.

Any ideas greatly appreciated.
Thanks

Do you have a formula that describes the position against voltage curve? Is it just
V = Rs/(Rs + R) * 3.3?

Do you realise you will be drawing 330mA when Rs is 0? That is over 1 Watt! I hope that R is fairly beefy.

1 Like

Indeed.
I think I need another way to measure the resistance of the sensor. Voltage division is clearly not going to be the right solution. Not when it's 0-190 ohms....

If you used 200 ohms then it would probably be ok. It would only use half the range but that wouldn't matter, provided the accuracy was ok. I don't think you are looking for ultimate precision are you? That would be 16mA.

No, precision not really required, it's a tank level sensor so rough volume is all that's required.
The D1 has a built in voltage divider as the ADC is only 0-1vdc, but will happily accept 3.3v so there is that to add into the mix.
I'll try changing the fixed resistor to 200ohms see how we get on.
Thanks

If your 5V supply really is 5V and pretty smooth - then you could use a pull up to that instead of the 3.3V supply - I think 100 Ohms would actually give you 3.3V at the pin when the other is 190... but be careful :slight_smile:

1 Like

I think there is potentially a danger with pulling up to 5V. If the sensor became disconnected then the pin would be pulled up to 5V. I haven't been able to find an absolute max rating for the input so don't know whether that might damage the device or not.

If that seems to be working then you can work out the formula that determines the voltage from the resistance, then you can simple invert the equation to give you resistance from voltage and apply that in a function node.

So I've changed the fixed resistor to 220ohms (Don't have any 200) and the output does seem more stable. There is still a non linear ramp at the 0 end of the sensor travel, but it's much smaller and thus a little more manageable. Prob 70% of travel is reasonably linear so I can work with that.
I would be keen to make changes to either manipulate the output to 'flatten' the curve, or find a way to measure the resistance perhaps without voltage division (Much like a multimeter does).

I'm still stuck on how to smooth out the raw readings within NodeRed, maybe apply a mapping that outputs a value based on an incoming value following a non-linear scale with points of reference perhaps.
I think the math is beyond me, but I do think that value mapping to a scale with the node doing the scaling, very much like the Scale/Range node but with more than a start and end reference point perhaps...?

I am on my phone at the moment, I will sort out the formula for you a bit later.

1 Like

Looking back at the graph you showed of Position against Ohms is that something you have measured, or calculated, or come from the datasheet?
If you measured it did you measure the ohms when disconnected from your circuit?
I ask because one would expect the resistance to be approximately a straight line and not have the perturbation in the middle.

Like Colin said, I would avoid using the 5V rail for your pull-up as you stand the chance of destroying the Wemos if the sensor was removed or went open-circuit.

You also need to take note of the fact the +3V3 voltage regulator on the Wemos D1 Mini board is tiny and and can only supply a limited amount of current. Using the 220 ohm resistor, the maximum current drawn when the sensor is at 0 ohms will be 15mA - which the Wemos is able to supply safely.

PS:
Did you actually use your orginal circuit with the 10 ohm pull-up ??
If you did then the maximum current drain would have been 330mA !!!!!!!!!!!!!!!!!!!
That might explain the strange curves on the graphs

Hi, it was measured directly using a multimeter. The black float position was roughly positioned along the shaft to get the numbers in the chart. Not very scientific, but as the slope is mostly a straight line it would be fair to say the curve from the sensor is linear (near as makes a difference).

Hi,
Yes I did try the setup on the 10 ohm fixed resistor on the 3.3v rail (Never the 5v), that's where the second graph (V vs P) was derived. It's a 1w resistor.
Perhaps I need to try this on a fresh D1 with the 220ohms fixed 1w resistor. It does reduce the range a lot though.

OK. Feed the ADC signal directly into a function node containing the following

const R = 220
const k = 3.3
msg.payload = (msg.payload * R)/(k - msg.payload)
return msg;

Then connect debug nodes showing what is going into and out of the function node and put the sensor at each end and at the mid point and show us what is going into, and out of the function.

1 Like

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