All wiring guides

Free wiring guides

Wire the MC-38 door switch to the ESP32-S3

Magnetic door switch, MC-38. Closes when its magnet is beside it: knows if a door is shut.

Which pin goes where

On the partOn the ESP32-S3
AGPIO 5
BGND

Wire it with the USB cable unplugged. Follow the names printed on your own part: makers sometimes reorder the pins.

In 3D

Example sketch

// Magnetic door switch, MC-38
// on the ESP32-S3-DevKitC-1 (N8R2 or N16R8)
// https://stem.manusignal.com/en/parts/mc-38-door-switch-esp32-s3

const int PIN_A = 5;

int last = -1;

void setup() {
  Serial.begin(115200);
  pinMode(PIN_A, INPUT_PULLUP);
}

void loop() {
  int now = digitalRead(PIN_A);
  if (now != last) {
    last = now;
    Serial.println(now == HIGH ? "ON" : "off");
  }
  delay(20);
}
  • Tools > Board > ESP32S3 Dev Module, then Tools > Port and choose the board's port.

This sketch is compiled for the board before the page is published. It has not been run on real hardware by us.

What you should see

Open the Serial Monitor at 115200. It prints ON when the magnet moves away: the door is open.

If it does not work

It says the door is always open.
The magnet must sit within 1 cm of the switch when the door is shut.

The same part on the ESP32-C3

More parts on the ESP32-S3