This repository is generated from francescopace/espectre. Report issues and send pull requests there.
Turn an ESP32 into a Wi-Fi motion sensor from an Arduino sketch. When someone moves through a room, they change the way Wi-Fi signals travel through it. ESPectre reads those changes, known as channel state information (CSI), and reports motion to your sketch. No camera, no radar, and no extra hardware: just the board and the Wi-Fi network already in the room.
Your sketch keeps control of Wi-Fi and of everything else it does.
- Arduino-ESP32 core 3.3 or later.
- ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C5, or ESP32-C6.
- A 2.4 GHz access point that the board stays connected to, or a 5 GHz one on ESP32-C5.
In the Arduino IDE, open Sketch > Include Library > Manage Libraries, search for ESPectre, and install it. With Arduino CLI, run:
arduino-cli lib install ESPectreFor the development version, a ZIP archive, or an ESP-IDF project, see other ways to install.
Open File > Examples > ESPectre > MotionDetection, set your network in arduino_secrets.h, and upload it. Open the serial monitor at 115200 baud. On ESP32-S2, the USB port prints only while the monitor holds DTR on.
#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);
}Call begin() after WiFi.begin(). The connection does not have to be up yet. Call loop() from every Arduino loop. Callbacks run inside begin(), loop(), and end(), so keep them short.
The sensor calibrates after each connection. ready() is false until then, and motion() stays false while sensing is not ready. If motion is detected when sensing stops being ready, onMotion() reports idle first.
Keep the room quiet while the sensor calibrates, then move. See the placement guide for where to put the board.
Two examples show sensing on a board with a display: the connection, the calibration progress, the motion state, the movement score, and the threshold.
Only these examples need the Adafruit ST7735 and ST7789 Library, which also installs Adafruit GFX. Install it from the Library Manager, or with Arduino CLI:
arduino-cli lib install "Adafruit ST7735 and ST7789 Library"Open the example from File > Examples > ESPectre, set your network in arduino_secrets.h, and upload it. Keep the room quiet while the display shows Calibrating, then move.
| Display | NeoPixel | Meaning |
|---|---|---|
| Connecting | Blue | The board is joining your network |
| Calibrating | Blue | The sensor is calibrating. The default detector also shows its progress |
| Waiting | Blue | The board is connected, but results are not ready yet |
| Idle | Green | No motion, with the movement score and threshold |
| Motion | Red | Motion, with the movement score and threshold |
| Error | Blinking yellow | A fault. The serial monitor prints the full message |
The FeatherReverseTFT example uses the display and NeoPixel of the Adafruit Feather ESP32-S3 Reverse TFT. It was inspired by John Edgar Park's demo for the same board. Choose Tools > Board > Adafruit Feather ESP32-S3 Reverse TFT. The NeoPixel uses the Arduino-ESP32 core.
CI compiles this example, but it has not been tested on the board yet. The Waveshare example below runs the same display code and has been.
The WaveshareTouchLCD147 example uses the display of the Waveshare ESP32-S3-Touch-LCD-1.47. The board has no status LED, and the example does not use the touch panel. Choose Tools > Board > ESP32S3 Dev Module, and set USB CDC On Boot to Enabled to read the serial output. The display pins are at the top of the sketch.
| Member | Purpose |
|---|---|
config() |
Configuration for the next begin(), such as threshold or csi_target_pps |
begin() / end() |
Start or stop sensing. begin() returns false when setup fails |
loop() |
Advance sensing and deliver callbacks |
ready(), motion() |
Whether results can be trusted, and whether motion is detected |
movement(), threshold() |
Latest movement score and the threshold it is compared against |
onMotion(), onReady(), onFault() |
Callbacks for motion changes, readiness changes, and runtime faults |
runtime() |
The full SDK controller for thresholds, recalibration, and diagnostics |
The configuration starts from the SDK defaults. Settings changed at runtime are not saved, so the values in your sketch always apply after a reboot. Set config().persist_runtime_overrides to true to save them.
See the SDK guide for the full runtime contract.
ESPectre turns Wi-Fi power save off at every connection, because it reduces the CSI rate. Do not call WiFi.setSleep(true) while sensing.
ESPectre sends a small stream of ping packets to the gateway to keep CSI flowing. See traffic destination to choose another target.
On a mesh network, pass the BSSID and channel of the nearest access point to WiFi.begin(). A board joined to a distant node gets weak CSI, and detection becomes unreliable.
Arduino-ESP32 retries the first connection once, and later does not reconnect after some failures, such as a refused authentication. Reconnect from your sketch when WiFi.status() stays disconnected. ESPectre reconnects the board on its own only after it restarts the connection to apply its radio settings.
ESPectre logs follow the Core Debug Level setting, like the core's own messages. They are off by default. To send them elsewhere, register a log sink before begin().
On ESP32-S2 with USB CDC On Boot enabled, these logs go to the UART0 pins, not to the USB port.
These apply to the Arduino library, not to the ESP-IDF component.
- The library includes sensing only. MQTT, Direct HTTP, and provisioning are not included.
- The
traffic.tx_packets_totalandtraffic.rx_packets_totaldiagnostics stay at zero. - On ESP32, the fixed transmit rate does not apply, because Arduino builds ESP-IDF with A-MPDU enabled.
- The MotionDetection example uses 70–88% of the default 1.2 MB app partition, the most on ESP32-C5 and ESP32-C6. Choose a larger Partition Scheme when your sketch adds other libraries.
The develop branch of espectre-arduino follows each development build. Install it with Arduino CLI:
arduino-cli config set library.enable_unsafe_install truearduino-cli lib install --git-url https://github.com/francescopace/espectre-arduino.git#developEach stable release tags espectre-arduino, where GitHub offers the library as a ZIP archive. CI also builds espectre-arduino-<version>.zip as the arduino-library workflow artifact. In the Arduino IDE, choose Sketch > Include Library > Add .ZIP Library. With Arduino CLI, run:
arduino-cli config set library.enable_unsafe_install truearduino-cli lib install --zip-path espectre-arduino-<version>.zipESP-IDF projects that use Arduino as a component do not need this library. Add the SDK from the ESP Component Registry, include espectre_sdk.h, and use espectre::ESPectre:
idf.py add-dependency "francescopace/espectre"The component includes the same class and the full SDK, with menuconfig, optional services, and the traffic diagnostics. Register a log sink to see ESPectre logs. See the SDK guide for the details.
ESPectre is available under GPLv3 and a separate commercial license. See LICENSING.md.