75 lines
3.6 KiB
Markdown
75 lines
3.6 KiB
Markdown
# 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.sh` topic.
|
|
- **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
|
|
|
|
1. **Install Libraries:**
|
|
- Open the Arduino IDE and go to `Sketch` > `Include Library` > `Manage Libraries...`.
|
|
- Install the following libraries:
|
|
- `Adafruit SSD1306` by Adafruit
|
|
- `Adafruit GFX Library` by Adafruit
|
|
- `BH1750` by Christopher Laws
|
|
|
|
2. **Configure the Code:**
|
|
- Copy `secrets_template.h` to a new file named `secrets.h` in the same directory.
|
|
- Open `secrets.h` and populate `SECRET_WIFI_SSID`, `SECRET_WIFI_PASSWORD`, and `SECRET_NTFY_TOPIC` with your WiFi credentials and desired `ntfy.sh` topic.
|
|
- The `secrets.h` file is ignored by git to keep your credentials safe.
|
|
|
|
3. **Upload the Code:**
|
|
- Connect your ESP32 board to your computer.
|
|
- Select the correct board and port in the Arduino IDE.
|
|
- Click the upload button.
|
|
|
|
4. **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 configured `ntfy.sh` topic 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.
|