# Potentiometer (Variable Resistor)

## What is Potentiometer
Potentiometer is a resistor with continuously adjustable resistance, changed by rotating the knob.
### Potentiometer Features
- **Continuous Adjustment**: Resistance can change smoothly
- **3 Pins**: Two fixed ends, one sliding end
- **Wide Applications**: Commonly used for dimming, volume control, parameter adjustment, etc.
## Pin Description
Potentiometer has 3 pins:
- **Pin1**: One end (fixed end)
- **Pin2**: Middle sliding end (output end)
- **Pin3**: Other end (fixed end)
## Working Principle
When the knob is rotated, the sliding end moves on the resistor strip, changing the resistance distribution with the two ends, but total resistance remains unchanged.
```
Pin1 āā[Resistor]āā Pin2 āā[Resistor]āā Pin3
ā
Sliding End
```
### Resistance Changes
- **Pin1 to Pin2**: Resistance changes with knob position (0Ī© to nominal value)
- **Pin2 to Pin3**: Resistance changes with knob position (nominal value to 0Ī©)
- **Pin1 to Pin3**: Total resistance unchanged (equals nominal value)
## Usage Methods
### Potentiometer Dimming Circuit (Direct Visual Effect)

### Connection Instructions (Potentiometer Dimming)
According to the diagram above, connection order is:
```
VCC (5V) ā Potentiometer Pin1
Potentiometer Pin2 (middle pin) ā LED anode ā 220Ī© resistor ā GND
Potentiometer Pin3 ā GND
```
**Working Principle**:
- Rotate knob, potentiometer Pin2 output voltage varies from 0V to VCC
- **Clockwise Rotation**: Output voltage increases, LED brightens
- **Counterclockwise Rotation**: Output voltage decreases, LED dims
- Can continuously adjust LED brightness
**Effect**: Rotate potentiometer knob, LED brightness changes accordingly, can directly see dimming effect
### As Variable Resistor
Use only Pin1 and Pin2 (or Pin2 and Pin3), resistance varies from 0Ī© to nominal value.
## Common Resistance Values
| Resistance | Application Scenarios |
|-----------|---------------------|
| 100Ī©, 220Ī© | Current adjustment |
| 1KĪ©, 4.7KĪ©, 10KĪ© | Voltage division, dimming (most common) |
| 1MĪ© | High-impedance circuits |
## Arduino Example Code
### Basic Example: Read Potentiometer Value
```cpp
const int potPin = A0; // Potentiometer connected to A0
void setup() {
Serial.begin(9600);
pinMode(potPin, INPUT);
}
void loop() {
int value = analogRead(potPin); // Read 0-1023
Serial.println(value);
delay(100);
}
```
### Connection Method
- **Pin1** ā **VCC (5V)**
- **Pin2** ā **Arduino A0**
- **Pin3** ā **GND**
### Code Explanation
- `analogRead(pin)`: Read analog value, range 0-1023
- 0 corresponds to 0V, 1023 corresponds to 5V
- Can convert to other ranges using `map()` function
### Advanced Example: Potentiometer Controls LED Brightness
```cpp
const int potPin = A0;
const int ledPin = 9; // PWM pin
void setup() {
pinMode(potPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int potValue = analogRead(potPin); // 0-1023
int brightness = map(potValue, 0, 1023, 0, 255); // Convert to 0-255
analogWrite(ledPin, brightness);
delay(10);
}
```
**Explanation**: `map()` function maps 0-1023 to 0-255 for PWM control of LED brightness.
## Common Questions and Answers
### Q1: Potentiometer Reading Unstable?
- Check if connection has good contact
- Potentiometer may be worn, try cleaning or replacing
- Add software filtering (read multiple times and average)
### Q2: How to Choose Potentiometer Resistance Value?
- **Dimming, Volume Control**: Use 10KĪ© (most common)
- **Current Adjustment**: Use small resistance values (100Ī© - 1KĪ©)
- **High-Impedance Applications**: Use large resistance values (100KĪ© - 1MĪ©)
### Q3: Can Potentiometer Be Used as Fixed Resistor?
Yes, but wastes adjustment function. Use only two pins (1 and 2, or 2 and 3), resistance is fixed.
## Safety Precautions
ā ļø **Important Notes**:
- Do not exceed maximum power (usually very small)
- Do not rotate too forcefully to avoid damage
- Pay attention to pin connections to avoid short circuit
## Practical Applications
Potentiometers are commonly used for dimming, volume control, parameter adjustment, sensor calibration, etc. In Arduino projects, commonly used to provide analog input signals, control LED brightness, motor speed, etc.