Raspberry Pi - ADC
This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://newbiely.com/tutorials/raspberry-pi/raspberry-pi-adc
The Raspberry Pi has no built-in analog input pins, so it can't read sensors like potentiometers, thermistors, or gas sensors directly. This guide shows how to add an ADS1115 ADC module to a Raspberry Pi 5 so it can read analog values over I2C, using a potentiometer as the example sensor.
Supplies
Everything below is what the build uses. The links go to the parts we make and test.
- Raspberry Pi 5
- ADS1115 ADC Module
- Potentiometer
- Breadboard
- Jumper Wires
- Screw Terminal Block Shield for Raspberry Pi
- Raspberry Pi Prototyping Base Plate & Breadboard Kit
- DIYables Sensor Kit (18 sensors/displays)
- DIYables USB Type-A to Type-B Cable
Wiring
Connect the ADS1115 module to the Raspberry Pi using the I2C bus. Wire the potentiometer's analog output to one of the ADS1115's four input channels. You can wire other analog sensors such as a light sensor, water sensor, or soil moisture sensor the same way, since the ADS1115 supports up to four analog sensors at once on its four channels. For a cleaner setup, use a Screw Terminal Block Shield on the Raspberry Pi to secure all the connections instead of loose jumper wires.
How It Works
The ADS1115 is a 16-bit ADC with four analog input channels that communicates with the Raspberry Pi over I2C. It reads analog signals in the 0-3.3V range and converts them into a 16-bit digital value the Pi can process, since the Pi itself has no analog input pins. Because it has four channels, a single ADS1115 can serve up to four analog sensors at the same time, though this tutorial wires up just one.
Code
Before coding, enable I2C on the Raspberry Pi with sudo raspi-config, under Interfacing Options > I2C, then reboot. The Python script uses the Adafruit_ADS1x15 library to initialize I2C communication and create an ADS1115 object that reads the 16-bit value from the chosen channel. The script loops continuously, reading and printing the analog value to the terminal once per second so you can watch the sensor respond in real time.
raspberry-pi-adc.py - the sketch from the tutorial, unchanged.
Full Tutorial
The complete tutorial, wiring diagram and code explanation: https://newbiely.com/tutorials/raspberry-pi/raspberry-pi-adc