Components needed

  • Arduino Uno Board
  • Breadboard
  • Potentiometer
  • Resistors
  • Jumper Cables
  • An RGB LED
  • USB Cable
  • A computer with the Arduino IDE installed

Completed Circuit

The image above shows the completed circuit showing the potentiometer controlling the color of the RGB LED. Changing the resistance, by turning the knob of the potentiometer, changes the color of the RGB LED.

The Program

int wiperPin = A0;
int knobValue= 0, redPin=9, greenPin=8, bluePin=7;

void setup() {
  pinMode(wiperPin, INPUT);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

void loop() {
 knobValue= analogRead(wiperPin);

 if(knobValue<341) {
  digitalWrite(redPin, HIGH);
  digitalWrite(bluePin, LOW);
 else if(knobValue>682) {
  digitalWrite(redPin, LOW);
  digitalWrite(bluePin, HIGH);
 else {
  digitalWrite(redPin, LOW);
  digitalWrite(bluePin, LOW);

We want to change the color of the RGB LED whenever the resistance of the potentiometer changes. For that, we first need to know what is the resistance coming out of the potentiometer. To do that, we connected the wiper pin of the potentiometer to the analog pin (A0) on the Arduino board. Now to read the value of the pin A0, we need to set pin A0 to input. We achieved that by using pinMode(wiperPin, INPUT) function.

Now to read the value of pin A0 (wiperPin), we are using the analogRead function, and storing that value into the knobValue variable. Turning the potentiometer knob from left to the right will give us different values between 0 through 1023. We are changing the color of the RGB LED for different values of the knobValue variable.

Hope you will find this post helpful to learn about potentiometer. See video below for explanation of circuit and program. Please comment below if you have any question. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s