# Schematic Component List and Connection Guide

## Schematic Structure (Recommended)

### Page 1: Power Supply Section
- Power input via JST connector (J1 Pin 1)
- Voltage regulator (AMS1117-3.3)
- Input/output capacitors
- Power distribution

### Page 2: Main Controller (ESP32)
- ESP32-WROOM-32E module
- Decoupling capacitors
- Reset and boot buttons
- Status LEDs

### Page 3: Level Shifter and AC Interface
- TXB0104 level shifter
- AC connector (JST-XH)
- Signal connections

### Page 4: Programming Header (Optional)
- Header pins for external USB-to-Serial adapter
- Auto-reset connections

---

## Component List

### Page 1: Power Supply

| Ref | Component | Library | Symbol | Value | Notes |
|-----|-----------|---------|--------|-------|-------|
| U1 | Voltage Regulator | `Midea_ESP` | `AMS1117-3.3` | AMS1117-3.3 | 3.3V regulator |
| C1 | Capacitor | `Device` | `C` | 10µF | Input capacitor |
| C2 | Capacitor | `Device` | `C` | 10µF | Output capacitor |
| C3 | Capacitor | `Device` | `C` | 100nF | Input decoupling |
| C4 | Capacitor | `Device` | `C` | 100nF | Output decoupling |

**Note:** Power is supplied via J1 Pin 1 (+5V) from the AC unit connection. See Page 3 for J1 connector details.

**Connections:**
- **J1 Pin 1 (+5V)** → **U1 Pin 3 (IN)** (connect from Page 3 using net label `+5V_POWER`)
- **J1 Pin 1 (+5V)** → **C1 (one terminal)** (parallel connection - connect directly to +5V net)
- **J1 Pin 1 (+5V)** → **C3 (one terminal)** (parallel connection - connect directly to +5V net)
- **C1 (other terminal)** → **GND**
- **C3 (other terminal)** → **GND**
- **U1 Pin 2 (OUT)** → **+3V3 Power Rail** (connect to +3V3 power symbol)
- **U1 Pin 2 (OUT)** → **C2 (one terminal)** (parallel connection - connect directly to +3V3 net)
- **U1 Pin 2 (OUT)** → **C4 (one terminal)** (parallel connection - connect directly to +3V3 net)
- **C2 (other terminal)** → **GND**
- **C4 (other terminal)** → **GND**
- **U1 Pin 1 (GND)** → **GND**
- **U1 Pin TAB (GND)** → **GND**
- **J1 Pin 4 (GND)** → **GND** (connect from Page 3)

**Note:** 
- All capacitors are unpolarized (ceramic), so either terminal can connect to either net.
- **C1 and C3 are in PARALLEL** between +5V and GND (input filtering/decoupling)
- **C2 and C4 are in PARALLEL** between +3V3 and GND (output filtering/decoupling)

**Power Symbols:**
- Add `+3V3` power symbol (press `P`, select `+3V3`)
- Add `GND` power symbol (press `P`, select `GND`)
- Add `+5V` power symbol (press `P`, select `+5V`) - connects to J1 Pin 1 and level shifter

---

### Page 2: ESP32 Main Controller

| Ref | Component | Library | Symbol | Value | Notes |
|-----|-----------|---------|--------|-------|-------|
| U2 | ESP32 Module | `Midea_ESP` | `ESP32-WROOM-32E` | ESP32-WROOM-32E | Main MCU (onboard antenna) |
| C5 | Capacitor | `Device` | `C` | 100nF | VDD decoupling (Pin 2) |
| C6 | Capacitor | `Device` | `C` | 10µF | Bulk capacitor near module |
| SW1 | Reset Button | `Button_Switch_SMD` | `SW_PUSH` | - | Reset switch |
| SW2 | Boot Button | `Button_Switch_SMD` | `SW_PUSH` | - | Boot/Flash switch |
| R3 | Resistor | `Device` | `R` | 10kΩ | Reset pull-up |
| R4 | Resistor | `Device` | `R` | 10kΩ | Boot pull-up |
| LED1 | LED | `Device` | `LED` | - | WiFi status |
| LED2 | LED | `Device` | `LED` | - | BLE status |
| R1 | Resistor | `Device` | `R` | 220Ω | LED1 current limit |
| R2 | Resistor | `Device` | `R` | 220Ω | LED2 current limit |

