Example Code for Raspberry Pi – Analog Rotation Sensor

Last revision 2026/01/20

This guide explores the use of the Analog Rotation Sensor V2 with Raspberry Pi, detailing installation, connection, and code execution for precise angle control, utilizing a multi-turn precision potentiometer to subdivide voltage into 1024 parts.

Introduction

As the rotation angle of the ordinary potentiometer is only 300 degrees at most, the accuracy is quite low after distributing the 5V power supply of Arduino to every 1 degree.

So if you want to make a project with precise control of angle or analog quantity, this precision angle sensor is a good choice. Based on a multi-turn precision potentiometer, this sensor can be rotated about 10 turns and subdivide the voltage into 1024 parts. What’s more, it can be combined with the sensor expansion board through the 3P connection line, accurately sensing small changes in rotation.

*This product has been updated. Please refer to the product wiki at the bottom of the page for the specific line sequence of the V2 version. For V1 version, please connect according to the "1, 2, 3" marked on the module's silk screen.

Wiring Diagram

  • Power the Raspberry Pi on and install the Raspberry Pi expansion board correctly
  • Connect the sensor to the analog port 0 on the expansion board

Sample Code

  • 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

  • Install the drive library and program. In the terminal, type the following instructions and press ‘Enter’
    cd \~

git clone https://github.com/DFRobotdl/37\_Pcs\_Sensor.git

  • Find Analog_Rotation_Potentiometer_Sensor_V2.py in 37_Pcs_Sensor\6_Analog_Rotation_Potentiometer_Sensor, open it with Thonny Pyth IDE and run it, you can see the printed analog value, which will change if you rotate the sensor.


Was this article helpful?

TOP