Example Code for DFRduino-Voltage Display

Last revision 2025/12/12

This project uses an I2C LCD module to display the output voltage of the Power Shield. The Power Shield's built-in voltage measuring function maps the output voltage to Arduino analog pin 0, and the sample code reads this analog value, converts it to a voltage, and displays it on the LCD. Users can learn how to interface the Power Shield with Arduino, read analog signals, and use an I2C LCD for data display.

Hardware Preparation

Name Model/SKU Quantity Purchase Link
Power Shield DFR0105 1 DFRobot Product Page
I2C LCD Module DFR0135 1 DFRobot Product Page
Arduino Board (e.g., Uno) - 1 Arduino Product Page
External Power Supply (4.5-35V) - 1 -

Software Preparation

  • Development Tool: Arduino IDE (version 1.8.x or later). Download link: Arduino IDE
  • Required Libraries:
    • Wire (built-in in Arduino IDE)
    • LiquidCrystal_I2C (needs to be installed)
  • Library Installation Tutorial: Library Installation

Other Preparation Work

  1. Stack the Power Shield onto the Arduino board.
  2. Connect the I2C LCD module to the Arduino:
    • SDA pin of LCD → A4 pin of Arduino
    • SCL pin of LCD → A5 pin of Arduino
    • VCC pin of LCD → 5V pin of Arduino
    • GND pin of LCD → GND pin of Arduino
  3. Set the jumpers near the Power Input socket of the Power Shield according to your power supply needs:
    • Both jumpers on left side: Only provide regulated power to the PWROUT terminal (Arduino Vin will have no voltage).
    • Top jumper on left, bottom jumper on right: Provide regulated power to PWROUT and connect Arduino Vin to the external power supply.
  4. Connect the external power supply (4.5-35V) to the Power Shield's Power Input terminal.
  5. Ensure all connections are secure and the power supply voltage is within the specified range (4.5-35V).

Sample Code


#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("www.DFRobot.com");
  lcd.setCursor(0, 1);
  lcd.print("Voltage: ");
  lcd.setCursor(13, 1);
  lcd.print("V");
}
void loop()
{
      int val;
      float temp;
      val=analogRead(0);
      temp=val/4.092;
      val=(int)temp;//
      lcd.setCursor(9, 1);
      lcd.print(temp);
/*
      lcd.print(0x30+val/100,BYTE);
      lcd.print(0x30+(val%100)/10,BYTE);
      lcd.print('.');
      lcd.print(0x30+val%10,BYTE);
*/
      delay(100);
}

Result

LCD will display the output voltage from the Power shield.

If you have a multimeter, you can easily read the output voltage through output terminal without the LCD and LCD displaying code. In other words, voltage regulation is independent. Consider it as a normal shield with function of voltage regulation.

Was this article helpful?

TOP