software

How to use a potentiometer in arduino to measure voltage power on a plate? Step-by-step guide

If you have worked with Arduino you have probably already heard about what potentiometers are, a very useful element in this platform that allows you to carry out different types of projects, such as regulating the intensity of the light of an LED screen, controlling the position of a servo or in this case the speed of a motor. And it is that it has become one of the most common components used in this electronic platform.

Therefore, potentiometers are devices that will be used frequently to input analog values ​​into the Arduino board, so they can be used in a wide variety of electronic projects. It should be mentioned that they also have the ability to limit the flow of electrical current in a variable way.

In this way, these devices allow modifying the value of the current and the  voltage  simply by varying the value of the resistance . In accordance with everything mentioned so far, here we are going to teach you a little more what these components are in Arduino and how you can start using them, for this follow in detail everything that we are going to teach you next in the post.

What is a potentiometer and what are all the types that exist?

They are considered as a device that allows its resistance to be varied manually between what is a minimum value and a maximum value (Rmin – Rmax) in the case of the most common minimum values ​​is 0 ohms, while in the maximum values ​​the most common are 5k, 10k or 20k ohms .

These devices are internally constituted by a moving contact that moves along a resistive track. In this way, when the potentiometer is moved, the contact moves along the track and it will vary the length of the track section with which contact is being made, which causes the resistance to vary. Potentiometers typically have three terminals, where two ends are attached to either side of the track .

So both will always register the maximum resistance Rmax . While the remaining terminal will correspond to the mobile contact . In the case of this terminal, the resistance is varied with respect to the other two terminals as the potentiometer is activated, thus being the sum of the resistance to the other terminals equal to the maximum resistance . It should also be mentioned that the potentiometers serve to limit what is the flow of electric current in a variable way.

Causing a voltage drop in relation to resistivity. In the same way, it allows modifying the value of the current and voltage by simply varying the value of the resistance. When it comes to controlling current and voltage levels within an electrical circuit, the potentiometer should be used. That is why it has an exclusive and characteristic use in those projects of luminosity in LED , LCD, among others.

It is also essential to mention that there are different types of potentiometers and which we are going to show you next in the post:

Control potentiometers

This type of device is the most suitable to be used as a voltage control element for electronic devices . For this, the user must act on them in order to vary the normal operating parameters, such as the volume of a sound system.

In addition, there are different types of this control potentiometer such as the following:

  • Slide potentiometers: In this case the resistive track is straight, so the cursor’s path will also be straight. They have been in vogue for some time now and are mostly used in graphic equalizers, since the position of their cursors represents the response of the equalizer. However, it should be mentioned that sliders are more fragile than rotary ones and take up more space and are also usually much more sensitive to dust.
  • Rotary potentiometers: They are controlled when its axis rotates, these are the most common, since they are long-lasting and take up much less space than sliders. In addition, it should be mentioned that they are much more resistant.
  • Multiple potentiometers: These are several potentiometers with coaxial shafts, in this way they end up taking up very little space. For this, instrumentation, car radios, among many others are used.

Adjustment potentiometers

They are in charge of controlling the preset voltage, normally at the factory . In this case, users should not retouch, so it is not usually accessible from the outside. There are many encapsulated in plastic as many without capsules, and they usually distinguish vertical adjustment potentiometers, where their rotation axis is vertical and horizontal adjustment potentiometers with the rotation axis parallel to the printed circuit.

According to the law of variation of resistance, the following aspects are observed:

  • Logarithmic variation: The resistance will depend logarithmically on the angle of rotation, this is called with the letter A according to current regulations, since previously it was done with the letter B.
  • Linear variation: The resistance is directly proportional to the angle of rotation, currently it is called with the letter B, since before it was done with the letter A.
  • Sinusoidal variation: In this case the resistance is proportional to the sine of the angle of rotation, where two sinusoidal potentiometers integral and rotated at 90 ° can provide the sine and cosine of the angle of rotation.
  • Anti-logarithmic variation: Here the resistance is directly proportional to 10 with power the angle rotated, it is generally called with the letter F.

Printed potentiometers

In this case, the resistance law is achieved by varying the width of the resistive track, while in the case of windings the curve is adjusted to sections with wires of different thickness.

Multiturn potentiometers

To carry out fine adjustments to the resistance, there are multiturn potentiometers, in this case the cursor is attached to a multiplier screw  , so that to complete the stroke it takes several turns of the control unit.

Digital potentiometers

This is the name given to an integrated circuit where the operation simulates that of an analog potentiometer . It consists of a resistive divider of n + 1 resistance with its n intermediate points connected to an analog multiplexer that selects the output. All this is handled through a serial interface and usually has a tolerance of around 20% and to all this it is necessary to add the resistance due to the internal switches known as Rwiper.

In this case the most common values ​​are 10k and 100k, although this may vary depending on the manufacturer with 32, 64, 128, 512 and 1024 positions on a linear or logarithmic scale . This is handled by several manufacturers, but the main ones in them are Intersil, Maxim and Analog Devices . These devices have the same limitations as DAC converters, such as the maximum current they can drain, which is in the order of mA, INL and DNL .

What is a potentiometer for and why should you use it when working with Arduino?

Potentiometers are an electronic component very similar to resistors, but this time with a resistance value that instead of being fixed is variable, thus allowing to control the intensity of current throughout a circuit by connecting it in parallel and the drop in voltage. series connected voltage. It can also be said that they are very similar to rheostats, but the difference in this case is that the rheostat dissipates more power and is used for circuits with a higher current.  

Accordingly, potentiometers are used mostly to vary the voltage in a circuit placed in parallel, while rheostats are used in series to  vary the current. Therefore, it can be said that the potentiometers are used to introduce analog values into the Arduino board allowing a complete action to be carried out together with other components.

One of its functions may be the following:

  • They allow varying the speed of a motor, regulating the intensity of light or varying the position of a servomotor.

In this way it can be said that potentiometers are devices that are used very frequently to modify the desired variables, either voltage or current . This is how it is very important to be able to know the resolution of the Arduino card, since having a resolution of 10 bits means that it has a maximum value of 1024. Taking all this into account, we will teach you how to use it in Arduino from scratch .

Learn step by step how to use a potentiometer with Arduino from scratch

Considering everything mentioned previously in the post, here we are going to teach you how to use the potentiometer with Arduino from scratch , bearing in mind that this is a component that will be very useful when creating and programming projects from this platform.

To do this, follow each of the steps that we are going to teach you below:

Using the potentiometer with an Arduino board

In the case of working with the Arduino UNO board, it can have 6 analog pins, they range from A0 to A5 and their most common use is to read data from analog devices such as the potentiometer. Here a 10-bit resolution is achieved , which implies that there are 1024 different values, that is, that a range of voltages ranging from 0V to 5V can be read, detecting possible changes in voltages of 0.004V (5/1024). .

In this way, the values ​​that will be obtained from going from 0 to 1023 . So that you can understand all this better, here we are going to show you an example through the serial monitor where you can see what values ​​are obtained on an analog pin according to how the position of the potentiometer is modified.

In the following image you can see the connection:

The code

Keep in mind that you must upload a code to the board, in this case you must upload the following code:

// Variable where we will store the value of the potentiometer

Long value;

Void Setup () {

// we initialize the serial communication

Serial.begin (9600)


// We write start messages on the serial monitor

Serial.println ("Sketch start - potentiometer values");
 
}

Void loop () {

// We read from pin Aø value

Value = analogRead (Aø)

// We print through the serial monitor

Serial.print ("value is =");

Serial.println (value);

Delay (1000);
}
  • When the code has been uploaded to the potentiometer on the board, the serial monitor should be opened. In this case, the output will depend on the position of the potentiometer, as you turn the wheel it will be possible to see how the value is changing.

  • At one end the resistance will be minimum and will let 5 V pass , an analog value of 1023 and at the other end the resistance will be maximum and will let 0 V pass an analog value of 0.

So that you can understand all this in a better way, here we are going to show you another example of how to use the potentiometer on an Arduino board:

Power LEDs with a potentiometer on Arduino

In this case , 4 LEDs will be added to the circuit, depending on how the position of the potentiometer is modified, each of the LEDs will turn on .

For this, it will be necessary to mount the circuit through the following diagram:

As you have seen, 1024 different values can be read, these range from 0 to 1023 . By dividing this range by 4 and assigning a range to each of the LEDs, you can control which LED to turn on depending on the input value on the analog pin.

The ranges of the values ​​in these cases are the following:

  • From 0 to 255, LED 1 will light.
  • From 256 to 511 LED 2 will light.
  • From 512 to 767 LED 3 will light.
  • 768 to 1023 will light LED 4.

As the potentiometer is varying the analog input, one LED can light up and another, all of this will be programmed by nested ifs.

Code

Here it will be necessary to use the property of the variable resistance potentiometer to turn on one and the other LED, this will allow making a series of ifs to determine which LED is going to turn on and which one is going to turn off .

Depending on the values ​​obtained at the input of the analog pin, the code would be like the following:

// Variable where we store the value of the potentiometer

Long value;


// We declare the pins of the LEDs

Int LED_1 = 2;

Int LED_2 = 3;

Int LED: 3 = 4;

Int LED 4 = 5;

 

Void setup () {

// We initialize the serial communication

Serial.begin (9600);


// We write start messages on the serial monitor

Serial.println ("Sketch start - potentiometer values");

pinMode (LED_1, OUTPUT);

pinmode (LED_2, OUTPUT);

pinMode (LED_3, OUTPUT);

pinMode (LED_4, OUTPUT);

}


Void loop () {

// We read from pin A ø value

Value = analogRead (Aø);
}
 

// We print through the serial monitor

Serial.print ("The value is =");

Serial.println (value);


If (value> = ø && value <= 225)

{

Digitalwrite (LED_1, HIGH);

DigitalWrite (LED_2, HIGH);

DigitalWrite (LED_3, HIGH);

DigitalWrite (LED_4, HIGH);

}

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button