The light on the wiper · 07 of 10

Seeing the bend

Fifty readings a second into the Serial Plotter, and one slow, even turn of the knob from end to end. On an Uno at 5 V the line climbs straight, flattens from about two-fifths of the turn and shoots up at the end. On 3.3 V it does the same, later and less.

Turn it slowly and watch the line

The sketch does nothing but read and print, fifty times a second. The Serial Plotter draws each number as the next point of a line, so a knob turned at an even speed draws the shape of the curve over time: straight if the reading is proportional to the turn, bent where it is not.

The sweep, printed
Board and VCC
Turned
0 %
Reading
0
Plain divider
0
Every dot is one line of the sketch's output. A knob turned at an even speed should draw a straight line, the dashed one. Run it.

The figure runs the book's model, not a capture. Pick the Uno and run it: the first 40 % of the turn climbs about 410 counts along the dashed line, the next half only about 270, and the last tenth about 345. That is the LED, pulling the wiper down through the upper track until the very end.

Your own curve

Load the sketch, open Tools > Serial Plotter, and turn the knob from one end to the other over about five seconds. Nobody turns at a perfectly even speed, so the line will wobble. Do it three or four times: what repeats is the board, and what changes is your hand.

On an Uno with VCC on 5V, expect a straight climb to about two-fifths of the turn, a long flattening, and a steep rise over the last part. Exactly where it bends depends on your LED's forward voltage, which varies a little from part to part.

The same board on 3V3

Move the block's VCC wire from the Uno's 5V pin to its 3V3 pin and sweep again. The line now tops out near 675, because the Uno still measures against 5 V and the knob only reaches 3.3 V. And it is straighter: the LED lights later and draws less from 3.3 V, so the dip is about 95 counts at worst instead of about 260.

That is the trade on an Uno. 5V gives the full 0 to 1023 and a bright LED, with a large bend. 3V3 gives about two-thirds of the counts, a slightly dimmer LED, and a smaller bend that is still there.

On the 3.3 V boards

The line is straight to about three-fifths of the turn, then sags below where it should be, by up to about 580 counts of 4095 near 90 %, and catches up at the very end. On an ESP32 or ESP32-S3 you may also see the line go flat at 4095 before the end. That is the ADC's own ceiling at roughly 3.1 V, described in counts and volts, not the LED.

The code

One reading every 20 ms, printed with a label so the Serial Plotter draws it as a line. Open Tools > Serial Plotter, then turn the knob slowly and evenly from one end to the other over about five seconds.

rotary_pot_sweep.ino
/*
  Rotary Potentiometer - the sweep                       TK08 / /p/tk08

  Wiring. Count from the square pad on the TinkerBlock board, knob
  up, header at the bottom:

    GND    -> GND
    VCC    -> 5V on an Uno; 3V3 on an ESP32, ESP32-S3 or Pico
              (on an Uno, try 3V3 as well, and compare)
    NC     -> nothing   (unconnected on the board)
    SIGNAL -> A0 on an Uno, GPIO 34 on an ESP32, GPIO 4 on an
              ESP32-S3, GP26 on a Raspberry Pi Pico

  Arduino IDE
    Tools > Board                 your board, e.g. ESP32S3 Dev Module
    Tools > Port                  the one that appears when you plug in
    Tools > USB CDC On Boot       Enabled   (ESP32-S3 only)
    Tools > Serial Plotter        at 115200, Serial Monitor closed
    No library needed.
*/

// The pin SIGNAL is wired to, picked for the board you compile for.
// Uno: A0. ESP32: 34. ESP32-S3: 4. Pico: 26.
#if defined(ARDUINO_ARCH_AVR)
const int POT_PIN = A0;
#elif defined(ARDUINO_ARCH_RP2040)
const int POT_PIN = 26;
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
const int POT_PIN = 4;
#else
const int POT_PIN = 34;         // the classic ESP32
#endif

void setup() {
  Serial.begin(115200);
#if !defined(ARDUINO_ARCH_AVR)
  analogReadResolution(12);     // the Pico's core starts at 10 bits
#endif
}

void loop() {
  Serial.print("reading:");
  Serial.println(analogRead(POT_PIN));
  delay(20);                    // fifty points a second
}

The same #if block as the first read picks the pin and the resolution. Nothing here corrects the reading: the point is to see the raw curve your board produces. On an Uno, run it once with VCC on 5V and once on 3V3, and compare the two lines.

When it does not work

My curve is wobbly, not smooth.

Nobody turns a knob at a perfectly even speed, and the plot shows every hesitation as a flat spot. Try a few sweeps and look for the shape they share. The flattening in the upper part of the turn and the jump at the end are the part that repeats.

The Serial Plotter is empty or shows nothing useful.

Close the Serial Monitor first: only one of the two can hold the port. Then check the plotter's speed is 115200. The sketch prints one labelled number per line, which is the format the plotter expects.

On 3V3 my Uno's line tops out around 675, not 1023.

That is right. The Uno measures against its own 5 V, and the knob now only reaches 3.3 V, which is about two-thirds of the range. The line should also be straighter, with a smaller dip over the last two-fifths, which is the point of the comparison.

My ESP32's line goes flat at the very top.

That flat part is the ADC, not the LED: at its default setting the ESP32's ADC stops rising at roughly 3.1 V and reads 4095 above it. The LED's own dip is lower down, from about three-fifths of the turn to near the end, and is a sag rather than a flat line.

Where this goes next

Five readings that turn a crooked curve back into a position you can trust.

Calibrating the turn

Edit this page — content/books/rotary-potentiometer/seeing-the-bend.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Rotary Potentiometer

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum