Lab 3: Sensing: Potentiometer

Yuetian Wang
2 min readSep 21, 2021

--

Yuetian Wang. Professor Kimiko Ryokai. Tangible User Interfaces, Fall 2021

Description

In the part 2, I use one potentiometer to control the blinking of 3 LEDs. And in the part 3, I choose the option 1. I use one potentiometer to control the blinking of 3 LEDs and another potentiometer to control the brightness of 3 LEDs.

Part 2

Video

Code

/*
Analog Input

Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on the value obtained
by analogRead().

The circuit:
- potentiometer
center pin of the potentiometer to the analog input 0
one side pin (either one) to ground
the other side pin to +5V
- LED
anode (long leg) attached to digital output 13 through 220 ohm resistor
cathode (short leg) attached to ground

- Note: because most Arduinos have a built-in LED attached to pin 13 on the
board, the LED is optional.

created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe

This example code is in the public domain.

https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput
*/

int sensorPin = A0; // select the input pin for the potentiometer
int redledPin = 9;
int blueledPin = 10;
int greenledPin = 11;
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(redledPin, OUTPUT);
pinMode(blueledPin, OUTPUT);
pinMode(greenledPin, OUTPUT);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the redledPin on
digitalWrite(redledPin, HIGH);
digitalWrite(blueledPin, HIGH);
digitalWrite(greenledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(redledPin, LOW);
digitalWrite(blueledPin, LOW);
digitalWrite(greenledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

Components Used

1- Arduino

1- Breadboard

1- Potentiometer

3- 220 ohm Resistor

3- LED Lights

Part 3

Video

Code

int blinkSensorPin = A0;
int dimSensorPin = A5;
int bluePin = 9;
int greenPin = 10;
int redPin = 11;
int fadeAmount = 5;
int sensorValue = 0;
int dimSensorValue = 0;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
blinkControl();
}
void blinkControl() {
dimSensorValue = analogRead(dimSensorPin);
sensorValue = analogRead(blinkSensorPin);

int brightness = map(dimSensorValue, 0, 1024, 0, 255);

analogWrite(redPin, brightness);
analogWrite(greenPin, brightness);
analogWrite(bluePin, brightness);

delay(sensorValue);
analogWrite(redPin, LOW);
analogWrite(greenPin, LOW);
analogWrite(bluePin, LOW);
delay(sensorValue);
}

Components Used

1- Arduino

1- Breadboard

2- Potentiometers

3- 220 ohm Resistors

3- LED Lights

--

--