ESP32-S3 bases/The screw terminal base/14. A first build on the screw terminal base
The screw terminal base · 14 of 22

A first build on the screw terminal base

An LED on GPIO 4 and a button on GPIO 5, wired into the screw blocks one wire at a time. The LED goes on the right block and the button on the left, because GPIO 4 is on the right block and GPIO 5 is on the left.

What goes where

You need an LED, a resistor of a few hundred ohms (330 Ω here), a push button and four short wires. Seat the ESP32-S3 first, with its USB sockets over the boxes printed USB, and leave the cable out while you wire.

The two circuits are on different blocks, and that is the lesson of this base.

WireFromTo
1Right block, 4 (tenth way)Resistor, one end
2Resistor, other endLED, long leg
3LED, short legRight block, GND (second way)
4Left block, 5 (third way)Button, one leg
5Button, other legLeft block, GND (second way)
Which wire goes in which terminal
LED on the right block
Step
GPIO 4 is set to
Terminal for GPIO 4
right block, way 10
Terminal for GND
right block, way 2
LED
lit
The LED is on the right block because GPIO 4 is. The resistor sits in series with the LED, from GPIO 4 to ground. Without it the pin pushes more current through the LED than either is meant to carry.

GPIO 4 is on the dev board's left row and on the right block. GPIO 5 is on the left row and on the left block. Wire by the number printed beside the screw, not by the row.

Stripping a wire and tightening a screw

Strip enough insulation that bare copper fills the clamp and none of the insulation is under it. Back the screw out until you can see the clamp open, put the copper in, and tighten until the wire will not pull out by hand. Then stop: the thread is small. Tug the wire. A screw that has closed on insulation feels tight and tests dead.

Solid wire holds better than fine stranded wire that can splay. If the wire is stranded, twist the strands together first so none of them is left outside.

Why these pins

The list of pins to leave alone is 43 and 44 (serial), 19 and 20 (native USB), 35 to 37 (the PSRAM of an N16R8 module) and 48 (the RGB LED). This base does not bring out 43, 44 or 35 to 37, and GPIO 19 and 20 are the right block's last two ways. GPIO 4 and 5 are on none of those lists and are not read at boot, so the first sketch cannot upset the board.

They are also two of the display plug's spare contacts. With a display fitted, choose two other ways: the display shares the wires.

The sketch

INPUT_PULLUP turns on a weak resistor inside the chip that holds the pin HIGH. The button, when pressed, joins the pin to ground and wins, so the pin reads LOW. That is why the sketch tests == LOW.

millis() / 500 counts half seconds since the sketch started, and % 2 makes it flip between 0 and 1 every half second. The sketch never stops to wait, so it reads the button every pass of the loop.

Reading the result

Open the Serial Monitor at 115200. You get pressed and released as you hold and let go. The two failures separate: nothing printed means the sketch is not running; printed but the LED is dark means the LED wiring.

The code

screw_first_build.ino

Blinks an LED on GPIO 4 once a second. While the button on GPIO 5 is held down, the LED stays lit, and the sketch prints each press and release.

// ESP32-S3 Screw Terminal Base: blink an LED, read a button.
//
// Wiring, one wire per line:
//   Right block, GPIO 4 (tenth way) -> 330 ohm resistor -> LED long leg
//   LED short leg -> right block, GND (second way)
//   Left block, GPIO 5 (third way)  -> button, one leg
//   Button, other leg -> left block, GND (second way)
//
// Seat the ESP32-S3 with its USB sockets over the boxes printed USB
// first, then plug in the cable.
//
// Arduino IDE, Tools menu:
//   Board             ESP32S3 Dev Module
//   USB CDC On Boot   Enabled (Disabled if cable in UART socket)
//   Flash Size        16MB (128Mb)
//   PSRAM             OPI PSRAM
// No library needed.

const int LED = 4;     // right block
const int BUTTON = 5;  // left block

bool wasPressed = false;

void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);  // HIGH open, LOW pressed
}

void loop() {
  bool pressed = digitalRead(BUTTON) == LOW;
  bool blinkOn = (millis() / 500) % 2 == 0;
  digitalWrite(LED, (pressed || blinkOn) ? HIGH : LOW);

  if (pressed != wasPressed) {
    Serial.println(pressed ? "pressed" : "released");
    wasPressed = pressed;
  }
}

The button reads LOW when pressed, because it joins the pin to ground and INPUT_PULLUP holds the pin HIGH the rest of the time. GPIO 4 and 5 are on no list of pins to avoid: not USB, not PSRAM, not read at boot.

When it does not work

The LED does not light

Check the wire is on the right block's tenth way, labelled 4, and not on the left block, which has no GPIO 4. Then check the LED's long leg is on the resistor side. An LED the wrong way round stays dark and is not damaged by it.

The LED stays dark and nothing prints

The sketch is not running, so look at the board and the upload before the wiring. Check the board is seated with its USB sockets over the boxes printed USB, and that the upload finished. If the red LED on the ESP32-S3 is off, unplug at once: it may be end for end.

The Serial Monitor prints pressed all the time

The button is wired between GPIO 5 and ground, so the pin should read HIGH when it is open. If it reads LOW all the time, a leg of the button is shorted across, which happens when both wires go to the same side of a four-legged button. Use one leg from each side.

A wire pulls out even though the screw is tight

The clamp has closed on insulation, or beside the copper. Back the screw out until you can see the clamp open, put bare copper under it with no insulation inside the clamp, tighten until the wire will not move, and tug it.

Where this goes next

The PinPulse: every GPIO on a pin and a socket, with a light on each.

What the shield does →

Edit this page — content/books/esp32s3-base/screw-first-build.mdx

Community

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.

Browse Modules and blocks on the forum →