Introduction: Digital Potentiometer MCP41100 and Arduino
We know the analog potentiometer , is a three-terminal resistor with a sliding contact that forms an adjustable voltage divider .
Potentiometers Many application such like :
1)volume controls on audio equipment.
2) Control the amplifier Gain and offset .
3) Transducer " displacement transducers ".
and many Other application , But did you you want to control the resistance value by Microcontroller instead of using analog one ?
Analog potentiometers have some problem with MCU , Microcontroller doesn't have an easy way to interface with them .
The Digital Potentiometer , give you an ability to adjust the resistance ,allowing you to control a voltage splitter with digital signals
In this simple instructable I will show you how to control Digital Potentiometer MCP41100 Using Arduino IDE .
Step 1: Material
we will need :
1) Arduino Board .
2)Digital Potentiometer MCP41100 .
3)Resistor 100 Ohm
4)LED
5)BreadBoard.
6JumperS
The pin Configuration for MCP41100 above , very easy .
Data sheet for MCP41100 here
This IC using SPI Protocol to communicate with Arduino Board .
Step 2: Calculate the Resistance .
Ok , now we will look at this table , which is show who we can Calculate the Output resistance .
MCP41100 Have a sensitivity of 8bit , 256 taps for each potentiometer will taken from .
The MCP41100 Nominal resistane equal 100K ohm "Rab" and from the Datasheet , The wiper resistance is 125 ohm"Typical" ,
For example , if we write 222 to MCP41100 ,The resistance will equal :
Rwa= (100*10^3)*(256-222)/256 + 125 = 13.41K ohm . (corrected by Spacebrain,big thanks )
Step 3: Arduino Code
/*
this program taken from arduino Example .
modified by By Mohannad Rawashdeh
http://www.genotronex.com
https://www.instructables.com/
This code used to control the digital potentiometer
MCP41100 connected to arduino Board
CS >>> D10
SCLK >> D13
DI >>> D11
PA0 TO VCC
PBO TO GND
PW0 TO led with resistor 100ohm .
*/
#include <SPI.h>
byte address = 0x11;
int CS= 10;
int i=0;
void setup()
{
pinMode (CS, OUTPUT);
SPI.begin();
// adjust high and low resistance of potentiometer
// adjust Highest Resistance .
digitalPotWrite(0x00);
delay(1000);
// adjust wiper in the Mid point .
digitalPotWrite(0x80);
delay(1000);
// adjust Lowest Resistance .
digitalPotWrite(0xFF);
delay(1000);
}
void loop()
{
for (i = 0; i <= 255; i++)
{
digitalPotWrite(i);
delay(10);
}
delay(500);
for (i = 255; i >= 0; i--)
{
digitalPotWrite(i);
delay(10);
}
}
int digitalPotWrite(int value)
{
digitalWrite(CS, LOW);
SPI.transfer(address);
SPI.transfer(value);
digitalWrite(CS, HIGH);
}
Step 4: Simple Applications :Motor Drive Controller and LED Controller
the arduino Code :
/*
this program taken from arduino Example .
modified by By Mohannad Rawashdeh
http://www.genotronex.com
This code used to control the digital potentiometer
MCP41100 connected to arduino Board
CS >>> D10
SCLK >> D13
DI >>> D11
PA0 TO VCC
PBO TO GND
PW0 TO led with resistor 100ohm .
*/
#include <SPI.h>
byte address=0x11;
int CS= 10;
void setup()
{
pinMode (CS, OUTPUT);
SPI.begin();
// adjust high and low resistance of potentiometer
// adjust Highest Resistance .
digitalPotWrite(0x00);
delay(1000);
// adjust wiper in the Mid point .
digitalPotWrite(0x80);
delay(1000);
// adjust Lowest Resistance .
digitalPotWrite(0xFF);
delay(1000);
}
void loop()
{
for (int i = 0; i <= 255; i++)
{
digitalPotWrite(i);
delay(10);
}
delay(1000);
for (int i = 255; i >= 0; i--)
{
digitalPotWrite(i);
delay(5);
}
}
int digitalPotWrite(int value)
{
digitalWrite(CS, LOW);
SPI.transfer(address);
SPI.transfer(value);
digitalWrite(CS, HIGH);
}
Video :
30 Comments
2 years ago
This type of connection can be also done for hardware spi as the same as for PIC32 SPI interface
Question 2 years ago
How can I control the DigiPot with a digital sensor like the Sunfounder DS18b20?(https://www.sunfounder.com/ds18b20-temperature-sensor-module.html)
3 years ago
Note that on a mega the pins are different !
See https://www.arduino.cc/en/reference/SPI
Pins 51 and 52 instead of 11 and 13
3 years ago
Great project but how can I use 2 or more digital potentiometer ?
Question 4 years ago
Hello
I am working on a CNC machine. I am using a brushless dc motor as a spindle ( Motor specs. 18V, 30A, 21000rpm).
I will be using a motor driver to control the spindle motor.
Driver specs:
Working Voltage: DC 10-50V
Output Voltage: Linearity Under Load
Maximum Current: 60A
Persistent Current: 40A
Fixed frequency: 25Khz
Speed Control Range: 0%~100%
Speed Regulation Method: Potentiometer (Tape Switch)
Speed Control Type: Regulating Current
Forward Reversal: Support
Support Motor: DC Brush Motor
(Driver board link : https://www.banggood.com/DC-10-50V-122448V-60A-PW... )
But the problem is the driver board uses a 10K pot, and my cnc controller board gives out PWM singal via only two pins i.e +10V and GND. so how do i connect those two PWM pins to the microchip to eleminate the pot on the motor driver board and control it digitally. I am using an eleksmaker mana 3 axis board as a controller.
(Board link: https://www.banggood.com/3-Axis-Stepper-Motor-Dri... )
I am a beginner in electronics so i request you to a bit detailed.
Thank you
Answer 3 years ago
Hi,
the method above what was written by Mohammad suitable for you, only change MCP41100 to MCP41010. It is 10k digital pot.
You can buy here: https://www.aliexpress.com/item/32558521843.html
Maybe you can use PWM to voltage module, looks like this one: https://www.aliexpress.com/item/32800628563.html
Or you should make a low pass filter, here is the tutorial: https://www.allaboutcircuits.com/technical-article...
Good luck! :)
4 years ago
Hi
how do we control this nodemcu ? can we use it on a standalone with mobile hotspot connection. if so, can you pls give me the info
4 years ago
nice
Question 4 years ago on Introduction
Hello Mohannad.
Could you please say what software do you use for electric circuit drawing?
5 years ago
Thanks for this, great work!
I just noticed a small mistake:
Rwa= (100*10^3)*(256-222)/256 - 125 = 13.41K ohm
It should be:
Rwa= (100*10^3)*(256-222)/256 + 125 = 13.41K ohm
Reply 5 years ago
wow you are right I'm sorry I didn't notice that , I corrected as well
Many thanks
5 years ago
Hello, thanks for this instructable. Il bought a bunch of MCP4110 but If was wondering how to connect a LED strip? Can I connect a 12v directly on the digipot ?
Reply 5 years ago
no it will not work on this way , this potentiometer can works with Low power application , if you connect it directly to LED strip it will blow up for sure .
try using PWM using Mosfet / Fet transistor to control Led strip brightness (that's what you want to do , right ?)
Reply 5 years ago
Ok thank you!
Is PWM a component? I read things about PWM but I don't get the how to...
I will soon receive a MOSFET I will be able to try.
How did you control the led in the video?
Reply 5 years ago
PWM(Pulse width modulation) is a method(Technique) to control a DC Voltage , and you can achieve that in different ways(like using Transistor).
In my video , you can see that I connected MCP41100 to 555 timer which act as a PWM controller , MCP41100 connected to the control side not to the High power side(you can see the schematic for more details).
hope that's clear for you , and if you have another question I will be happy to answer it
9 years ago on Introduction
How did you determine the address (byte address = 0x11)? Does 0x11 mean it's 17 in decimal? Could you explain that please?
Thanks
Reply 6 years ago
I know this is an old thread, but I just discovered it, it was useful to me, and I spent an hour trying to figure out where the address came from as well.
From what I understand, you need to send a command byte followed by the data byte. The command byte has the format "00CC00PP" where the CC gives command summary and PP gives the Pot selection. CC of 01 is "write data byte to potentiometer" and PP of 01 is "execute command on pot 0". This gives 00010001, which would be the decimal value of 17.
7 years ago
what is the program your using for your schematic diagrams?
Reply 6 years ago
Fritzing
6 years ago
Mohannad-thank you very much. Good work.