loading
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

T
his 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 .


Step 3: Arduino Code

The arduino Code  below :

/*
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

This Is a simple example to control the speed of DC Motor using555 timer  ,  PWM Technique

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 :





How did you determine the address (byte address = 0x11)? Does 0x11 mean it's 17 in decimal? Could you explain that please? <br>Thanks
<p>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. </p><p>From what I understand, you need to send a command byte followed by the data byte. The command byte has the format &quot;00CC00PP&quot; where the CC gives command summary and PP gives the Pot selection. CC of 01 is &quot;write data byte to potentiometer&quot; and PP of 01 is &quot;execute command on pot 0&quot;. This gives 00010001, which would be the decimal value of 17.</p>
what is the program your using for your schematic diagrams?
<p>Fritzing </p>
<p>Mohannad-thank you very much. Good work.</p>
<p>I am wonting to controle the DigiPot with a analogue pot. how do you change the resistance of the digiPot. I am using thew MCP41100 and a Arduino. can any one help???????????</p>
<p>Use map command and map value like (0,1024,1,128)</p>
<p>I tried implementing the circuit using mcp4131 and the potentiometer didnt switch ON the bulb connected to it. I measured the resistance to check whether the code was actually varying it, and discovered that it was static at 5k(4131 has total resistance of 10k). I decided to run the code on proteus but it seemed like proteus doesn't recognize the SPI library, cos the pin 13 and pin 11 remained static without producing any changing output. Pls i need some guidance</p>
<p>To get this to work with the Leonardo you need to wire the SCK pin from the MCP41100 to ICSP#3 and the SI pin to ICSP#4. Everything else works just fine so the Leonardo only needs that minor change. </p>
<p>Hi Mohannad </p><p>i just wanted to ask if there is a way to define the range of the digital pot for example in the analogue one we goes from 0 to 1K ohm so it is marked as 1k pot (in my case) so how i can know this from the digital pot ? </p><p>Thanks in advance</p>
<p>Hello and thank you for this very nice example to control the speed of DC Motor using PWM + 555 timer. I'd like to ask a few questions:</p><p>1) is the digital potentiometer necessary or would it possible to use a RC filter like this (http://www.avdweb.nl/arduino/hardware-interfacing/super-simple-dac.html)?</p><p>2) In any case, how do you make it direct (ie increasing PWM increases motor speed)? I'd like my motor to stop in case the arduino is not connected</p>
<p>Hello and thank you for this very nice example to control the speed of DC Motor using PWM + 555 timer. I'd like to ask a few questions:</p><p>1) is the digital potentiometer necessary or would it possible to use a RC filter like this (http://www.avdweb.nl/arduino/hardware-interfacing/super-simple-dac.html)?</p><p>2) In any case, how do you make it direct (ie increasing PWM increases motor speed)? I'd like my motor to stop in case the arduino is not connected</p>
Hi RichardBronosky <br> <br>Yes I use 555 timer as PWM generator , Not arduino's PWM. <br>There is no sensor on my code ! You can Adjust Pot immediately By Using Interrupt , For example , If sensor Value reach to a critical value or change it's state the Interrupt change the Potentiometer value immediately . <br>yes , for full stop write : digitalPotWrite(255); Or digitalPotWrite(0xFF); No additional Switch required . <br>last Question I didn't understand what do you mean by Same supply ?! PWM Consume a lot of power greater than arduino consume , You can put arduino in Idle mode if no change on action &quot;Same speed I mean &quot; but not save a lot of power as you assume . <br> <br>PWM used AVR Timer , you will need Timer to operate RF , Servo , LED Driver , You will need the PWM For these device , and control the Motor using PWM With 100KHz frequency More accurate than Use arduino's PWM 490Hz frequency !
Please clarify a few things for me as I am very new to all this. You are using a &quot;PWM Technique&quot;, but from your code it looks like you are not using Arduino's PWM. So you are using the 555 timer to generate the pulses, right? [1] If so, this means that the Arduino could sleep for 1 minute in between taking sensor readings and making adjustments to the digital potentiometer and the motor would continue at a constant rate in between, right? [2] Is there a value the the arduino could send the circuit to set it to full stop, or will that require and additional switch? [3] Finally, considering that I will be powering a motor on the same supply, it there really any point in trying to save power by sleeping the Arduino? [4] I ask that because I could do the PWM in the Arduino a save a lot of complexity. <br> <br>Thank you so much for all this!

About This Instructable

96,320views

90favorites

License:

Bio: Maker, PCB designer , electronics instructor from Jordan just one word ! I Adore electronics follow me on FB https://www.facebook.com/Mohannad-Rawashdeh-Raw-774983565988641/
More by Mohannad Rawashdeh:TTP224 Digital Touch Sensor Applications Using Arduino RF 315MHz/433MHz Wireless and Arduino...again! Motor Driver BTS7960 43A 
Add instructable to: