A digital potentiometer is a type of variable resistor that is controlled by digital signals instead of a physical knob. The resistance of the device can be adjusted by sending digital commands to the potentiometer. This allows for precise control over the resistance and eliminates the need for physical access to the device. The MCP4231-103 is a digital potentiometer (also known as a digital rheostat) manufactured by Microchip Technology. It is a non-volatile, single-channel digital potentiometer with an SPI interface. In this example, we'll use an Arduino Uno and the MCP4231-103 digital potentiometer to control the brightness of an LED.
MCP4231-103 SPI Digital Potentiometer
The MCP4231-103 has a 10KΩ resistance range and a resolution of 7 bits, which provides a total of 128 different resistance values. The device is capable of continuously adjustable resistance, allowing for smooth transitions between resistance levels.
The MCP4231 integrated circuit is controlled by issuing command over SPI interface from microcontrollers like Arduino. The SPI interface of the MCP4231-103 allows for easy communication with a microcontroller or other digital devices. The chip select (CS) pin is used to enable and disable communication with the device, while the clock (SCK), data in (SI), and data out (SO) pins are used for SPI communication.
Following shows the Microchip MC4231-103 IC pin out.
Pin Description:- Pins P0A, P0W, and P0B: These are the pins for the first digitally controlled potentiometer.
- Pins P1A, P1W, and P1B: These are the pins for the second digitally controlled potentiometer.
- VDD: Connects to your 5V supply.
- VSS: Connects to ground.
- CS: CS is the SS pin for the SPI interface, and the bar above it indicates that it is active low. (0V means the chip is selected, and 5V means it is not selected.)
- SDI and SDO: These pins correspond to serial data in and out, respectively(a.k.a. MOSI and MISO).
- SCK: This is the SPI clock line that was explained earlier in the chapter.
- SHDN: These stand for shut down and write protect, respectively. The SHDN pin is active low,
like the CS pin. When held low, the hardware “disconnects” the wiper from the internal resistor network. Usually one wants the potentiometer to be always active, so in these examples the SHDN pin is connected directly to 5V. - WP: This is Write Protect pin which is internally not connected(NC) pin. One can ignore this pin.
The MCP4231-103 is commonly used in applications where precise control over resistance is required, such as controlling the brightness of an LED, adjusting the gain of an amplifier, or setting the reference voltage for a sensor. Here for basic demonstration of digital potentiometer usage with Arduino we will simply control the brightness of a LED.
Interfacing SPI MCP4231-103 Digital Potentiometer with Arduino
The following circuit diagram shows how to interface an Arduino with
the MCP4231-103 digital potentiometer and how to connect a LED to the digital pot.
- The MOSI (Master Out Slave In) pin of Arduino is connected to the SDI (Serial Data Input) pin 3 of the digital potentiometer.
- The MISO (Master In Slave Out) pin of Arduino is connected to the SDO (Serial Data Output) pin 13 of the digital potentiometer.
- The SCK (Serial Clock) pin 13 of Arduino is connected to the SCK (Serial Clock) pin 2 on the digital potentiometer.
- The CS (Chip Select) pin on the digital potentiometer is connected to a digital pin (10) of Arduino.
- A LED is connected via a resistor to the P0W wiper pin 9 of the digital potentiometer
- The pin 8 and 10 of the potentiometer are connected to +5V and ground respectively.
- The VDD pin on the digital potentiometer is connected to the 5V supply voltage.
- The GND (Ground) pin on the digital potentiometer is connected to the ground of the Arduino.
Programming
The following is Arduino program that uses the SPI (Serial Peripheral Interface) library to communicate with a digital potentiometer.
#include <SPI.h>
const int csPin = 10;
const byte POT0Address = 0x00;
void setup() {
pinMode(csPin, OUTPUT);
SPI.begin();
}
void loop() {
for (int i = 0; i <= 128; i++) {
digitalWrite(csPin, LOW);
SPI.transfer(POT0Address);
SPI.transfer(i);
digitalWrite(csPin, HIGH);
}
for (int i = 128; i >= 0; i--) {
digitalWrite(csPin, LOW);
SPI.transfer(POT0Address);
SPI.transfer(i);
digitalWrite(csPin, HIGH);
}
}
Here's a brief explanation of the code:
#include <SPI.h>
: This line includes theSPI
library, which provides functions for communicating with a device over SPI.const int csPin = 10;
: This line defines a constant integer variable namedcsPin
and sets its value to 10. This variable represents the chip select (CS) pin on the digital potentiometer, which is used to enable and disable communication with the device.const byte POT0Address = 0x00;
: This line defines a constant byte variable namedPOT0Address
and sets its value to 0x00. This variable represents the address of the digital potentiometer in the SPI communication.void setup()
: This function is called once when the Arduino starts up. It sets thecsPin
as an output using thepinMode
function and initializes the SPI communication using theSPI.begin
function.void loop()
: This function is called repeatedly after thesetup
function has completed. It contains twofor
loops that increase and decrease the resistance of the digital potentiometer by sending SPI data. In each loop, thecsPin
is set to LOW to enable communication with the digital potentiometer, thePOT0Address
and a value ranging from 0 to 128 are sent to the digital potentiometer using theSPI.transfer
function, and thecsPin
is set to HIGH to disable communication with the digital potentiometer.
In conclusion, the MCP4231-103 digital potentiometer is a versatile and simple component that can be easily interfaced with an Arduino microcontroller. It allows for precise control of resistance values in a circuit, which can be useful in a wide range of applications, from LED brightness control to motor speed regulation. The use of the SPI library in Arduino makes it easy to interface with the potentiometer and adjust resistance values with a few lines of code. Whether you're a beginner or an experienced maker, the MCP4231-103 digital potentiometer is a great addition to your toolkit and can help you create exciting projects with ease.
References: