1. Gather the things

What You Need:

  • A resistive strip (graphite on paper, conductive plastic, or resistance wire)
  • Two terminals (e.g. paperclips, metal contacts, or soldered wires)
  • A third contact (a wiper — use a metal slider or even a paperclip)
  • A base (cardboard or acrylic sheet)
  • Multimeter (to test resistance)


2. Do a thing

1. Prepare the Resistive Element

Use a piece of graphite-covered paper, a strip of nichrome wire, or a conductive plastic track. This acts as the variable resistor.

2. Attach Fixed Contacts (Terminal Ends)

Secure two metal clips or wires at the far ends of the resistive strip. These act as the ends of the potentiometer.

3. Create the Wiper

Use a metal arm, slider, or rotating contact that can touch and slide along the resistive strip. This is your middle pin, which adjusts the resistance between the two ends.

4. Mount on a Base

Fix everything on a cardboard or plastic sheet to keep it sturdy. Make sure the wiper can move freely.

5. Test with a Multimeter

 

3. Do a thing

Measure resistance from one end to the wiper while moving it. It should vary smoothly from near-zero to max resistance.

6. Connect to Your Circuit (Optional)

If you're testing it in a real project (e.g. Arduino), connect:

  • End 1 to GND
  • End 2 to VCC
  • Wiper to an analog input
Back to blog

Arduino Code

example.ino
#include <FastLED.h>

// Pin definitions
#define POT_PIN A0         // Analog pin for potentiometer
#define BUTTON_PIN D1      // Button pin for calibration
#define LED_PIN D0         // Digital pin to control the LED strip
#define LED_COUNT 20       // Number of LEDs in the strip
#define THRESHOLD 5        // Minimum change in potentiometer value to update LEDs

CRGB leds[LED_COUNT];      // Array to store the LED colors
int prevValue = 0;         // Stores the previous potentiometer value for comparison
int highValue = 1023;      // Initial high calibration value (max value of potentiometer)
int lowValue = 0;          // Initial low calibration value (min value of potentiometer)

void setup() {
  Serial.begin(115200);
  
  pinMode(BUTTON_PIN, INPUT_PULLUP); // Initialize the button as an input with an internal pull-up resistor

  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_COUNT); // Initialize the LED strip
  
  FastLED.setBrightness(30); // Set a moderate brightness level
  
  FastLED.show(); // Ensure all LEDs are off initially
  
  Serial.println("Setup complete, awaiting button press...");
}

void loop() {
  int potValue = analogRead(POT_PIN); // Read the current value of the potentiometer
  Serial.print("Potentiometer Value: ");
  Serial.println(potValue);

  // Check if the button is pressed (logic LOW if using INPUT_PULLUP)
  if(digitalRead(BUTTON_PIN) == LOW) {
    Serial.println("Button pressed");
    // Calibrate the low or high value based on the current potentiometer reading
    if(potValue < 300) { // Threshold to differentiate between low and high calibration
      lowValue = potValue;
      Serial.print("New lowValue: ");
      Serial.println(lowValue);
    } else {
      highValue = potValue;
      Serial.print("New highValue: ");
      Serial.println(highValue);
    }
    potValue = 0; // Reset potValue to avoid immediate recalibration effect
    FastLED.show(); // Update LED strip to reflect any changes
  }

  // Update LEDs only if the change in potentiometer value exceeds the threshold
  if(abs(potValue - prevValue) >= THRESHOLD) {
    prevValue = potValue; // Update previous value for next comparison
    int numLEDS = map(potValue, lowValue, highValue, 0, LED_COUNT); // Map pot value to number of LEDs

    // Create a color gradient based on the current position within the calibrated range
    for(int i = 0; i < LED_COUNT; i++) {
      int red = i * (255 / LED_COUNT);
      int green = 255 - red;

      if(i < numLEDS) {
        leds[i] = CRGB(red, green, 0); // Set color based on position
      } else {
        leds[i] = CRGB::Black;  // Turn off LEDs beyond the current position
      }
    }
    
    FastLED.show(); // Update the LED strip with new colors
  }

  delay(30); // Short delay to debounce button and slow down the loop for readability
}