first commit

This commit is contained in:
Dejvino 2026-02-12 18:47:02 +01:00
commit 7f7a3b0dc7

79
README.md Normal file
View File

@ -0,0 +1,79 @@
# ESP32 Washing Machine Activity Notifier
This project turns an ESP32 into a smart device that monitors a washing machine's activity using vibration and light sensors and sends notifications when a cycle starts and finishes. It also displays the current status on an OLED display.
## Features
- **Vibration Sensing:** Detects machine operation by monitoring vibrations.
- **Light Sensing:** Detects the machine's internal light to determine if the door is open.
- **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
- SW-420 vibration sensor module (or similar)
- BH1750 light sensor module
- SSD1306 128x64 OLED display (I2C)
- Breadboard and jumper wires
## Pinout
| Component | Pin on ESP32 |
| ------------------- | ------------ |
| Vibration Sensor | GPIO 4 |
| I2C SCL (OLED, BH1750) | GPIO 22 |
| I2C SDA (OLED, BH1750) | GPIO 21 |
### Wiring Diagram
```
+-----------------+ +-----------------+ +-----------------+ +-----------------+
| ESP32 Dev Board | | Vibration Sensor| | BH1750 Sensor | | OLED Display |
+-----------------+ +-----------------+ +-----------------+ +-----------------+
| 3.3V |----->| VCC |----->| VCC |----->| VCC |
| GND |----->| GND |----->| GND |----->| GND |
| GPIO 4 |----->| OUT | | | | |
| | +-----------------+ | | | |
| GPIO 22 (SCL) |------------------------------>| SCL |----->| SCL |
| GPIO 21 (SDA) |------------------------------>| SDA |----->| SDA |
+-----------------+ +-----------------+ +-----------------+
```
## 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:**
- Open the `esp32_MachineNotify.ino` file.
- Replace the placeholder values for `WIFI_SSID`, `WIFI_PASSWORD`, and `NTFY_TOPIC` with your WiFi credentials and desired `ntfy.sh` topic.
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 the vibration sensor on the washing machine where it can detect vibrations from the spin cycle.
- Place the light sensor inside the machine's drum to detect the internal light.
## Code Explanation
The code is structured as follows:
- **Includes and Definitions:** Includes the necessary libraries for WiFi, I2C devices, and the display. It also defines pins, thresholds, and other constants.
- **`setup()`:** Initializes serial communication, I2C, sensors, the OLED display, and connects to WiFi.
- **`loop()`:** This is the main part of the program.
- It continuously reads the values from the vibration and light sensors.
- It implements a non-blocking logic using `millis()` to check if the sensors have been in a certain state (e.g., vibration active or light level high) for a continuous period of 5 seconds.
- It updates the overall device state (`isDeviceActive`) 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.