A first build on the expansion base
A potentiometer on GPIO 3 and an LED on GPIO 7, wired to the two edge strips with four jumper wires. The knob sets the blink rate, and the Serial Monitor prints what the pin read.
Seat the board, then wire
Put the board in with V5 on the board next to 5V on the base, as
seat the board describes, and fit it before
the cable goes in. The switch can stay OFF: USB powers everything on this page.
You need a 10 kΩ potentiometer, an LED, a 330 Ω resistor and four jumper wires. The pins on the outer strips take wires with a socket end, and the yellow sockets take wires with a pin end.
Four wires, in order
Ground goes in first, so nothing is live with no way home. The 3V hole feeds the potentiometer, whose middle terminal then goes to GPIO 3 on the left strip. GPIO 7 goes through the resistor to the LED. Both signals come from the left strip and both supplies from the right, because that is where the base puts them.
What you should see
The LED blinks and the knob changes the rate: about 50 ms on and 50 ms off at
one end, a second each at the other. A mid-range reading of 2048 gives
525 ms. The Serial Monitor prints one line per blink, such as
knob 2048 -> 525 ms.
Why these two pins
GPIO 3 is an analog input and nothing on the board uses it. GPIO 7 is a plain digital pin, also free. GPIO 5 and 6 are the display, 8 is the LED the board carries, and 9 is the button that decides whether the next reset starts a sketch or waits for an upload, so none of them is a place to plug in an LED.
The code
Reads a potentiometer on GPIO 3 and blinks an LED on GPIO 7 faster the further the knob is turned down. The Serial Monitor prints the raw reading and the wait.
// ESP32-C3 OLED on the Expansion Base: a knob sets how fast an LED
// blinks.
//
// Wiring (the silkscreen on the base names every hole):
// Right strip 3V -> potentiometer, one outer terminal
// Right strip GND -> potentiometer, other outer terminal, and
// the LED's short leg
// Left strip 3 -> potentiometer, middle terminal
// Left strip 7 -> 330 ohm resistor -> LED long leg
//
// Arduino IDE, Tools menu:
// Board ESP32C3 Dev Module
// USB CDC On Boot Enabled
// Flash Size 4MB (32Mb)
// Partition Scheme Default 4MB with spiffs
// Upload Speed 921600
// Serial Monitor 115200
// No library needed.
const int KNOB_PIN = 3; // analog input
const int LED_PIN = 7; // free digital pin
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int raw = analogRead(KNOB_PIN); // 0 to 4095
int wait = map(raw, 0, 4095, 50, 1000); // milliseconds
digitalWrite(LED_PIN, HIGH);
delay(wait);
digitalWrite(LED_PIN, LOW);
delay(wait);
Serial.printf("knob %d -> %d ms\n", raw, wait);
}GPIO 3 is one of the five analog inputs, GPIO 0 to 4, and GPIO 7 is a plain digital pin that nothing on the board uses. The potentiometer takes its supply from the 3V hole, so what the pin reads runs from 0 at one end of the knob to 4095 at the other.
When it does not work
An LED passes current one way. The long leg goes to the resistor and the short leg to ground. If it is the right way round, check that the resistor's other end is in the hole printed 7 on the left strip, and that the short leg's wire reaches GND on the right strip.
USB CDC On Boot is set to Disabled, which is the default. The sketch runs and prints nothing. Set it to Enabled, upload again and reopen the monitor at 115200.
The middle terminal is not the one on GPIO 3. A pot has two ends and a middle, and the middle is the moving one. Ends to 3V and GND, middle to the hole printed 3. A reading stuck at 4095 can also mean the wiper wire is in the 3V hole by mistake.
The wiper wire is in a hole that is not GPIO 3, or it has come out of its socket. The sketch still runs, because an unwired analog pin returns a drifting number rather than an error, so the rate wanders by itself. Reseat the wire in the hole printed 3.
A second analog read, and the divider across the cell that makes it possible.
Battery level, on the screen →Edit this page — content/books/c3oled/expansion-first-build.mdx
Questions about this product
See what other owners have asked, and read their solutions.
This page covers several products. Choose yours to see the right 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.