IAN LANG ELECTRONICS

The Rheostat

 

Don't confuse potentiometers with rheostats. A rheostat has two terminals and produces a varying current by increasing or decreasing the resistance between them.

 

The Potentiometer or Pot for Short

 

The potentiometer has three terminals. Two are on the outside and one is in the middle; the latter is known as the wiper. If one outside terminal and the wiper are connected the potentiometer acts like a rheostat, if both are connected the output from the wiper acts in the manner of a voltage divider. Potentiometers are commonly made from four materials; carbon-made have a typical power rating of 0.5 W, cermet (CERamic and METal) may be as low as 0.25W or as high as 2W, wire-wound types (which are big and heavy and rarely used in electronic applications) can have a rating up to 50W, and conductive plastic up to 0.5W. These values are typical and you must pay attention to the power ratings before you fit a potentiometer. They can easily catch on fire. The symbol for a potentiometer is as below, the wiper is represented by the arrow, though if you look in the Oomlaut book the schematic shows it as a zig-zag rather than a rectangle. The zig-zag is the American (and now increasingly Chinese) standard symbol, the rectangle the European. Potentiometers can be logarithmic or linear. Linear ones change their resistance uniformly, logarithmic ones change slowly at one end and quickly at the other. The logarithmic is used for volume controls.

 

                                                                                         

 

 

 

The Trimmer and Preset.

CIRC-08

Go Back

This is the second circuit in which Oomlaut deal with analogue inputs and it's a good construct, easily put together and well explained.

It introduces the potentiometer (though in these pages we've seen it before now) in a nice easy way and gives some practical circuits with which you can control the output of the Arduino. Let's have a look at these, then, but first we're going to build the circuit as it appears in the book.

 

It's a fairly easy construct, the potentiometer, if you haven't used it before, can be a bit fiddly though. Just make sure the two outside pins are connected to 5V and GND and the middle to A0 on your Arduino board.

This potentiometer supplied is a breadboard compatible one, it has much longer pins than the standard ones, and so if you're buying another for later experiments make sure you get another breadboard compatible one because the standard ones are horrible to use on a breadboard. Measuring the resistance range, this one goes from 0.1 ohms  to 9.5 kilohms. It looks linear, and small pots like this usually are.

The terms above may make no sense to you whatsoever, but fear not, because we before we dive in and work the Arduino, we'll look at what a potentiometer actually is.

The Potentiometer as a Voltage Divider

 

If we attached the outside terminals of a pot to the power supply between Vs and V0 then we can take Vout from the wiper. The pot is acting as two fixed resistors in series and each of the resistors varies in proportion with the other as we turn the shaft. Thus we can actually control a loaded voltage divider with a great degree of accuracy.  In fact in this circuit that's just what we are going to do. Vs in our case is 5V and 0V is GND. Vout is what's going to the Arduino board.

These are usually very small cermet or carbon potentiometers used in a circuit and not exposed to the end user. They are used where a current or voltage needs to be limited to a pre-determined value and due to factors this value cannot be directly predicted. The output of a signal to a television set may need to be attenuated a little, and a preset would be used for this purpose. The symbol is as below, and the picture shows a selection. A multi-turn, as on the right, is very sensitive. It's also breadboard compatible: look at the much longer pins.

European symbol for a potentiometer

A standard size pot for electronic work which can deal with a couple of  Watts.  Pots are also known as three terminal variable resistors, dividers, adjusters and if you're my wife finding one on the kitchen floor, "a little twisty thing".

Voltage Divider

It is at this point you are saying  "Pah! Enough of these theoretical concerns, Lang, we want to get our hands dirty! Show us some code, you scoundrel!" and so, just to oblige here's the first lot, shorn of all the REM statements at the top:

 

int sensorPin = 0;    // select the input pin for the potentiometer

int ledPin = 13;      // select the pin for the LED

int sensorValue = 0;  // variable to store the value coming from the sensor

 

void setup() {

  // declare the ledPin as an OUTPUT:

  pinMode(ledPin, OUTPUT);  

}

 

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);    

  // turn the ledPin on

  digitalWrite(ledPin, HIGH);  

  // stop the program for milliseconds:

  delay(sensorValue);          

  // turn the ledPin off:        

  digitalWrite(ledPin, LOW);  

  // stop the program for for milliseconds:

  delay(sensorValue);                  

}

 

Before you upload turn the pot so that it's about halfway round it's distance of travel. When you've fired up your board, Here's what will happen:

 

The LED will flash.

 

er.....that's it. But this is a blinky with a difference. If you turn the pot first one way and then the other the LED will flash either more quickly or slowly depending on which way you're turning it. If not check your wiring to and from the pot, it's easy to put one in the wrong place.

 

So, this is achieved obviously by switching the LED on and off rapidly. How are we telling your board, or more specifically the ATmega chip that resides in your board, to do this? Let's go through the code bit by bit.

 

