- Published: Wednesday, 01 September 2010
- Written by Jon Chandler
- Hits: 6415
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.