## Simulating Analog Sensor Inputs

When developing an embedded application using analog sensor inputs, testing at specific sensor levels can be difficult.  For example, in my icemaker controller project, actions need to occur at certain water levels.  Using the actual sensor and a reservoir is time consuming, requiring filling and pumping out water to check sensor points.

Fortunately, simulating sensor operation is easy.  Many sensors, including my pressure sensor, output a 0 - 5v signal proportional to the input parameter.  A potentiometer (variable resistor) can easily simulate the sensor signal.

The schematic of a simple pot circuit is shown to the left.  End ends of the pot's resistive element are connected to ground and 5 volts.  The ADC input is connected to the pot's wiper which is a sliding contact along the resistive element.  The circuit acts like a voltage divider.  If the wiper is positioned near the ground terminal, the output voltage approaches zero.  As the pot's knob is turned, and the wiper movers towards the 5v input, the wiper terminal will be at a higher voltage.

Simulating a range of sensor values is as simple as turning the knob.

The first part needed is a potentiometer.  These come in a range of values, configurations and sizes.  A trim pot with a slot for a screwdriver isn't too useful here.  The photo below shows a standard size pot like you might find at Radio Shack.  The first question is what resistance range you want.  As you can see in the schematic, the resistance is connected between power and ground so too low of a value will result in a lot of current flow, heating, and could damage the pot.  Too big of a value will result in too little current for the ADC to work properly.  The acceptable range is pretty large.  Anything from 2k - 10k ohms will work well.

The next question is the taper of the pot.  A linear-taper pot is exactly that - linear.  If the knob is rotated to the midpoint, the resistance value and the output voltage) will be 50%.  If the knob is rotated three-quarters, the result is 75% output.  This is usually what we want.

The alternative is a logarithmic-taper pot.  These are designed to match the response of the ear.  At low values, a small rotation of the pot results in a large change in values.  At higher values, a small rotation of the pot results in a small change.  This is usually not the type we want.

So a linar-taper pot between 2k - 10k would be a good choice.

From the picture above, you can see the pot has 3 terminals just like the pot in the schematic.  But which terminals are which?  The wiper is the center terminal.  The terminals on either side are the ends of the resistive element.  As long as it's a linear-taper pot, either of these can go to ground and the other to +5V.  The only difference is which way the output voltage varies when the knob is turned.  To me, I expect the minimum level when the knob is rotated to the full counter-clockwise (anti-clockwise for non-American-English speakers <g>), and maximum level when the pot is rotated in the clockwise direction.  The simple way to remember this is that the terminal should be connected to the desired level when the knob is rotated in that direction.  So the left terminal should go to ground, the right to +5v.

A pot like this will span the full range of the ADC and let you check results easily over the entire range of values.  Setting an exact value, say an ADC count of 200, can be tough, as a tiny rotation might shoot right past the desired value.  When I calibrate instruments with this type of pot, I only half-jokingly say I grab the pot shaft and just think about turning it to get a desired value.

An alternative when high resolution is needed is a ten-turn pot.  Instead of turning about 270 degrees from one end of the range to the other, ten complete turns are needed to go from one end to the other.  The picture below shows a ten-turn pot.

This will work in the same way as the single turn pot.  The diagram on the side of the pot shows the connections.  If we follow the same plan with counter(anti)-clockwise = zero, terminal 1 will be ground, 3 will be +5 and 2 is the wiper.  Note the terminals 1 and 3 are in-line, and the wiper is offset from the other two.

Using the ten-turn pot, it's not too difficult to get the desired value.  On the other hand, making a rapid change from one extreme to the other is sacrificed.  Many turns are required.

Here are a couple pictures of my 10-turn pot in an enclosure.

Posted: 8 years 6 months ago by BARNEYB
i need to simulate the output of ADP5100 pressure sensor...it has an output impedance of 50ohms and the output varies from 0.45-4.5 volts...how do i do it?
Posted: 8 years 6 months ago
i need to simulate the output of ADP5100 pressure sensor...it has an output impedance of 50ohms and the output varies from 0.45-4.5 volts...how do i do it?

Simulate it with a pot exactly as shown in the article. The input impedance of a PIC is greater than 1K, so the output impedance of the pressure sensor is fine - as long as the input impedance is greater than the output impedance, you're good to go.

You could use a 1k pot with good results and measure the voltage between ground and the wiper to verify ADC readings.
Posted: 8 years 6 months ago by MrDEB
For better accuracy Barney might I suggest using a multi turn pot instead of a single turn. Seeing how you need to go from .45v to 4.5 and assuming you want a fine adjustment.
A single turn pot might go from .45v and JUMP to .5v just inserting a screwdriver or ? to adjust.
Using say a 15 turn pot then .2v per turn is approximately what you will obtain.
Perhaps adding a resistor(pot2) from pot1 to ground, then zero pot1 and adjust pot2 for your desired .45v.
Then you have pot1 adjustable FROM .45 to 4.5v as desired.
this is all dependent on input voltage.
Posted: 8 years 6 months ago by MrDEB
another possible idea for adjustable voltage reference
http://www.national.com/mpf/LM/LM10.html#Diagrams
Posted: 8 years 6 months ago by jmessina
I think the original idea was how to do it SIMPLY, and not create another whole project just to get a variable 0-5V output to test out your code.
Posted: 8 years 6 months ago by MrDEB
The op wants a supply that is adjustable from .45 to 4.5
"i need to simulate the output of ADP5100 pressure sensor...it has an output impedance of 50ohms and the output varies from 0.45-4.5 volts...how do i do it?"
Posted: 8 years 6 months ago by W4GNS
Amen Brother !
I think the original idea was how to do it SIMPLY, and not create another whole project just to get a variable 0-5V output to test out your code.
Posted: 8 years 6 months ago by MrDEB
One crazy idea BUT it works in LT SPICE
output is what was wanted but schematic is probably not correct?
Just a thought as it might spark someones imagination for something better?
Posted: 8 years 6 months ago by jmessina
Wouldn't it be easier to just use the original single pot? If you're only interested in 0.45 to 4.5V, then don't set the pot there.

It's usually a good idea to actually be able to go outside the range of interest when you're simulating something. That way, you can check that your code does something sensible when you get unexpected data from the sensor, and doesn't go off into never-never land, like dividing by zero or something stupid.

The chances of getting exactly 0.454-4.540V out of the sensor is probably about 0. If you code it that way, one day you'll be in for a big surprise.
Posted: 8 years 6 months ago by MrDEB
Good point on going outside the desired range.