This repository is about a smart curtain opener and includes various components like a clock, environmental sensors, servo motor control, and more, all integrated with an UNO R3 and an ESP32.
- Timing: 0:00 - 23:59
- Features:
timer1for precise timing.- Integration with ESP32 for network time synchronization (TBD).
- Functionality: Continuously monitors and compares environmental data against set thresholds.
- Sensors:
- Temperature & Humidity:
- Input:
D2 (PD2)
- Input:
- Photoresistor:
- Type: ADC
- Input:
A0 (PC0)
- Temperature & Humidity:
- Mode: Timer0 phase-correct mode
- Output:
PD6
-
Controls DC motor for fan/air conditioner operations.
-
DC motor
- '+' :
PD3 - '-' :
GND
- '+' :
- Details of communication protocols and methods with ESP32.
-
Mode: 2 stop bits, 8 data bits, no parity bits
-
Atmega Pin:
- TX -
TX - RX -
RX - GND -
GND
- TX -
-
ESP32 Pin:
- TX -
GPIO 7 - RX -
GPIO 8 - GND -
GND
- TX -
-
Master: Atmega 328P
-
Atmega Pin:
- SCK -
13 - MISO -
12 - MOSI -
11 - CS / SS -
10
- SCK -
-
Slave: ESP32 (use ESP32SPISLAVE library)
-
ESP32 Pin:
- SCK -
GPIO 5 - MISO -
GPIO 21 - MOSI -
GPIO 19 - CS / SS -
GPIO 33
- SCK -
- Integration details with Blynk app for remote monitoring and control.
After a series of designs and tests, we found out that Atmega328P can only receive 4 Bytes of data at once under interrupt mode. eg, buffer[4]
Beacause of time constrain, we do not have enough time to do more test, as a result, we need to embrace this fact. That means we need to use only 4 byte of data to create a very short and efficient communication protocol.
- Buffer Size: 4 Bytes (
buffer[4]) - Buffer Composition:
buffer[0]: Instruction Identifierbuffer[1]: Data Byte 1 (if needed)buffer[2]: Data Byte 2 (if needed)buffer[3]: Ending Identifier
- A: Open curtain
- B: Close curtain
- C: Toggle air-conditioner
- D: Not used
- E: Set time to open curtain
- F: Set time to close curtain
- G: Set temperature to open air-conditioner
- H: Set temperature to close air-conditioner
- I: Set current time
- J: Smart decision switch for curtain
- K: Smart decision switch for air-conditioner
- X: Current time
- Y: Current temperature and humidity
- Z: Not Used
- On/Off Signal Instructions (A, B, C, J, K): Do not require additional data.
- Temperature and Humidity Instructions (G, H, Y):
buffer[2]: Humidity data (int to char + 32 for visibility)buffer[3]: Temperature data (int to char + 32 for visibility)
- Time Transmit Instructions (E, F, I, X):
buffer[2]: Hour data (int to char + 32 for visibility)buffer[3]: Minute data (int to char + 32 for visibility)
- Data in
intformat is converted tochar + 32. This is for debugging purposes, as ASCII codes become visible starting from 32.