**Power Connections (For ESP32-WROOM-32E with Only Pin 2 VDD Exposed):**
- **ESP32 Pin 2 (VDD)** → **+3V3 Power Rail**
  - **Note:** Only Pin 2 (VDD) is exposed on your module (onboard antenna variant)
  - **C5 (100nF):** **U2 Pin 2 (VDD)** → **C5 (one terminal)** → **+3V3**, **C5 (other terminal)** → **GND** (decoupling capacitor - required)
  - **C6 (10µF):** **U2 Pin 2 (VDD)** → **C6 (one terminal)** → **+3V3**, **C6 (other terminal)** → **GND** (bulk capacitor - recommended near module)
  - **Placement:** C5 and C6 must be placed as close as possible to Pin 2 (<5mm recommended)
- **ESP32 GND pins** (all exposed GND pins) → **GND**
  - **Note:** Connect all exposed GND pins to ground plane
  - **Typical GND pins:** Pin 1, and any other exposed GND pins on your module
- **Note:** Internal VDD pins are handled by the module internally - only external Pin 2 needs decoupling

**Critical Control Pins (Per Datasheet):**
- **U2 EN (Enable Pin) - Pin 3 in RF_Module library:**
  - **Function:** Active HIGH - enables ESP32 operation (must be HIGH for normal operation)
  - **Pull-up resistor:** R3 (10kΩ) → +3V3 (required by datasheet)
  - **Reset button:** SW1 connected to EN pin (active LOW reset - pulls EN LOW to reset)
  - **Connections:**
    - **U2.EN** → **R3 (10kΩ)** → **+3V3** (pull-up resistor)
    - **U2.EN** → **SW1 Pin 1** (reset button)
    - **SW1 Pin 2** → **GND** (when button pressed, EN goes LOW = reset)
  - **Note:** EN must be HIGH (3.3V) for ESP32 to operate. Pulling it LOW resets the chip.
- **U2 GPIO0 (Boot Mode Pin):**
  - **Function:** Boot mode selection
  - **HIGH (3.3V):** Normal boot from flash
  - **LOW (GND):** Download mode for flashing
  - **Pull-up resistor:** R4 (10kΩ) → +3V3 (required by datasheet)
  - **Boot button:** SW2 connected to GPIO0 (pull LOW for download mode)
  - **Connection:** U2.GPIO0 → R4 → +3V3, U2.GPIO0 → SW2 Pin 1, SW2 Pin 2 → GND

**GPIO Connections:**
- **U2 GPIO17 (UART1 TX):** → Label: `ESP32_TX` → Connect to Page 3 (U3.A1) - AC communication
- **U2 GPIO16 (UART1 RX):** → Label: `ESP32_RX` → Connect to Page 3 (U3.A2) - AC communication
- **U2 GPIO2:** → R1 (220Ω) → LED1 Anode → LED1 Cathode → GND (WiFi status indicator)
- **U2 GPIO4:** → R2 (220Ω) → LED2 Anode → LED2 Cathode → GND (BLE status indicator)
- **U2 GPIO1 (UART0 TX):** → Label: `UART_TX` → Connect to Page 4 (J2 Pin 3) [if programming header]
- **U2 GPIO3 (UART0 RX):** → Label: `UART_RX` → Connect to Page 4 (J2 Pin 4) [if programming header]

**Programming Header Connections (Optional):**
- **U2 GPIO0:** → Label: `DTR` → Connect to Page 4 (J2 Pin 5) - Auto-reset for flashing
- **U2 EN:** → Label: `RTS` → Connect to Page 4 (J2 Pin 6) - Auto-reset for flashing

