Using 0 - 5 volt sensor

Hello I am using a pressure sensor that has an analog linear output of 0 - 5 volts. 0 volts is 0psi and 5 volts is 100psi. Is it possible to connect the analog sensor to a Photon and read the 0 - 5vdc output of the sensor? I have seen diagrams for using 2 resistors to drop the voltage to 3.3 but that will affect the accuracy and I do not want to use. If the Photon will not do is there another Particle product that will? Thank you

Hi @aharris

I would use an op-amp for that job. You need a gain (loss) of 3.3/5 or 0.66. The op-amp should run on a 5V supply.

Here is a tutorial to get you started but you really just need the op-amp and a few resistors:

2 Likes

@bko’s suggestion is dead on, but the accuracy impact of a voltage divide might not be as big as you anticipate - you’d just need to select the resistor values right and get the initial calibration according to resistor tolerance correct :wink:

But going the extra mile with an op-amp is definetly the more professional approach.

The next step up would be using an external dedicated high-res ADC.

1 Like

Thanks guys that’s what I was thinking but was hoping I missed something.

Watch out… the “Summing Amplifier” configurations in the article are all inverting, which you almost certainly don’t want, as they will produce negative voltages at the output of the op-amp for positive voltages at the input. The ADC inputs on the photon/electron are not able to sample negative voltages.

Take a look at the non-inverting configurations (in the same tutorial series):

You’ll either need to select an opamp that can swing its output very close to the negative rail (and even if it swings very close to the negative rail, it will be impossible to actually reach zero volts) or you’ll need to provide the opamp with a negative supply voltage lower than 0 volts, even though the output should never go below zero volts.

I’d strongly consider trying the voltage divider solution, as it is way less complex. The challenge is to select the resistors such that the load on the output of your sensor is small enough, while providing enough current to drive the Particle ADC inputs. (The ADC inputs on the Particle devices are rather finicky, in my experience, as compared to the Arduino/Atmel ADC inputs.)

Jeff

Inverting is fine on a +5V op-amp since there is no negative supply. If you want to invert the answers back you just need some integer arithmetic like posAnswer = 4095-negAnswer;

1 Like

@JeffInCO, you will also note that non-inverting op-amp configurations cannot have a gain of less than 1 so cannot be used here since the target gain is 0.66.

@bko – I’m not following your logic. With no negative supply, it’s impossible for the inverting configuration to satisfy the equation Vout = -(Rf/Rin)*Vin unless the reference point (to which the “+” input of the op-amp is connected in the inverting configuration) is somewhere other than zero volts. Maybe this is what you mean?

@peekay123 – You’re right, and my bad. You can’t get a gain less than 1 with the non-inverting config, although a voltage follower can buffer the output of the pressure transducer, which might provide some additional flexibility in choosing resistor values for a voltage divider either in front of or at the output of the opamp.

@JeffInCO, take a look at this TI article, specifically at Case1: Vout=mVin+b. You are correct that with a single rail op-amp configuration, the “+” input of the op-amp needs to be biased. For the specific case in the article, with Vref = GND, R1 and R2 create a voltage divider, biasing the op-amp input. Combined with the op-amp gain, and knowing Vout=0 @ Vin=0 (b=0) and Vout=3.3@Vin=5v, the resistors can be calculated.

Of course, as you mentioned, another way is to create a simple op-amp follower with resistor divider to achieve similar results. :wink:

1 Like

Thanks for all the input. I do not want any “extra” hardware so I will switching to a different processor anyway.

Hi @JeffInCO

As @peekay123 pointed out, you just need two extra resistors to set the positive input of the op-amp at mid-rail. If you are worried about the non-linearity at the extremes of the range (near 0 and +5V input) then you might want a larger supply voltage but I think in this case it will be close enough for the intended usage.

A follower would be a good choice as well and uses two fewer resistors, but you would still have some non-linearity at each end.

1 Like

If you don’t want any additional hardware, you can use your 100 psi sensor for an application that never reaches 66 psi. The Voltage output would be <= 3.3V.

