Ten Bar Level Voltage Meter with a LM3914
Here is a MicroPython project for reading a potentiometer value and displaying it on a 10-segment LED bar using the LM3914 chip with a Raspberry Pi Pico. Let's break this down into the circuit description and code implementation.
Raspberry Pi Pico
This project uses a Raspberry Pi Pico to read an analog voltage from a potentiometer and display the voltage level on a 10-segment LED bar graph controlled by an LM3914 display driver chip.
Components Needed
- Raspberry Pi Pico
- LM3914 LED bar/dot display driver IC
- 10-segment LED bar graph (or 10 individual LEDs)
- 10kΩ potentiometer
- 1kΩ resistor for LM3914 current limiting
- Breadboard and jumper wires
- Micro USB cable for programming the Pico
Circuit Description
The circuit consists of three main parts:
- Potentiometer Input: Connected to the ADC0 pin (GPIO26) of the Raspberry Pi Pico
- Raspberry Pi Pico: Reads the analog value and controls the LM3914
- LM3914 Display Driver: Controls the 10-segment LED bar graph
Breadboard Layout
1. Power Rails
- Connect 3.3V from Pico to the breadboard power rail
- Connect GND from Pico to the breadboard ground rail
2. Potentiometer
- Connect the outer pins to 3.3V and GND respectively
- Connect the middle pin (wiper) to GPIO26 (ADC0) on the Pico
3. LM3914 Connections
- Pin 1 (LED1): Connect to first LED in the bar graph
- Pin 2-9: Connect to respective LEDs in the bar graph
- Pin 10 (LED10): Connect to the last LED in the bar graph
- Pin 11 (V-): Connect to GND
- Pin 12 (SIG): Connect to GPIO16 (used as PWM output from Pico)
- Pin 13 (REF OUT): Not connected
- Pin 14 (REF ADJ): Connect to GND through a 1kΩ resistor for current limiting
- Pin 15 (MODE): Connect to 3.3V for bar graph display mode (or to GND for dot mode)
- Pin 16 (V+): Connect to 3.3V
- Pin 17 (RHI): Connect to 3.3V
- Pin 18 (RLO): Connect to GND
How The Level Meter Works
Circuit Operation
-
The potentiometer acts as a voltage divider, providing a variable voltage between 0V and 3.3V to the ADC0 pin of the Raspberry Pi Pico.
-
The Pico's ADC converts this analog voltage to a digital value (0-65535 for 16-bit resolution).
-
The MicroPython code reads this value and maps it to a PWM duty cycle.
-
The PWM output from GPIO16 is connected to the SIG pin (pin 12) of the LM3914.
-
The LM3914 compares this signal voltage to its internal reference voltage and lights up the appropriate number of LEDs in the bar graph.
-
With proper calibration, turning the potentiometer will cause the LED bar to display the corresponding voltage level.
Sample MicroPython Code
Here's the MicroPython code to read the potentiometer value and control the LM3914:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
Code Explanation
- We use the ADC (Analog-to-Digital Converter) on GPIO26 to read the potentiometer value.
- We use PWM (Pulse Width Modulation) on GPIO16 to generate an analog-like voltage for the LM3914's SIG pin.
- The
map_value()
function converts the voltage reading range to the PWM duty cycle range. - The main loop continuously reads the potentiometer value, updates the PWM duty cycle, and displays debugging information.
Additional Notes
-
Filtering: You might want to add a small capacitor (e.g., 0.1µF) between the PWM output and the LM3914 SIG pin to smooth out the PWM signal.
-
Mode Selection: The LM3914 can operate in either "bar" mode or "dot" mode:
- Connect pin 15 to 3.3V for bar mode (multiple LEDs lit)
-
Connect pin 15 to GND for dot mode (only one LED lit)
-
Current Limiting: The 1kΩ resistor connected to pin 14 limits the current through the LEDs. Adjust this value to change the LED brightness.
-
Alternatives: If you don't have an LM3914, you could directly control 10 LEDs from 10 GPIO pins of the Pico, but the LM3914 approach is more elegant and uses fewer pins.
This project demonstrates how to interface analog components with the Raspberry Pi Pico using MicroPython, combining ADC input, PWM output, and external display driver circuits.