Example Code for Raspberry Pi – Analog Voltage Monitoring Module

Last revision 2026/01/20

This article provides a detailed guide and example code for using a Raspberry Pi with an analog voltage monitoring module, explaining the connection, programming, and adjustment process to effectively monitor power levels in interactive media works or robot power supplies.

Introduction

Based on the resistance divider principle, this voltage monitoring sensor can be used with the Arduino sensor expansion board to detect the voltage and power level, monitoring the power of interactive media works or the robot power supply.

This module can reduce the input voltage by 5 times. Since the maximum Arduino analog input voltage is 5 V, its input voltage cannot be greater than 5 V × 5 = 25 V.

Hardware Preparation

Wiring Diagram

  • Connect the Raspberry Pi correctly to devices such as the screen, power, keyboard and mouse.

  • Connect the pin of this module to pin 0 on the Analog board of the Raspberry Pi expansion board. The schematic diagram is as follows.

  • Connect a power to power it on. The wiring diagram is as follows.

Sample Code

  • Open the system to enter the terminal

  • Install Python dependency libraries and git, and you need to get your Raspberry Pi connect to internet for this step(skip if installed). In the terminal, type the following instructions and press ‘Enter’
    sudo apt-get install build-essential python-dev python-smbus git

  • Download the drive library and program.
    git clone https://github.com/DFRobotdl/111.git

  • Find DFR0051.py in the file you just downloaded before, click to run it

  • Adjust the input voltage, then the analog port will read it.

Was this article helpful?

TOP