**Note:** According to ESP32-WROOM-32E datasheet:
- **Power supply:** Must be stable 3.0V to 3.6V (we use 3.3V)
- **Peak current:** Up to 500mA during WiFi transmission
- **Decoupling:** 100nF ceramic capacitor required at exposed VDD pin (Pin 2)
- **Bulk capacitor:** 10µF recommended near module (C6)
- **PCB layout:** Decoupling capacitors must be placed as close as possible to Pin 2
- **Module variant:** Your module (onboard antenna) only exposes Pin 2 as VDD - internal VDD pins are handled by the module

**Button Connections:**
- **SW1 (Reset Button) - Connected to EN Pin (Pin 3 in RF_Module library):**
  - **SW1 Pin 1** → **U2.EN** (Enable pin - Pin 3 in RF_Module library)
  - **SW1 Pin 1** → **R3 (10kΩ)** → **+3V3** (pull-up resistor)
  - **SW1 Pin 2** → **GND**
  - **Function:** Pressing SW1 pulls EN LOW, which resets the ESP32
  - **Normal state:** EN is HIGH (3.3V) via R3 pull-up, ESP32 operates normally
  - **Reset state:** When button pressed, EN goes LOW (GND), ESP32 resets
- **SW2 (Boot Button) - Connected to GPIO0:**
  - **SW2 Pin 1** → **U2.GPIO0** (Boot mode pin)
  - **SW2 Pin 1** → **R4 (10kΩ)** → **+3V3** (pull-up resistor)
  - **SW2 Pin 2** → **GND**
  - **Function:** Pressing SW2 pulls GPIO0 LOW, which puts ESP32 in download mode
  - **Normal state:** GPIO0 is HIGH (3.3V) via R4 pull-up, ESP32 boots from flash
  - **Download mode:** When button pressed, GPIO0 goes LOW (GND), ESP32 enters download mode

**LED Connections:**
- LED1 Anode → R1 → U2.GPIO2
- LED1 Cathode → GND
- LED2 Anode → R2 → U2.GPIO4
- LED2 Cathode → GND

**Decoupling Capacitors (For Module with Only Pin 2 VDD Exposed):**
- **C5:** U2 Pin 2 (VDD) → GND (100nF ceramic, 0805 package)
  - **Purpose:** High-frequency decoupling for VDD pin
  - **Placement:** As close as possible to Pin 2 (<5mm)
- **C6:** U2 Pin 2 (VDD) → GND (10µF ceramic, 0805 package)
  - **Purpose:** Bulk capacitor for power supply stability
  - **Placement:** Near ESP32 module, close to Pin 2

**Note:** 
- Your ESP32-WROOM-32E module (onboard antenna) only exposes Pin 2 as VDD
- Internal VDD pins are handled internally by the module
- Only the exposed Pin 2 requires external decoupling capacitors
- C5 (100nF) for high-frequency decoupling
- C6 (10µF) for bulk power supply filtering

**PCB Layout Requirements:**
- **C5 (100nF):** Place **as close as possible** to Pin 2 (<5mm recommended)
- **C6 (10µF):** Place near ESP32 module, close to Pin 2
- **Trace width:** Use short, wide traces from Pin 2 to capacitors
- **Ground connection:** Connect capacitors to ground plane with short, wide traces
- **Power trace:** Use adequate trace width for 500mA peak current (minimum 0.5mm)

---

### Page 3: Level Shifter and AC Interface

| Ref | Component | Library | Symbol | Value | Notes |
|-----|-----------|---------|--------|-------|-------|
| U3 | Level Shifter | `Midea_ESP` | `TXB0104PWR` | TXB0104PWR | 4-channel level shifter (TSSOP-14) |
| J1 | AC Connector | `Connector_JST` | `JST_XH_B4B-XH-A` | - | 4-pin JST-XH |
| C14 | Capacitor | `Device` | `C` | 100nF | VCCA decoupling (U3 Pin 12) |
| C15 | Capacitor | `Device` | `C` | 100nF | VCCB decoupling (U3 Pin 11) |

**TXB0104PWR Pin Connections:**

**Low Voltage Side (3.3V - ESP32):**
- **U3 Pin 1 (A1)** → Net Label: `ESP32_TX` → Connect to Page 2 (U2.GPIO17)
- **U3 Pin 2 (A2)** → Net Label: `ESP32_RX` → Connect to Page 2 (U2.GPIO16)
- **U3 Pin 3 (A3)** → NC (Not Connected)
- **U3 Pin 4 (A4)** → NC (Not Connected)

