3.6 KiB
3.6 KiB
ESP32 Dual Machine Activity Notifier
This project turns an ESP32 into a smart device that monitors two machines (e.g., washer and dryer) using light sensors and sends notifications when a cycle starts and finishes. It also displays the current status on an OLED display.
Features
- Dual Light Sensing: Monitors two separate devices using two BH1750 light sensors.
- Status Display: Shows real-time sensor data and device status on a small OLED display.
- Notifications: Sends start and stop notifications to a
ntfy.shtopic. - WiFi Connectivity: Connects to your local WiFi network.
Hardware Requirements
- ESP32 development board
- 2x BH1750 light sensor modules
- SSD1306 128x64 OLED display (I2C)
- Breadboard and jumper wires
Pinout
| Component | Pin on ESP32 | Notes |
|---|---|---|
| I2C SCL (OLED, Sensors) | GPIO 22 | Shared bus |
| I2C SDA (OLED, Sensors) | GPIO 21 | Shared bus |
Wiring Diagram
+-----------------+ +-----------------+ +-----------------+
| ESP32 Dev Board | | BH1750 Sensor | | OLED Display |
+-----------------+ +-----------------+ +-----------------+
| 3.3V |---------->| VCC |----->| VCC |
| GND |---------->| GND |----->| GND |
| | | | | |
| GPIO 22 (SCL) |---------->| SCL |----->| SCL |
| GPIO 21 (SDA) |---------->| SDA |----->| SDA |
+-----------------+ +-----------------+ +-----------------+
Note: For Sensor 1, connect the ADDR pin to GND (or leave floating if default is low). For Sensor 2, connect the ADDR pin to 3.3V to change its I2C address to 0x5C.
Setup & Usage
-
Install Libraries:
- Open the Arduino IDE and go to
Sketch>Include Library>Manage Libraries.... - Install the following libraries:
Adafruit SSD1306by AdafruitAdafruit GFX Libraryby AdafruitBH1750by Christopher Laws
- Open the Arduino IDE and go to
-
Configure the Code:
- Copy
secrets_template.hto a new file namedsecrets.hin the same directory. - Open
secrets.hand populateSECRET_WIFI_SSID,SECRET_WIFI_PASSWORD, andSECRET_NTFY_TOPICwith your WiFi credentials and desiredntfy.shtopic. - The
secrets.hfile is ignored by git to keep your credentials safe.
- Copy
-
Upload the Code:
- Connect your ESP32 board to your computer.
- Select the correct board and port in the Arduino IDE.
- Click the upload button.
-
Deploy the Device:
- Place Sensor 1 inside the first machine (e.g., Washer) to detect internal light.
- Place Sensor 2 inside the second machine (e.g., Dryer) to detect internal light.
Code Explanation
The code is structured as follows:
- It continuously reads the values from both light sensors.
- It implements a non-blocking logic using `millis()` to check if the sensors have been in a certain state (light level high) for a continuous period.
- It updates the overall device states (`isDevice1Active`, `isDevice2Active`) based on the individual sensor states.
- If the device state changes, it calls `sendNotification()`.
- It calls `updateDisplay()` to show the latest data.
sendNotification(): Sends a POST request to the configuredntfy.shtopic with a message.updateDisplay(): Manages the OLED display. It clears the screen and prints the current status of the sensors and the device. It also implements a scrolling feature to cycle through the displayed information every 2 seconds.