Introduction: Digital Voltmeter

This is an instructable for beginners to teach you how to use an analog to digital converter

This will let you measure a ratio between a higher reference voltage and an input voltage. You need to calculate the actual voltage yourself because the basic stamp cannot calculate numbers below 1 (such as a percent)
Both the binary data and the decimal value will be displayed in the basic stamp debug window

This is done on a basic stamp 2 because it is the only microcontroller I have right now.
(I'll be making a programmer and cool toys for the PIC16F877A and PIC16F628A very soon.)

You will also need a 5v voltage regulator and a 3v voltage regulator (it's not really needed)
5v for the higher reference voltage, and the 3v for the test reading voltage (it's not really needed)
Your development board should already have a 5v supply though

And a MCP3001 analog to digital converter from Microchip at , another converter can be used if it uses the same method to transmit the measurement result, and you may need to modify the code


Step 1: Understanding Resolution

The resolution of a A/D converter means the accuracy, and it ranges from 8 bit and higher, the more bits, the more accurate results you can get

8 bit resolution has a maximum decimal value of 255, which means you can measure 255 different voltages ranging from 0 to whatever reference voltage you are using

16 bits has a maximum decimal value of 65535, big difference in accuracy, but only twice the storage needed

Say, if you wanted to make a voice recorder, and you needed the top sound quality, you need to get better resolution because it will make the sound so much more accurate, but the file size will be bigger

Step 2: Serial Communication

This particular A/D converter, MCP3001, uses a SPI serial interface, after reading it's database, it all becomes very clear.

There are three pins connecting your microcontroller (the basic stamp) to the converter:

Clock, (aka "CLK", or "CK") is used to synchronize data transmission, it lets two different components send bits at the same speed, a single bit is sent in one clock cycle.
a clock cycle is putting the clock pin high (aka "on", "positive", or "+") then low (aka "off", "negative", or "-") , basically generating a square wave

Data, (aka "DAT", "DT", or "D out") is what outputs the reading values, it will output either a 1 or a 0 in one clock cycle, and your microcontroller stores that bit

Chip Select, (aka "CS", or "SS", SS means slave select, same thing though) is useful when you have multiple serial interfaced devices connected to just one microcontroller, only the chip that is "selected" will work, on this converter, putting the CS pin to high means not selected, while putting the CS pin low means you want to use that chip, and it begins to work

For A/D converters, sometimes the converter needs time to take a sample, for the MCP3001, you need to give it two clock cycles while it takes the sample, then the bits starts to stream in to your microcontroller, those are then stored in the memory of your microcontroller

The code will use the basic stamp's shift in command which makes this process easier, if you are using something else, you can manually make the clock high, read one bit, put the clock low, pause, and repeat until all 10 bits are read and stored

For more information, please read the MCP3001's datasheet
the images below are from the datasheet, READ IT

Step 3: The Circuitry

Connect the chip select pin on the converter to pin 0 on the basic stamp, clock to pin 1, data to pin 2

"V ref" is the reference voltage input, connect that to the 5v voltage regulator's output

"V in +" pin is the reading input, and it should be connected to some sort of probe, or the 3v regulator for testing purposes

"V in +" pin is the reading input, and it should be connected to some sort of probe, or the 3v regulator's output
"V in -" pin is also a reading input, and it should be connected to some sort of probe, or the ground (which means negative)

Vss is connected to the ground, and Vdd is connected to the 5v regulator output

The battery on board your basic stamp's development board should be enough to power the entire thing, so connect the positive battery terminal to the input of both regulators, and the negative terminal to all the grounds on the regulators and the Vss pin on the converter

You can breadboard this just for fun, or if you want you can solder it to a microcontroller and add a lcd screen or something

Step 4: The Code

This code is written in PBASIC which is used only for the basic stamp, the "shifin" command makes it very easy, if you have a AVR or PIC chip or something else, you should probably find a sample code for SPI interfaces, or bit bang (manually outputing the bits one by one, look it up) the whole input process, which is not hard with this A/D converter

Download the basic stamp code in this step, I hope I commented the code well

Step 5: Program It, and You Are Done

Program the basic stamp or whatever you are using, and test out your new digital voltmeter

What ever you are measuring must be lower than the reference voltage

Do not reverse the probe polarity, it may damage your converter


dolphin42 (author)2009-10-22

Oh - and the >4000 V - means "At least 400V static discharge from the "human body model simulator" a very specific network of resistors anc caps that simulates a charged up person.  there is a secondary number, generally less than 1000V for "machine discharge" (the machine, being metal - discharges much more rapidly into the chip) - this refers to things like assembly robots (most electronics are assembled robotically now)

so it does NOT mean the chip can handle a bazillion volts. - not by any means,

treat CMOS parts (that's most everything now) with care.

dolphin42 (author)2009-10-22

the reason that most modern CMOS ICs need protection is because of how the transistors work. the key to the amazing low current draw is the thin layer of glass that is between the input (gate) of the MOSFETs used and the switched current (the rest of the device) - this thin layer of glass is so thin that it breaks down at about 25V (this can be as low as 6V or much higher, but it is a low voltage relatively speaking) - when you walk around with a static charge on you and you touch an unprotected gate - you'll blast right through the glass layer and destroy the MOSFET (or merely cripple it so the device 'sort of' works.)  - the protection networks route any voltage higher than the +power terminal or lower than the -power terminal onto the power buss of the part, effectivly distributing the static over all the terminals of the part. Most of the time this will protect the part from the static. BUT NOT ALWAYS! this is why you need to handle the parts with care, and don't run pins directly to the outside world unless it's through a high vlaue resistor (to limit the actual current of a static event to levels the protection networks can handle safely.) If you don't have an antistatic mat, you can use an unfolded newspaper to work on. (newspaper is anti static, if not as good as a proper antistatic work surface).

LasVegas (author)2007-04-03

ESD protection is 4000V and above, not below. > 4kV

frank26080115 (author)LasVegas2007-04-03

oh, so... if it's 7 volts to 4000 volts, it's fried if it's 4000 volts and over, it'll be alright? thx

0_Nvd_0 (author)frank260801152009-04-23

ESD is for a very short time. That's why the protection works. It is the current * time that damages (FRIES) the chip. Even low over voltage would kill the chip if sustained for a longer period of time.

LasVegas (author)frank260801152007-04-04

Actually, if you feed 120v into the pins, I assure you that you have no chip left, but that's not the point. ESD Protection is protection from "ElectroStatic Discharge." This is the static buildup that occurs if you're wearing wool socks with rubber soles or any other combination of dissimilar materials. It could be enough that it makes you jump when you touch a friend or so small that you never knew it was there. Either way, many components would be instantly destroyed because you touched it and discharged through the device. This device, with the protection, shouldn't suffer that fate.

binnie (author)LasVegas2007-05-15

i think he was jsut being humorous

MrPhelps (author)LasVegas2009-04-23

Are you serious ? I'm not sure but if you are, do you think it would resist a 1 million volt discharge ? >4kV means that the device has a protection better than 4kV, without knowing what level exactly. So you should take 4kV as a maximum. Also, this is a protection for human contact, calculated for the human body model (100pF in series with 1500ohm). You won't get this protection if you connect it with something else, the mains, a battery, a lightning rod, etc ... Something else : if you wish to record a 20kHz signal, you need to sample at least at 40kHz. That's the Nyquist theorem. That's why CDs or high quality digital audio in general has a sampling rate of 44.1kHz or above.

frank26080115 (author)2007-04-04

I just used a ds1620 on my bs2 and made a working computerized thermometer, the code is found here , and connecting it is simple

About This Instructable




Bio: I am an electrical engineer. I graduated from U of Waterloo. I used to work for Adafruit Industries as an EE. Now I work for ... More »
More by frank26080115:LED Pocket WatchEasy Cord Wrapping Around Power BricksUsing SMD Components on Breadboards
Add instructable to: