- It has three terminals.
- It has a sliding or rotating contact that forms a adjustable voltage divider.
- It act as a variable resistor (or) rheostat.
Figure 1: potentiometer
Connection:
Step 1: Potentiometer to ArduinoMega2560
The first pin of the potentiometer can be connected to the Gnd of the Arduino Mega 2560. The second pin of the potentiometer can be connected to the Analog pin A0 of the Arduino Mega 2560. The third pin of the potentiometer can be connected to the 5V of the Arduino Mega 2560.
Step 2: Connection From LED To Arduino Mega 2560
Postive pin = 06
Negative pin = Gnd
Programming
- const byte POTENTIOMETER = 0;
- const byte CONTROL = 6;
- int reading;
- int value;
- void setup()
- {
- pinMode(CONTROL, OUTPUT);
- }
- void loop()
- {
- reading = analogRead(POTENTIOMETER);
- value = map(reading, 0, 1024, 0, 255);
- analogWrite(CONTROL, value);
- }
Explanation:
- Through this we can control Light /fan using potentiometer.
- If we adjust the potentiometer on the decreasing side the light brightness decreases.
- Also the fan speed also decreases.
- If we adjust the potentiometer on the increasing side the light brightness increases.
- Also the fan speed increased.
Output:
Figure 2: Output
Read more articles on Arduino: