Arduino Challenge for Using Potentiometer to Tune the Piezo

Johnny Chen
2 min readMay 21, 2023

Arduino Starter Kit Project 06 Youtube Video Challenge

In the Arduino tutorial for starter kit (, the challenge presented for changing the phototransistor to control the Piezo to potentiometer.

First, the terms for the project explained:

  • Potentiometer: It is used to control the voltage or current in a circuit. The potentiometer consists of a resistive track and a sliding contact, which can be moved by rotating a knob or shaft. The two pins are connected to voltage and ground, while the other would connect to analog signal input to Arduino.
  • Piezo: A piezo is a device that vibrates when receiving electricity, and would create song wave.

So the challenge would involve adjusting project 5: Mood Cue and project 6: Light Theremin.

// declare
int sensorValue; // hold sensor value
int potLow = 1023; // calibrate low value
int potHigh = 0; // calibrate high value
const int ledPin = 13; // LED pin

void setup() {
// Initialize Serial Monitor

// Make the LED pin an output and turn it on
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);

// calibrate for the first five seconds after program runs
while (millis() < 5000) {
sensorValue = analogRead(A0);
// record the max sensor value
if (sensorValue > potHigh) {
potHigh = sensorValue;
// record the min sensor value
if (sensorValue < potLow) {
potLow = sensorValue;
// turn the LED off, signaling the end of the calibration period
digitalWrite(ledPin, LOW);

void loop() {
// read analog signal to A0 pin
sensorValue = analogRead(A0);
// map the sensor values to a wide range of pitches
int pitch = map(sensorValue, potLow, potHigh, 100, 2000);

// play the tone for 20 ms on pin 8
tone(8, pitch, 20);

Serial.print("sensorVal: " + String(sensorValue));

int angle = map(sensorValue, potLow, potHigh, 0, 179);
Serial.println("Angle: " + String(angle));


The schematic of the Arduino would be pretty similar to project 06, except for replacing phototransistor with potentiometer. Also, we could put capacitor in-between potentiometer and wires-to-voltage-and-ground for smoothing out the voltage changes.

Thank you for your reading, please leave a comment!


  2. 05 Starter Kit: Mood Cue (
  3. 06 Starter Kit: Theremin (