**High Voltage Side (5V - AC):**
- **U3 Pin 9 (B1)** → Net Label: `AC_RX` → J1 Pin 2
- **U3 Pin 8 (B2)** → Net Label: `AC_TX` → J1 Pin 3
- **U3 Pin 7 (B3)** → NC (Not Connected)
- **U3 Pin 6 (B4)** → NC (Not Connected)

**Power (Per TXB0104 Datasheet):**
- **U3 Pin 12 (VCCA)** → **+3V3 Power Rail** (Low voltage side: 1.2V to 3.6V, we use 3.3V)
  - **C14 (100nF)** → **U3 Pin 12 (VCCA)** → **+3V3**, **C14 (other terminal)** → **GND** (decoupling capacitor - required by datasheet)
- **U3 Pin 11 (VCCB)** → **+5V Power Rail** (High voltage side: 1.65V to 5.5V, we use 5V)
  - **C15 (100nF)** → **U3 Pin 11 (VCCB)** → **+5V**, **C15 (other terminal)** → **GND** (decoupling capacitor - required by datasheet)
- **U3 Pin 10 (OE)** → **+3V3 Power Rail** (Output Enable - referenced to VCCA per datasheet)
  - **Note:** OE input circuit is referenced to VCCA (not VCCB) per datasheet
  - **Function:** HIGH (3.3V) = enabled, LOW (GND) = high-impedance state
- **U3 Pin 5 (GND)** → GND
- **U3 Pin 13 (GND)** → GND
- **U3 Pin 14 (GND)** → GND

**Critical Requirement (Per Datasheet):**
- **VCCA must NOT exceed VCCB:** 3.3V ≤ 5V ✓ (correct)
- **Decoupling capacitors:** 100nF ceramic capacitors required on both VCCA and VCCB (C14, C15)

**AC Connector (J1) - JST-XH Connector on PCB:**
- **J1 Pin 1** → **+5V Power Rail** → Connect to Page 1 (U1 Pin 3 via capacitors) - **Power input for PCB**
- **J1 Pin 2** → Net Label: `AC_RX` → U3 Pin 9 (B1)
- **J1 Pin 3** → Net Label: `AC_TX` → U3 Pin 8 (B2)
- **J1 Pin 4** → **GND** → Connect to all GND nets

**Note:** J1 is a JST-XH connector mounted on the PCB. This connector provides:
- **Power input** (Pin 1: +5V) - Powers the entire PCB
- **AC communication** (Pins 2-3: UART signals)
- **Ground** (Pin 4: GND)

You will connect a cable with a matching JST-XH connector on one end to connect to your AC unit. The other end of the cable connects to J1 on the PCB.

**Net Labels to Use:**
- `ESP32_TX` - ESP32 transmit to level shifter
- `ESP32_RX` - ESP32 receive from level shifter
- `AC_TX` - AC transmit line
- `AC_RX` - AC receive line

---

### Page 4: Programming Header (Required for Flashing)

| Ref | Component | Library | Symbol | Value | Notes |
|-----|-----------|---------|--------|-------|-------|
| J2 | Header | `Connector_PinHeader_2.54mm` | `PinHeader_2x04_P2.54mm_Vertical` | - | 2x4 programming header (8 pins total, 6 used) |
| R5 | Resistor | `Device` | `R` | 10kΩ | DTR pull-up (optional but recommended) |
| R6 | Resistor | `Device` | `R` | 10kΩ | RTS pull-up (optional but recommended) |

**Programming Header (J2) Pinout - 2x4 Header (2.54mm pitch):**

**Pin Layout (Top View):**
```
┌─────────────┐
│ 1  2  3  4  │  ← Top row
│ 5  6  7  8  │  ← Bottom row
└─────────────┘
```

