This project uses an ESP32 microcontroller to detect motion using one or more sensors and publish the results to an MQTT broker. The code is written in C++ using the Arduino framework and PlatformIO.
An example of use with a Node-RED workspace:
This project depends on the following libraries:
- WiFi.h
- PubSubClient.h
- Wire.h
The config.h
file contains the following configuration options:
WIFI_SSID
: the SSID of the WiFi network to connect toWIFI_PASSWORD
: the password for the WiFi networkMQTT_SERVER
: the hostname or IP address of the MQTT brokerMQTT_PORT
: the port number for the MQTT brokerMQTT_USER
: the username for the MQTT broker (optional)MQTT_PASSWORD
: the password for the MQTT broker (optional)
- Upload the code to your ESP32 microcontroller using the PlatformIO IDE or the
pio run --target upload command
in your project directory. - Connect one or more motion sensors to the ESP32 using the
sensorPins
array in the code. - When motion is detected, the ESP32 will publish a message to the
esp32/motion
topic on the MQTT broker with a payload of1
. When motion detection ends, the ESP32 will publish a message to the same topic with a payload of0
. - ESP32 will be suscribed to the
esp32/output
topic to turn on/off the built-in led.
This project is licensed under the MIT License. See the LICENSE
file for details.
Let me know if you need any further assistance!