Let me guess: your smart home is currently a digital landfill of six different manufacturer apps, three proprietary wireless bridges plugged into the back of your router, and a Chinese cloud server that decides whether or not your living room lamp is allowed to turn on today. You asked Alexa to turn off the kitchen lights, and instead, your robot vacuum started speaking Spanish and aggressively ramming into your dog.

We have all been there. The fragmentation of the smart home has been a waking nightmare. But finally, the industry giants got into a room, stopped screaming at each other, and agreed on a universal standard: Matter.

Matter is the “one protocol to rule them all.” It works locally over Wi-Fi, it doesn’t require a creepy cloud account, and it natively integrates into Apple Home, Google Home, and Alexa simultaneously. In this project, we are going to flash an ESP32-S3 to act as a certified Matter Node. No more bridges. No more proprietary junk. Just pure, unadulterated control.

What You Need

For Matter to work effectively over Wi-Fi (especially with CHIPoBLE provisioning), you need an ESP32-S3 or ESP32-C3. Standard ESP32s can work, but they require hardcoding Wi-Fi credentials rather than passing them smoothly over Bluetooth during setup.

Step 1: Prep the Arduino IDE

The brilliant folks at Espressif have integrated the Matter protocol directly into the ESP32 Arduino Core (v3.1.0 and up). You don’t even need to install external libraries!

Just ensure your board is selected in the Tools > Board menu (e.g., “ESP32S3 Dev Module”). Crucial step: Go to Tools > Partition Scheme and select “Huge APP (3MB No OTA / 1MB SPIFFS)”. Matter is a heavy protocol; standard partitions will fail to compile.

Step 2: The Code

This code sets up a standard On/Off Light endpoint. It uses the Preferences.h library to remember if the light was on or off in case the board loses power, and it maps the physical BOOT button on the ESP32 to a physical toggle switch.

#include <Arduino.h>
#include <Matter.h>
#include <Preferences.h>

MatterOnOffLight OnOffLight;
Preferences matterPref;
const char *onOffPrefKey = "OnOff";

const uint8_t ledPin = 2; // Test LED pin
const uint8_t buttonPin = BOOT_PIN; 
MatterButton button;

bool setLightOnOff(bool state) {
  if (state) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
  matterPref.putBool(onOffPrefKey, state);
  return true;
}

void setup() {
  button.begin(buttonPin);
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200);

  matterPref.begin("MatterPrefs", false);
  bool lastOnOffState = matterPref.getBool(onOffPrefKey, true);
  
  OnOffLight.begin(lastOnOffState);
  OnOffLight.onChange(setLightOnOff);

  Matter.begin();
  matterWaitUntilReady();
  OnOffLight.updateAccessory();
}

void loop() {
  matterRestartIfNoFabric();
  matterButtonEvent_t ev;
  while ((ev = button.poll()) != MATTER_BUTTON_NONE) {
    if (ev == MATTER_BUTTON_CLICK) {
      OnOffLight.toggle();
    } else if (ev == MATTER_BUTTON_LONG_HOLD) {
      OnOffLight.setOnOff(false);
      Matter.decommission();
    }
  }
}

Step 3: Commissioning (The Magic Part)

  1. Upload the code to your ESP32-S3.
  2. Open the Serial Monitor at 115200 baud and press the Reset (RST/EN) button on the board.
  3. The Serial Monitor will spit out an 11-digit manual pairing code and a URL to generate a QR code.
  4. Open the Apple Home, Google Home, or Amazon Alexa app on your phone, click Add Device, and scan that QR code.

The app will securely transfer your Wi-Fi credentials to the ESP32 over Bluetooth. Within seconds, your humble microcontroller will appear as a certified smart light in your ecosystem.

You can now toggle it with your voice, set up routines, or just click the physical BOOT button on the board to watch the state instantly sync to your phone. Welcome to the future.