# Reading voltage into a computer

Discussion in 'General Electronics Discussion' started by segfault0x20, Apr 22, 2010.

1. ### segfault0x20

4
0
Apr 22, 2010
Hi, I'm working on a project for measuring the power usage of my home.

I have two clip-on amp meters that output 1mV AC per amp being drawn.

I've already built a circuit to convert the AC mV to DC and amplify it, now I'm not sure where to go from here.

I need to find the cheapest and easiest way to read the voltage into a computer serial port, once every second.

I'm not really sure where to start, I just need to find a way to be able to check the serial port every second with my program and get the value of the current being drawn at that second, so I can store it and do my processing.

Any ideas?

2. ### (*steve*)¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥdModerator

25,448
2,809
Jan 21, 2010
Basically you need to amplify the signal, rectify it, and use a capacitor with a parallel resistor to average it over a short time period, then do some sort of A-D and squirt the result to your PC.

The easiest way of doing the A-D and conversion to a serial data stream is probably a uC. How good is your programming?

You probably want to average the current over each 1 second interval by making some number of readings per second, rather than just reading the value each second.

As long as your current measurements are taken by a clamp device, you should be well isolated from the mains, but I would still consider sending the data via an optocoupler -- just in case.

3. ### segfault0x20

4
0
Apr 22, 2010
My programming is a lot better than my electronics building is.

I was looking at a certain A/D chip, that apparently had a serial output, but I wasn't sure... It was a texas instruments TC564 I believe, I'll try to find it.

What's a uC?

Last edited: Apr 22, 2010
4. ### (*steve*)¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥdModerator

25,448
2,809
Jan 21, 2010
uC = microcontroller.

PicAxe is a very simple way to get into this, and has low costs for programmers. Otherwise you could look at PICs or all manner of other microcontrolers.

Likely you could find something that will do all you want in an 8 pin package

5. ### 55pilot

434
3
Feb 23, 2010
If hardware is not what you want to get into, I would suggest look into buying a "USB data acquisition" board. There are lots and lots of companies that make them and you should be able to find one that meets your needs that you can buy locally, wherever part of the world you happen to be located in.

They typically have several analog inputs that you can read from the PC. They have an ADC (Analog to Digital Converter or A/D) talking to a uC (micro-controller) which collects the data and sends to a PC using USB port. If you are strong in programming, you can do most of the work programming on the PC.

Edited to add: The type of boards I am suggesting will connect to the filter Steve suggested, going where the ADC goes in his suggestion. Or you can do it using a uC as suggested in the above post.

---55p

Last edited: Apr 22, 2010
6. ### segfault0x20

4
0
Apr 22, 2010
I wish I could do that, as I already found a very interesting (and cheap) board of that type, but the system I'm going to be working with has no USB ports, it's very old, hence the need for serial communication.

7. ### 55pilot

434
3
Feb 23, 2010
In that case, if you can get away with 8 or 10 bits of accuracy, you can use a PicAxe, a regular PIC or a similar uC. Many of them have 8 or 10 bit ADCs built right on the chip die itself. If you need 12 bits or more, then you need to look at an external ADC and both the hardware and the software effort increases.

---55p

8. ### segfault0x20

4
0
Apr 22, 2010
The PicAxe circuits look very promising, but unfortunately I'm still not sure exactly what I need. Would something like this be appropriate for what I'm trying to do?

http://www.rev-ed.co.uk/docs/axe021.pdf

That board with the PICAXE-08M uC (From what I've read, it looks like the -08M is the one with A/D converters built in)?

Could I use that to measure two analog inputs and feed them into the computer's serial port?

Last edited: Apr 22, 2010
9. ### (*steve*)¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥdModerator

25,448
2,809
Jan 21, 2010
That prototype board would probably be a reasonable start.

The major difference (for you) between the 08 and the 08M is that the 08 has only 8 bit ADC resolution, and the 08M has 10 bit resolution.

An alternate method of gaining higher resolution is to use the timer to time how long it takes to charge up a capacitor from a (variable) constant current source. To do that, you would need to convert the voltage you get from the sensor into a current, and then have a comparator detect when a certain voltage has been reached. This tends to be far more timing sensitive, and although picaxe's are not slow, you would probably want to write in PIC assembler to ensure that you can count the additional clock cycles correctly (or you'll have trouble getting more resolution anyway).

If your maximum current is 100A, a 10 bit ADC will give you a 100mA resolution. Taking multiple readings per time period will allow you to theoretically increase that resolution, although practically what you do is reduce the noise in the low order bits.

The 08M has 3 ADC inputs, so you *could* measure up to 3 analogue voltages quite easily.

This page has all the relevant information, the three picaxe manuals being the major source of information. Since they describe all models, you need to make sure that you check to see if certain features are available on the PICAXE you purchase.

You also need a programming cable (it may come with the prototyping board), and the software (which you can download at no charge). The picaxes are cheap (compared to freight) so it may be best to grab a couple -- just in case you kill one.

Most problems arise because people do not have a correct (or correctly wired) programming cable, or because thay fail to keep the serial in tied to ground when the serial cable is removed (pulling it -- or allowing it to float -- high can initiate programming mode which will stop your program)

If you go this route, start with a simple program to flash a LED every second or something to get the programming issues sorted out. If you have an output free, you could retain that to indicate that data is being sent as it will give you a visual indication that the program is working.

10. ### cds333

2
0
Apr 30, 2010
I did the same thing but instead of monitoring voltages I made a circuit with a BASIC Stamp that allowed me to turn lights and stuff on remotely via a website hosted from my server. I don't know much about PicAxe but with the basic stamp development board it was quite easy since the board uses a serial port to interface with the computer anyway (alternatively you can use a PIC but then you have to build your own interface board).

Microsoft Visual C# (or any other Visual language) 2008 and newer has a System.IO.SerialPort class that makes serial port communications very easy (no drivers or .dll files required, unlike USB communications). All you would have to do is put a line in your program to send data to the serial port and have a similar subroutine programmed into the basic stamp and you will be interfacing in no time.

It took me about 2-3 hours to build a simple asynchronous communication circuit from scratch, where I could hit one of four keys on the keyboard and an led would lite up on the BASIC Stamp board 1-4 blinks, and in turn I could hit one of three buttons on the board and a corresponding indication would pop up in my C# program.

I attached some code files if you want to see how it works... .cs file is C# code, .bs2 file is BASIC Stamp code file.

Anyway good luck with your project!

File size:
1.3 KB
Views:
287
File size:
1.7 KB
Views:
284