Lab 3: Sensing-Potentiometer

Tina Teng
4 min readSep 23, 2021

--

Tina Teng. Professor Kimiko Ryokai. Tangible User Interfaces, Fall 2021

Description

In this lab, we are exploring analog input. We will be using variable resistance devices, known as potentiometers (“pots” for short). We will use the Arduino Uno to read potentiometer values and control LEDs based on those potentiometer values. In part 1, we will solder wires to the potentiometers. Following in part 2, we will be controlling LED blinking speed and brightness level using one potentiometer. Extending upon part 2, in part 3, we will be controlling multiple LEDs with multiple potentiometers.

Three Pots Controlling Three LEDs Brightness Levels

Components Used

  • 1 Arduino UNO
  • 1 Breadboard
  • 3 LED (Red, Green, Blue)
  • 3 Resistors (220Ω)
  • 3 Potentiometers
  • Wires

Activity

Part 1: Soldering

In order to prepare the potentiometer to easily connect to our circuit, we had to solder wires to it. I take 1 of each red, black, and yellow wires and strip off the ends of each wires. To stabilize the potentiometer, I used “helping hands” to assist me.

It was my first time soldering, the first potentiometer took me 30 minutes, but with continuous tries and guidance from Zeke, Sam, and Professor Kimiko, I slowly got the hand of it and was able to solder my third potentiometer in 5 minutes.

Intermission: Verify that your Potentiometer works

Before we start using the potentiometer to control LEDs, we want to quickly verify that it is working.

After connecting potentiometer to Arduino and uploading the following code:

const int analogPin = A0;void setup() {
Serial.begin(9600);
}
void loop() {
int val = analogRead(analogPin);
Serial.println(val);
}

As we twist the potentiometer, it takes a reading from the potentiometer and then prints it on the serial interface:

We repeat the steps for all potentiometers.

Part 2: Controlling One LED from the Potentiometer

Following the circuit diagrammed below, I connected my 3 LED circuits to my potentiometer on my breadboard. I changed the provided code to account for the all three RGB LEDs.

Circuit schematic for controlling LEDs from one potentiometer.

By twisting a single potentiometer, I am able to control the 1) blinking speed and 2) brightness level of the LEDs.

Part 2.1: Blinking Speed

/* Blinking speed code */int sensorPin = A0;    
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
int sensorValue = 0;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

Part 2.1: Brightness Level

/* Brightness code */int sensorPin = A0;   
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
int sensorValue = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// declare the ledPin as an OUTPUT:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
analogWrite(redPin, sensorValue/4);
analogWrite(greenPin, sensorValue/4);
analogWrite(bluePin, sensorValue/4);
// stop the program for for <sensorValue> milliseconds:
delay(10);
}

Part 3: Multiple Pots Controlling Multiple LEDs

Extending the previous part, we control the brightness of all 3 LEDs with each of the 3 potentiometers, so the brightness of each LED can be individually controlled. In other words, one potentiometer controls the red LED, one potentiometer controls the blue LED, and one potentiometer controls the green LED.

Circuit schematic for controlling LEDs from three potentiometers.
/* Multiple Pots Controlling Multiple LEDs */// select the input pin for the potentiometers
int redPot = A0;
int greenPot = A1;
int bluePot = A2;
// each RGB LED, connected to associated digital pin
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
// store the value from each RGB sensor:
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
redValue = analogRead(redPot);
greenValue = analogRead(greenPot);
blueValue = analogRead(bluePot);

analogWrite(redPin, redValue/4);
analogWrite(greenPin, greenValue/4);
analogWrite(bluePin, blueValue/4);

delay(100);
}

--

--

Tina Teng

Tina is an undergraduate at UC Berkeley, studying business administration and data science. She is interested in HCI and UX research & design.