| J2 Pin | Signal | ESP32 Connection | Description |
|--------|--------|------------------|-------------|
| 1 | +3V3 | +3V3 Power Rail | Optional - Power ESP32 from programmer |
| 2 | GND | GND | Ground reference (required) |
| 3 | UART_TX | U2.GPIO1 (UART0 TX) | ESP32 transmits to programmer |
| 4 | UART_RX | U2.GPIO3 (UART0 RX) | ESP32 receives from programmer |
| 5 | DTR | U2.GPIO0 | Data Terminal Ready (auto-reset for flashing) |
| 6 | RTS | U2.EN | Request To Send (auto-reset for flashing) |
| 7 | NC | - | Not connected (spare) |
| 8 | NC | - | Not connected (spare) |

**Connections:**
- **J2 Pin 1** → **+3V3 Power Rail** (optional - for powering from programmer)
- **J2 Pin 2** → **GND** (required)
- **J2 Pin 3** → Net Label: `UART_TX` → Connect to Page 2 (U2.GPIO1) - ESP32 TX
- **J2 Pin 4** → Net Label: `UART_RX` → Connect to Page 2 (U2.GPIO3) - ESP32 RX
- **J2 Pin 5** → Net Label: `DTR` → Connect to Page 2 (U2.GPIO0) - Auto-reset
- **J2 Pin 6** → Net Label: `RTS` → Connect to Page 2 (U2.EN) - Auto-reset
- **J2 Pin 7** → **NC** (Not Connected - spare for future use)
- **J2 Pin 8** → **NC** (Not Connected - spare for future use)

**Flashing with 2x4 Header:**
- **Automatic** - no buttons needed:
  - DTR/RTS signals automatically put ESP32 in boot mode
  - Just run `esptool` or ESPHome - it handles everything
  - Much easier and faster

**Note:** Pins 7 and 8 are spare and can be used for future expansion if needed.

**Auto-Reset Circuit (Optional but Recommended):**
- **J2 Pin 5 (DTR)** → R5 → +3V3
- **J2 Pin 5 (DTR)** → U2.GPIO0 (Boot mode control)
- **J2 Pin 6 (RTS)** → R6 → +3V3
- **J2 Pin 6 (RTS)** → U2.EN (Reset control)

**Note:** The pull-up resistors (R5, R6) are optional. Most USB-to-Serial adapters have built-in pull-ups, but adding them ensures reliable operation.

**Net Labels:**
- `UART_TX` - ESP32 UART TX to programmer
- `UART_RX` - ESP32 UART RX from programmer
- `DTR` - Data Terminal Ready (auto-reset)
- `RTS` - Request To Send (auto-reset)

**External USB-to-Serial Adapter Connections:**
When connecting an external USB-to-Serial adapter (e.g., CP2102, CH340, FT232):
- Adapter **VCC** → J2 Pin 1 (optional - only if you want to power ESP32 from adapter)
- Adapter **GND** → J2 Pin 2
- Adapter **RX** → J2 Pin 3 (UART_TX from ESP32)
- Adapter **TX** → J2 Pin 4 (UART_RX to ESP32)
- Adapter **DTR** → J2 Pin 5 (auto-reset)
- Adapter **RTS** → J2 Pin 6 (auto-reset)

---

## How to Add Components in KiCad

### Step 1: Add Components
1. Press **`A`** (or click "Place Symbol" tool)
2. In the symbol chooser, search for the component
3. Click to place on schematic
4. Press **`E`** to edit properties (set Reference, Value)

### Step 2: Add Power Symbols
1. Press **`P`** (or click "Place Power Port" tool)
2. Select power symbol: `+3V3`, `+5V`, or `GND`
3. Click to place
4. All symbols with the same name are automatically connected

### Step 3: Add Wires
1. Press **`W`** (or click "Place Wire" tool)
2. Click on a pin, then click on destination pin
3. KiCad will route the wire automatically

### Step 4: Add Net Labels (for cross-page connections)
1. Press **`L`** (or click "Place Net Label" tool)
2. Type the net name (e.g., `ESP32_TX`)
3. Click on the wire to attach the label
4. Use the same label name on other pages to connect them

