Cheap Analog Signal Acquisition for PCs

There are times when you’ll need to read analog signals and pass them to a computer to process or display. Analog signal acquisition cards are usually expensive and not suitable for hobbyist on a budget. So if you’re not running mission critical systems requiring ultra fast and accurate updates, here’s a very cheap and easy solution to getting your analog signals into your computer.

This idea came to me when I was looking for a USB interface card for my CarPC. Unfortunately for me I have a very old car that doesn’t support the current OBDII system so I have to hardwire everything to get their status. I needed the status of the fans, coolant temperature, compressor clutch, and a host of other parameters to feed my obsession for information that I don’t need and to distract me from the road ahead. While looking for a cheap and easy way to get all these information (PICs, etc.) I stumbled upon cheap China made USB controllers. And since USB is pretty much standard with every computer, I was sold.

First off, you will need an analog USB joystick. You can probably see where this is heading. The reason is because USB joysticks are so cheap that it makes sense to experiment with them. Besides analog inputs, you get discrete inputs too with these joysticks. You can grab some of these joysticks from the links below:

Note: I would recommend the gamepad type because there are 4 analog inputs as compared to only 3 for the joystick. Get the cheapest analog controller you can possibly find. Warranty is not an issue for obvious reasons.

DSC_0004 copy

This controller from a local computer store cost me RM23 ($8) only. It has about 20 discrete inputs (buttons) and 4 analog inputs and also a vibration unit inside.

First thing you’ll want to do when you get your controller is to plug it into the computer and check if it works. If not you still have the option to return it to get a replacement. Once you are satisfied with the condition of the controller, it’s time to have some fun. Take out your screwdriver set and tear it open.

DSC_0006 copy

Here you’re looking at the analog  joystick board (green). All the connections that you need can be tapped from here. If they are 4 axis of analog control, you will have 4 inputs from here.

DSC_0006

The  red squares show where the 4 potentiometers are. The red circle shows the input connections. The 5V and ground reference is there also.

DSC_0009 copy

Measuring the supply voltage to the potentiometers. As expected, it was 5v (USB powered)

So basically the controller works as follows:

schematic

Looking at the diagram on the left, with a supply of 5v and ground, the potentiometer divides this and gives an output that varies between 0-5v. So depending on where the potentiometer is positioned, the output voltage to the joystick’s controller input can be anywhere from 0v to 5v. The joystick controller then reads this voltage and gives a reading to the computer.

DSC_0015 copy

An externally connected potentiometer is used for testing. The purple wire supplies the 5v, blue wire supplies the ground and green wire is the input. A capacitor is connected between the input and ground because the readings were “jumpy”, probably due to external interference.

So if the potentiometer is turned all the way down, the input to the joystick controller will be 0v. The joystick will then send a “full left” (or “full right” depending on the design) to the computer. If we turn the potentiometer all the way up, the input to the joystick controller will be 5v. The joystick will then send an opposite signal to the computer, telling it that they joystick has now been moved all the way to the other direction.

If the potentiometer is turned somewhere in between, it might give a signal of 3v. The joystick controller will then interpret this and tell the computer where the joystick location is.

If you have managed to follow the explanation above, you’ll see why we can use this to measure analog voltages. We can theoretically apply a voltage to the analog input of the joystick controller and the joystick will send that signal to the computer. I say theoretically because that is not exactly the case in real life, as you will see below:

joystickform

This is the software that reads the joystick input. It’s written in C# and it can be downloaded from codeproject.com along with the source code. I’m not an expert in C# so please direct your C# questions to someone else. But a little reverse engineering and trial and error should help you modify the source sufficiently for your own use.

I disconnected the potentiometer and instead connected the input to 2 different batteries, one at a time:

liiontest

When I connected it to the Li-ion battery of 3.86v (measured with a voltmeter), it gave me a reading of 62154.

aatest

When I connected it to a AAA battery of 1.5v, I got 8191. If we assumed that 0v will show zero on the computer and 5v will show 65535 then the readings will not make sense. For example:

Input Voltage = (Axis Value / 65535) x 5v

In the case above, we got 8191 for the 1.5v battery. So if we substitute that into the formula above, we’ll get:

Input Voltage = (8191/65535) x 5v = 0.6249v (which is obviously not the voltage of the 1.5v battery)

So it seems that the joystick controller only reads a certain range of voltage, with dead zones at both the upper limit and lower limit. Hence, we need to calculate those values. We have 2 variables to figure out: the lower limit and the range. Upper limit is not required to get the correct voltage reading. We already have 2 samples to work with from above (the li-ion battery and 1.5v AAA battery). By using simple high school maths, we can then calculate for the 2 unknowns:

calculation

Note: the AAA battery was at 1.49v.

From here, we know that the lower limit is 1.1431v. So anything below this, the joystick reads as zero. Also, we now know that the joystick only reads a range of 2.8647v. That’s not a lot to play with. But it’s sufficient.

So now with the unknowns calculate, we can write our equation for this joystick:

Input Voltage = 1.1431 + (Axis Value / 65536) x 2.8647v

To test the equation, we use the example of the 1.5v battery again:

Input Voltage = 1.1431 + (8191 / 65535) x 2.8647v = 1.5011v

Now the value of 1.5011v looks more convincing.

DSC_0012 copy

From here, you can tap the other analog inputs. And using the values acquired from the equations, you can write your program to display the values in voltages instead of unintelligible numbers like 8191.

If you need to read more range or higher voltages, just use a voltage divider network.

Of course, if you require better resolution, you can always go for the commercial devices, like the one shown below:

That’s about all that you need to know on how to make a cheap and easy analog signal acquisition device for a computer. If you have questions, comments or suggestions feel free to leave them in the comments section below or send me an email.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>