int sensorPin = 0;    // select the input pin for the potentiometer

int ledPin = 13;      // select the pin for the LED

int sensorValue = 0;  // variable to store the value coming from the sensor

 

void setup() {

  // declare the ledPin as an OUTPUT:

  pinMode(ledPin, OUTPUT);  

}

 

void loop() {

 // read the value from the sensor:

  sensorValue = analogRead(sensorPin);    

  // turn the ledPin on

  digitalWrite(ledPin, HIGH);  

  // stop the program for milliseconds:

  delay(sensorValue);          

  // turn the ledPin off:        

  digitalWrite(ledPin, LOW);  

  // stop the program for for milliseconds:

  delay(sensorValue);                  

}

 

 

if you've done the previous seven lessons first of all thank you and second of all you'll have a pretty good idea of what this lot is doing by now. If not:

The first three lines are setting variables; you can see what they do by the REM statements following the // mark.  The function void setup ( ) is the one that only runs once, on power-up, and tells it that we're going to use pin 13 as an output.

 

 

 // read the value from the sensor:

  sensorValue = analogRead(sensorPin);    

  // turn the ledPin on

  digitalWrite(ledPin, HIGH);  

  // stop the program for milliseconds:

  delay(sensorValue);          

  // turn the ledPin off:        

  digitalWrite(ledPin, LOW);  

  // stop the program for for milliseconds:

  delay(sensorValue);                  

}

 

All of that lot flashes the LED on and off. Now, when we turn the pot, we're acting like we have two fixed resistors in series totalling 10 kilohms. As we turn it, we still have 10k, but it's split over two resistors, so if we turn it a bit, one might equal 9k and the other 1k. Let's call them R1 and R2. There's a formula to calculate how much voltage will come out of the junction (in our case the wiper) of a voltage divider. It's:

 

Vout = (R1 /(R1+R2))Vs

 

It's not that scary, I promise. In the above case, R1 is 9k and R2 is 1k  and if you add them together you get 10k, so that makes the equation Vout =(9000/10000)Vs or, since they're both thousands, we can cancel out the last three zeros on both and get  Vout=(9/10)Vs. 9/10= 0.9 and so Vout=(0.9)Vs, Vs is the supply voltage and we're supplying it from the 5V terminal on the board and so Vout=(0.9)5 or if you like it better that way, Vout = 0.9 X 5 and that equals 4.5V.

 

If we turned the pot exactly to the centre we'd still have 10k in total but now both R1 and R2 are equal, and so 5K each.  In four steps then:

 

Vout = (5/ 5+5)5 ;    Vout= (5/10)5;   Vout = (0.5)5   Vout= 2.5V

 

Turning it a bit more, R1 =3k and R2 =7K  and

 

Vout = (3/10)5 ;  Vout=(0.3)5;   Vout=1.5V

 

If we turn it to the top, R1=0 and R2 = 10k . If you divide 0 by anything, you get zero. if you multiply by zero, you still get zero.

 

Vout =(0/10)5;  Vout= (0)5 Vout= 0V

 

 

The pot of course could be anywhere between full down and full up, and the voltage at the wiper can be any number between 0 and 5V. It can't be higher than 5V because that's all were supplying it with. This voltage is sent to your Arduino board as a reference.

 

The story doesn't end here. Your Arduino board does not count in volts, it counts in millivolts. So although zero volts is in fact zero millivolts too, 2 Volts is in fact 2000 mV. 3.78V is 3780 mV. You get the idea, multiply by 1000.

But it doesn't use these millivolts directly either. Oh no. That'd be easy. The Arduino board is a digital device, and the reference voltage is an analogue one. So what it does is it samples the analogue voltage and parcels it up into 1024 discrete steps. Then it selects which parcel to use.  5V is the top, so that's 500mV and if 5000 mV =1024 (the value of the top parcel) and each parcel has an equal millivoltage to it; so x =5000/1024 = 4.89 and so the upper limit for each parcel is 4.89 mV.

 

 

If that seems like gibberish to you, allow me to elucidate.  If the input at A0 was 4.7mV, that would return a value of 1 in discrete digital values. If it were 4.89mV , it would still be 1. If it were 4.92, that value digitally would be 2. If it were 14.58 mV it would be three, because 4.89 X 2 is 9.78 and 14.58 is greater than that, and 4.89 X 3 is 14.67 and 14.58 is lesser than that. If it then went up to 14.87mV, that's greater 14.67 but lesser than 19.56 (4X 4.89) and so into 4 it goes.

 

Armed with this knowledge, let's have a peep at the code line by line and assume that we've got 3V (or 3000 mV, it's the same thing) hitting A0. It starts over the page, so print the code out if  you find it any easier to follow that way.

 

 

 

 

 

 

 

 

 

More > Copy & Paste Code from Here: