DEV Community

Cover image for Measure DC Voltage and Current with Arduino: A Step-by-Step Guide with Simple Code and LCD Display
uchemma001
uchemma001

Posted on

Measure DC Voltage and Current with Arduino: A Step-by-Step Guide with Simple Code and LCD Display

This article will teach you how to use the Arduino IDE to measure DC voltage and current with a simple code and a single connection on one LCD display, providing a schematic to follow and step-by-step lines of codes.

Arduino

Arduino is an open-source platform for electronics projects that uses a microcontroller to control various components. It is user-friendly, with an accessible IDE and a large, supportive community.

Its versatility allows for a range of projects, from simple LED control to robotics and automation. Arduino is open-source, cost-effective, and suitable for both beginners and professionals.

This usually needs some or a lot of lines of code for it to function. Arduino has no specific language it is written in. Yes, it is written with a combination of languages, for example, C/C++, Assemble Language, Python, Java, and JavaScript.

Please note that the Arduino platform itself is built on a foundation of C/CC++ and assembly language.

The Arduino IDE (Integrated Development Environment) is like a special notebook for writing instructions (code) that tell Arduino boards what to do. This code, called sketches, is what makes Arduino projects come alive. You can get more basic knowledge on Arduino here

DC Voltage And Current Measurement

Direct current (DC) voltage and current are two of the basic electrical quantities that define the operation of an electronic circuit.

You can say a voltage is like the force that pushes the current through the circuit, while the current is the flow of electrical charge.

The Arduino's built-in analog-to-digital converter (ADC) can measure voltage up to its operating voltage (usually 5 volts).

Components

  1. Arduino board (UNO)

  2. LCD display

  3. Voltage Sensor (Array Module)

  4. Current (ACS712)

  5. Bread-Board

  6. Jumper wires

  7. DC voltage source X2 (battery, power supply)

  8. Dc Load (Bulb)

  9. Switch

Schematic

All components listed above are listed in this diagram. Do well to carefully follow through with the diagram. You can decide to use an adaptable box and then make the necessary spaces for the outside connections as shown in the diagram.
Schematic Diagram

Code/Sketch

Analog Input Pin

This line of code defines a constant called ANALOG_IN_PIN() and assigns a value to A0 and A1.

These A0 and A1 are the first analog input pins on the Arduino board. They are both from different sensors.

A0, this analog input pin is used to read analog current flowing in the load in use.

A1: These analog input pins are used to read analog voltage signals, which can have a range of values between 0 and 5 volts

LiquidCrystal_12C Library

Before you can run this line of code, you will definitely need to download the LiquidCrystal_I2C library. You can download it here.

The is made to work with 12C (Inter-Integrated Circuit) LCD displays. By including this library at the beginning of the sketch, we are making all the functions and features of the C library available for use in our code.

The #include <Wire.h> line includes the Wire library, which is necessary for I2C communication on Arduino.

LiquidCrystal_I2C lcd(0x27, 16, 2); initializes an object named lcd of type LiquidCrystal_I2C.

Code1

Variables

This is when you declare and initialize variables for measuring the voltage and current. Now these constants will be used throughout the measurement.

code2

Setup()

This is where you call your program to run, like initializing the serial communication at a baud rate of 9600, the pin mode and the LCD display.

The void setup() function in Arduino is a mandatory function that is called once at the beginning of the program.

code3

Loop

This code runs the necessary computations, records the results in the appropriate variables (in_voltage and current), and continually monitors the DC voltage and current. Whereas the current measurement averages 1000 measurements for accuracy, the voltage measurement just employs one analog read.

lcd.init() initializes or awakens the LCD display, creating a connection between your lines of codes and the LCD display.

code4

Serial Print

This is where you display or print your calculated input voltage and current values on the serial monitor in the Arduino IDE (this is like your display terminal).

code5

LCD display

Finally, this code segment is crucial for displaying the measured input voltage and current values in a readable format on the LCD screen, providing real-time feedback on the voltage and current measurements being taken by the Arduino.

code6

Furthermore, when you have the connections set and your code set, you can upload your code to the Arduino board by using your Arduino cable. After uploading, your DC voltage and current are ready to be measured.

You can place a DC voltage to calculate the voltage and also place any DC load to calculate the current flowing through it. Please do well to adhere strictly to the diagram above.

Conclusion

In this article, we have learned to measure and display DC voltage and current with Arduino with simple code, using the components provided in this article.

The key steps we covered were:

  1. Connecting the Arduino, LCD display, voltage sensor, and current sensor using jumper wires

  2. Writing Arduino code to read the analog input pins, perform calculations to determine the voltage and current values, and format the results for display

  3. Displaying the real-time voltage and current measurements on the LCD screen

This project introduces working with Arduino, sensors, and displays. It teaches interfacing components, creating interactive systems, expanding code, and gaining practical experience in embedded systems and electronics.

I hope you found this tutorial helpful and inspiring! Let me know if you have any other questions or ideas for projects you'd like to explore with Arduino.

Top comments (1)

Collapse
 
dondogg_97d62222eb7948a86 profile image
Dondogg

Hello dear,
thanks a lot for this great job. I love it.
Please I'm having difficult in downloading the schematic diagram. It keeps popping-up this error message.
The image "res.cloudinary.com/practicaldev/im... be displayed, becasue it contains errors
Please can you help out.