Required Components
- 1 x Arduino Board (e.g., Arduino Uno)
- 1 x 16x2 LCD (with I2C backpack for simplicity)
- 1 x 10kΩ potentiometer (for LCD contrast adjustment)
- Jumper wires
- Breadboard
- Voltage source (e.g., adjustable potentiometer or external voltage to measure)
Wiring Diagram
The LCD connects to the Arduino via the I2C interface:
- VCC: Connect to 5V on the Arduino
- GND: Connect to GND on the Arduino
- SDA: Connect to A4 on the Arduino
- SCL: Connect to A5 on the Arduino
The voltage to measure should be connected to analog pin A0
.
Code Explanation
The code reads an analog input using the Arduino’s ADC (Analog-to-Digital Converter), converts it to a voltage, and displays it on the LCD.
Key Concepts
- Analog-to-Digital Conversion: Arduino’s ADC converts input voltages (0V to 5V) into digital values (0 to 1023).
- Voltage Calculation: The formula
Voltage = sensorValue * (5.0 / 1023.0)
maps ADC values back to voltages. - I2C LCD Interface: Libraries like
LiquidCrystal_I2C
simplify communication with the LCD.
Arduino Code
Use the following code to build your voltmeter:
// Include libraries for I2C LCD
#include
#include
// Initialize the LCD with I2C address 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);
int analogPin = A0; // Pin to measure voltage
float inputVoltage = 0.0; // Variable for voltage value
void setup() {
lcd.begin(); // Initialize LCD
lcd.backlight(); // Turn on backlight
lcd.print("Digital Voltmeter");
delay(2000); // Display welcome message for 2 seconds
lcd.clear();
}
void loop() {
int sensorValue = analogRead(analogPin); // Read analog input
inputVoltage = sensorValue * (5.0 / 1023.0); // Convert ADC value to voltage
lcd.setCursor(0, 0); // Set cursor to first row
lcd.print("Voltage: "); // Display label
lcd.print(inputVoltage); // Display measured voltage
lcd.print(" V"); // Append "V" for volts
delay(1000); // Update every second
}
How It Works
- Setup: The LCD initializes and displays a welcome message.
- Voltage Measurement: The ADC reads an analog value and converts it to a corresponding voltage.
- LCD Display: The voltage is displayed on the first row of the LCD in real time.
Upload and Test
- Connect the Arduino to your PC using a USB cable.
- Open the Arduino IDE and paste the code above into the editor.
- Install the
LiquidCrystal_I2C
library via the Arduino Library Manager if not already installed. - Select your board and the correct port in the IDE.
- Click the upload button to program the Arduino.
- Adjust the input voltage and observe the changes on the LCD screen.
Tips for Customization
- Measure Higher Voltages: Use a voltage divider circuit to measure higher ranges (e.g., 0V to 12V).
- Improve Accuracy: Use a higher-resolution ADC module if your project requires more precision.
- Display Enhancements: Add additional information like minimum, maximum, or average voltage readings.
Conclusion
This digital voltmeter project demonstrates how to measure and display voltage using an Arduino and an LCD. It’s an excellent starting point for learning ADC, I2C communication, and voltage measurement. With minor modifications, this project can be adapted for a variety of applications.