ARDUINO · 3 MIN READ

Add ESPectre to an Arduino sketch

Detect motion from Wi-Fi CSI in an Arduino-ESP32 sketch. Your sketch keeps control of Wi-Fi and of everything else it does.

An ESP32 board connected to a laptop displaying the Arduino logo, sending a Wi-Fi CSI signal to a motion icon
The sketch starts the sensor and calls its loop. ESPectre turns the Wi-Fi signal into motion events.
Sections

The full runtime, in a library

Arduino-ESP32 is built on ESP-IDF, so the library runs the same runtime as the ESP-IDF SDK: CSI capture, calibration, detection, and the traffic that keeps CSI flowing. The ESPectre class wraps it with begin(), loop(), and callbacks that run on your sketch's task.

Wi-Fi trafficpings to the gateway
CSI captureESP-IDF runtime
Calibrationafter each connection
Detectionshared C++ detector
Callbacksyour sketch

Requirements

Requirements for the ESPectre Arduino library
RequirementCurrent support
BoardESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C5, or ESP32-C6
CoreArduino-ESP32 3.3 or later
ToolsArduino IDE or Arduino CLI
NetworkA 2.4 GHz access point that the board stays connected to, or a 5 GHz one on ESP32-C5

Installation

From v3.2.0, install ESPectre from the Arduino Library Manager. With Arduino CLI:

arduino-cli lib install ESPectre

To try the development version, install the develop branch of espectre-arduino, which follows every development build:

arduino-cli config set library.enable_unsafe_install true
arduino-cli lib install --git-url https://github.com/francescopace/espectre-arduino.git#develop
ESP-IDF projects that use Arduino as a component do not need this library. Add the SDK from the ESP Component Registry and use espectre::ESPectre; see the SDK guide.

Your first sketch

Open File > Examples > ESPectre > MotionDetection, set your network in arduino_secrets.h, and upload it. The core of the example is short:

#include <WiFi.h>
#include <ESPectre.h>

ESPectre sensor;

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin("your-network", "your-password");
  sensor.onMotion([](bool motion) { Serial.println(motion ? "Motion" : "Idle"); });
  sensor.begin();
}

void loop() {
  sensor.loop();
  delay(10);
}
  1. Start Wi-Fi, then the sensor

    Call begin() after WiFi.begin(). The connection does not have to be up yet.

  2. Call loop() every time

    Callbacks run inside begin(), loop(), and end(), so keep them short.

  3. Wait for calibration

    The sensor calibrates after each connection, while the room is quiet. Until then, ready() is false and no motion is reported.

Two more examples show the result on a board with a display: FeatherReverseTFT for the Adafruit Feather ESP32-S3 Reverse TFT, and WaveshareTouchLCD147 for the Waveshare ESP32-S3-Touch-LCD-1.47. See the display demos.

Wi-Fi

Current limits

For the full API, configuration, logging, and board notes, see the Arduino library reference.

Guides