Component Documentation: 22K 16mm Rotary Pot (Pack of 5)
The 22K 16mm Rotary Pot is a rotational potentiometer, commonly used in IoT projects to measure rotational angles or positions. This component is suitable for various applications, including robotics, autonomous vehicles, and interactive installations.
Resistance: 22 k
Power rating: 0.5 W
Operating voltage: 0 - 50 V
Rotational angle: 0 - 330
Mechanical life: 10,000 cycles
Dimensions: 16 mm (diameter) x 22 mm (height)
### Example 1: Reading Rotary Pot Values with Arduino
In this example, we will use the 22K 16mm Rotary Pot to control the brightness of an LED connected to an Arduino board.
Arduino Board (e.g., Arduino Uno)
22K 16mm Rotary Pot
LED
220 Resistor
Breadboard and Jumper Wires
Code
```c
const int potPin = A0; // Rotary pot connected to analog input A0
const int ledPin = 9; // LED connected to digital output 9
int val = 0; // Variable to store rotary pot value
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // Read rotary pot value (0 - 1023)
int brightness = map(val, 0, 1023, 0, 255); // Map value to LED brightness (0 - 255)
analogWrite(ledPin, brightness); // Set LED brightness
delay(10);
}
```
### Example 2: Using the Rotary Pot with Raspberry Pi (Python)
In this example, we will use the 22K 16mm Rotary Pot to control the rotation of a servo motor connected to a Raspberry Pi.
Raspberry Pi
22K 16mm Rotary Pot
Servo Motor (e.g., SG90)
Breadboard and Jumper Wires
Code
```python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
pot_pin = 17 # Rotary pot connected to GPIO 17
servo_pin = 18 # Servo motor connected to GPIO 18
GPIO.setup(pot_pin, GPIO.IN)
GPIO.setup(servo_pin, GPIO.OUT)
def read_rotary_pot():
pot_val = GPIO.input(pot_pin)
return pot_val
def set_servo_motor(angle):
servo = GPIO.PWM(servo_pin, 50) # 50 Hz frequency
servo.start(0)
servo.ChangeDutyCycle(angle)
time.sleep(0.5)
servo.stop()
while True:
pot_val = read_rotary_pot()
angle = (pot_val / 1023.0) 180.0 # Map value to servo motor angle (0 - 180)
set_servo_motor(angle)
time.sleep(0.1)
```
These examples demonstrate how to use the 22K 16mm Rotary Pot to measure rotational angles and control various outputs in IoT applications.