Schematics and C code for a 0-5V PIC LCD Volt Meter.

This PIC LCD volt meter project uses a PIC micro and an HD44870 LCD display. The analogue input is taken directly to the analogue input pin of the microcontroller without any other processing.

lcd volt meter

The basic input range is from 0V to 5V.

Specification

The LCD volt meter uses the microcontroller power supplies as reference voltages and so it is not likely to be very accurate (e.g. a 7805 5V regulator has an accuracy of 4%).

To improve accuracy add a voltage reference and feed the reference voltage to the Vref input on the PIC which is into RA3 ( change the control register values in the ADC to use the Vref). This project simply provides a quick and easy way of measuring volts without circuit complexity.

Voltage range 0V - 5V
Input signal level TTL
Maximum input impedance 2k5

The project mainly shows how to control and setup the software to read an analogue value from the first analogue port RA0.

Note when designing using the analogue inputs its a good idea to start from AN0 as there is only a limited set of ways that more analogue ports can be selected for use (see the chip data sheet - analogue inputs).

Warning : This lcd volt meter is only as accurate as the power supply. If you need good accuracy use a voltage reference fed into the ADC analogue reference pin. This will also requires enabling that feature in the microcontroller in the software.

Since you can't use a 5V refrence (if using a 5V supply) then use a 2.5V reference and divide the input using a vlotage divider by 2 - to get back to 0-5V reading range - or divide by more to allow higher voltage input. Don't forget to add protection on the microcontroller inputs i.e. 5V clamp diodes (to stop damage if too high an input is put to the top of the divider).

Compiler Mikroelectronika MikroC Compiler Free!
Target 16F877A (retargetable to other PICs that have Analogue input AN0).
Software level Easy.
Software notes Using fixed point long instead of floating point.
Hardware level Easy.
Hardware notes LCD will work with LVP (if PGM pin is pulled high).
Project version 1.01
Project files Enter your details to get the Download Link
and get the microcontroller newsletter:


(Note: Your email is safe it will never be sold or rented).
You will get All the C source code and hex file.

Note: Check your email for the project code download link.

PIC lcd volt meter using HD44780 LCD.
(Click diagram to open a pdf).
lcd volt meter using LCD and AN0.

TIP: This code uses fixed point which allows you to save programming memory space i.e. instead of floating point which uses up a lot of programming memory.

PIC lcd volt meter Hardware

You can use any PIC microcontroller that has an ADC and enough memory to hold the program.

The LED is pulsed after every ADC acquisition to indicate that the processor is alive - so you can tell if the software is active.

You can program the PIC in circuit through the ICSP connector.

lcd volt meter schematic circuit

LCD volt meter Software

Project files for the PIC frequency counter circuit

Compiler project files:
ADC_4MHz_LCD.mcppi

C Source files:
ADC_4MHz_LCD.c

Output files:
ADC_4MHz_LCD.hex

For a tutorial on compiling these lcd volt meter files click here.

You can recompile the lcd volt meter files if you want examine code operation (using the built in simulator) or change the source code. Note the hex file is contained in the download.

Description

ADC_4MHz_LCD.c

The code is simple showing how to set up the ADC using direct control (it does not use built in routines) so that the code can easily be ported to other compilers.

It enters a continuous loop collecting ADC samples and displaying them on the LCD.

The only complexity is that the code uses fixed point maths so that it avoids using floating point variables (saving memory space). Long variables are used to scale the output result. This statement

Calculation

lng = (ADC_ip * 5000L) >> 10;

Scales the ADC input value to 5000 and then divides by 1024. The output is a number between 0 and 5000. e.g. for a 2.5V input voltage the ADC will read 512. 512 * 5000 is 2560000 Dividing by 1024 gives 2500. So using the fixed decimal point between the 2 and the 5 gives the final result displaying "2.500"

The code converts the 10bit ADC number into a displayable voltage reading.

Calibration

Note: The circuit does not feed in an accurate voltage to Vref+ so the accuracy of the reading is only as good as the power supply voltage regulator (not shown on circuit diagram) - this will usually be a 7805 standard 5V regulator. This has an accuracy of 5% so the displayed output will be wrong by 5%. If you want to calibrate the output to get a more realistic a reading you can set the scale factor in the software to match the 7805 output voltage value.

All you do is use a multimeter to measure the power supply (mine read 4.91V) then instead of the 'ideal' scale factor of 50000L change it to match the multimeter reading e.g. for 4.91V use the statement

lng = (ADC_ip * 49100L) >> 10

This scales the maximum ADC output to 4.91 (The maximum reference value) and displayed readings will now match the multimeter readings. For production use this is not a good idea and you would be better off adding a voltage reference.

Summary

This design provides a quick and easy way to measure voltage with minimal components but for better accuracy use a voltage reference.

Note: To smooth the input signal use a capacitor e.g.. 100nF or use software averaging in the code.


New! Comments

Have your say about what you just read! Leave me a comment in the box below.




Privacy Policy | Contact | About Me

Site Map | Terms of Use





Subscribe to the MicroZine Newsletter and collect your free microcontroller Ebooks, download project code and more...


Visit our Facebook Page:

   Click Here

Recent Articles

  1. The Essential I2C Tutorial: All you need to know about I2C...

    I2C tutorial: Learn all about the 2 wire I2C serial protocol. Learn how easy it is to use, how it works and when to use it...

    Read more

  2. [Arduino] : Using the 74HC595 shift register with shiftOut().

    The Essential Guide to the 74HC595; What it is and how you can easily use one in any of your projects.

    Read more

  3. How to use a DS18B20 on the Arduino for easy temperature measurement

    How to Easily Use the DS18B20 Maxim One-Wire thermometer with Arduino example code showing external or parasitic power modes.

    Read more

  4. Secrets of Arduino millis: How it works and how to use it.

    How to use Arduino millis() to make delays, one-shots and simple schedulers plus simple analysis of arduino millis() code; Find out how it works.

    Read more

  5. The TCS230 Color Sensing Chip: How it works and how to use it.

    How to use the TCS230 (/TCS3200) Color detector chip and easily add it to any of your projects.

    Read more

  6. Pic Programmer Types

    Which pic programmer do you need? This page discusses PIC programmers and gives some essential information on choosing or building your own programmer.

    Read more

Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."

- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com<

"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


Learn Microcontrollers

"Interested in
Microcontrollers?"

Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon

Back to Top