1 Like

That’s a great idea Rftop. For this particular project I have a small accuracy that I need to accomplish and using only part of the ouput is not an option but that will work for other projects. Nice idea thanks. That’s why I like forum’s, you get high level technical answers along with simple easy solutions, then I can decide what to use. Thanks everyone!!

2 Likes

I’ve been in the same situation as you.
But don’t be scared to try a simple voltage divider.
It probably wont impact the precision as much as you would expect.

I may do this wrong, but somebody will fine-tune this if so :slight_smile:
The ADC precision is 3.3V / 4096, so you get 1241 “steps” per Volt.
Your 100 psi sensor has a 5V range, so that’s 20 psi/ V, or 0.05V per psi.
1241 * 0.05 = 62 “steps” per psi = 0.016 psi measurement resolution from the ADC over a 3.3V range.

The Best 100 psi pressure sensor that I’ve personally used has a specified accuracy of 0.25%
So a 100 psi sensor has a stated accuracy of 0.25 psi which is already higher than the Photon/Electron’s measurement capability.

The resistors have an accuracy rating, but unless I’ve got the wrong idea, the Photon/Electron is more than capable of performing the measurements when re-scaled to 3.3V max by a voltage divider.

1 Like

With a voltage divider (e.g. 5k + 10k) you’ll get 33mV per psi and the resolution of the 12bit ADC is aproximately 0.8mV or ~0.025psi.

1 Like

BDub has a great write up on ADC_SAMPLING_TIME might help:

Helped me figure out why my readings were off, good advice !

Odd analog readings (part 2)

Regards.

I’m interested in your reasoning on the cause of the loss of accuracy (I haven’t checked the specs on the A/D conversion yet in the Photon). Also interested in the reasoning behind using an op amp instead of resistors.

First, there is accuracy and there is resolution, two different things. If you are worried about resolution, I don’t think using a simple resistor divider should hurt you at all. I assume the photon A/D internally has resistors to scale the voltage to a 3.3 V range that maximizes the resolution of its conversion. So finding a different processor that scales the range to 5 V really is just a different set of resistor dividers. So adding your own resistor dividers shouldn’t really be any different, from a scaling perspective. The only way to get more resolution would be to choose a processor with more than 12 bit A/D conversion.

As for “accuracy”, you have a point, assuming the Photon has carefully calibrated its A/D converters. Using a resister divider could very easily introduce an error in the scaling if the resisters are not exactly the values you expect. If you want good accuracy, then you would probably have to use resisters with (.1%) tolerance or less, pretty rare beasts.

But… there is an easier way. Do the best you can with resistors, then calibrate your system by measuring a very accurate reference voltage (use a battery and measure with a good voltmeter) and in your software have a scaling factor to adjust the measurement to make it accurate. I would try that route.

The only reason I can think for adding an op amp would be if you are worried your resistor voltage divider lowers the impedance too much and distorts the sensor output. Even then, it is likely by a scale factor you could calibrate. But I’ll see what others think about that. Also, adding a resistor divider does introduce a little noise, since all resisters are noise sources. But for slow measurements, you can alleviate that with perhaps a small capacitor around the resisters, or by averaging measurements. I also doubt that resister noise is very significant for a 12 bit conversion.

Now, if you simply don’t want to add any components, sure, go with a microcontroller that can handle 5V inputs on its A/D converters, such as a microcontroller that allows a Vref equal to 5V.

1 Like

Fro very accurate applications, I’ve used ADS1115 before… 16 bit accuracy and has a very wide range with scaling options.

For example I needed something to very accurately measure 0.05v to 0.95v and this baby was awesome!

2 Likes

i simply ordered pressure sensor 100mBar gain with a 5V supply and a 3.3V max output

ou can als overrange the sensor so it will never reach the 5V output ( put a protection zener over it )

a trick use resistor - 20 turn potentiometer-resistor to adjust accurately

use oversampling to reduce the noice

and dont use the ESP32 on the analog ports for there linearity and accuracy problem ( learn from my mistake )