### Step 5: Add Hierarchical Sheets (for multiple pages)
1. Press **`S`** (or click "Place Hierarchical Sheet" tool)
2. Draw a rectangle for the sheet
3. Double-click to edit sheet properties
4. Set sheet name and file name

---

## Connection Summary by Net

### +3V3 Net (3.3V Power Rail)
- U1 Pin 2 (OUT)
- U2 All VDD pins (1, 3, 14, 21, 22, 27, 28, 33, 42)
- U3 Pin 12 (VCCA)
- U3 Pin 10 (OE)
- J2 Pin 1 (optional - if powering from programmer)
- R1, R2, R3, R4, R5, R6 (one end of pull-up resistors)
- LED1, LED2 anodes (via resistors)

### +5V Net (5V Power Rail)
- J1 Pin 1 (Power input from AC connection)
- U1 Pin 3 (IN)
- U3 Pin 11 (VCCB)

### GND Net (Ground)
- J1 Pin 4 (Ground from AC connection)
- U1 Pin 1 and TAB
- U2 All GND pins (2, 4, 13, 15, 20, 23, 26, 29, 34, 38, 40)
- U3 Pins 5, 13, 14 (GND)
- J2 Pin 2 (GND)
- All capacitor negative terminals
- SW1 Pin 2, SW2 Pin 2
- LED1, LED2 cathodes

### ESP32_TX Net
- U2 GPIO17 → U3 Pin 1 (A1)

### ESP32_RX Net
- U2 GPIO16 → U3 Pin 2 (A2)

### AC_TX Net
- U3 Pin 8 (B2) → J1 Pin 3

### AC_RX Net
- U3 Pin 9 (B1) → J1 Pin 2

### UART_TX Net (if programming header included)
- U2 GPIO1 → J2 Pin 3

### UART_RX Net (if programming header included)
- U2 GPIO3 → J2 Pin 4

### DTR Net (if programming header included)
- J2 Pin 5 → U2 GPIO0

### RTS Net (if programming header included)
- J2 Pin 6 → U2 EN

---

## Recommended Schematic Layout

### Option 1: Single Page (Simple)
- Left: Power supply (powered from J1)
- Center: ESP32 with peripherals
- Right: Level shifter and AC connector (J1 provides power)
- Bottom: Programming Header (if included)

### Option 2: Multiple Pages (Organized)
- **Page 1**: Power Supply (USB input, regulator, capacitors)
- **Page 2**: ESP32 Main (MCU, buttons, LEDs, decoupling caps)
- **Page 3**: Level Shifter & AC Interface
- **Page 4**: Programming Header (optional)

Use hierarchical sheets or net labels to connect between pages.

---

## Tips

1. **Use Net Labels** for cross-page connections instead of wires
2. **Group related components** together
3. **Place power symbols** near components that need them
4. **Use buses** if you have multiple similar signals (not needed here)
5. **Add text notes** to document special connections
6. **Run ERC** (Electrical Rules Check) after completing: Tools → Electrical Rules Checker

---

## Component Values Summary

| Component | Value | Purpose |
|-----------|-------|---------|
| U1 | AMS1117-3.3 | 5V to 3.3V regulator |
| U2 | ESP32-WROOM-32E | Main microcontroller |
| U3 | TXB0104PWR | 3.3V ↔ 5V level shifter |
| J2 | 6-pin Header | Programming header (optional) |
| R1, R2 | 220Ω | LED current limiting |
| R3, R4 | 10kΩ | Button pull-up resistors |
| R5, R6 | 10kΩ | DTR/RTS pull-up resistors (optional) |
| C1, C2 | 10µF | Power supply capacitors |
| C3, C4 | 100nF | Decoupling capacitors |
| C5-C13 | 100nF | ESP32 decoupling |
| C14, C15 | 100nF, 10µF | CP2102N decoupling |

---

## Next Steps After Schematic

1. **Annotate Components**: Tools → Annotate Schematic
2. **Electrical Rules Check**: Tools → Electrical Rules Checker
3. **Assign Footprints**: Tools → Assign Footprints
4. **Generate Netlist**: Tools → Generate Netlist
5. **Open PCB Editor**: Click "Open PCB in Board Editor"

