# Production-Grade Design: Option B - Solid-State Relay (SSR)

## Overview
This design replaces the mechanical Songle SRD-05VDC-SL-C relays (K1‑K4) with **solid‑state relays (SSRs)** having built‑in 4000 VAC reinforced insulation. SSRs have no moving parts, eliminate contact arcing, and typically offer longer life and silent operation. The driving circuit uses optocouplers for galvanic isolation between the ESP32 GPIO and the SSR input.

## SSR Selection: Crydom ODN2225 (or equivalent)
| Parameter | Value |
|-----------|-------|
| Part Number | ODN2225 (Crydom) — or Panasonic AQ222S |
| Input Voltage | 3‑32 VDC (ESP32 GPIO‑compatible) |
| Output Current | 2 A (continuous) at 250 VAC |
| Output Voltage | 250 VAC (max) |
| Input/Output Isolation | 4000 VAC (reinforced, per IEC 60335‑1) |
| Output Type | Zero‑cross (recommended for mains) |
| Package | 4‑pin DIP (PC mount) |
| Status LED | Built‑in (output side, optional) |
| Coil/Drive Resistance | ~1 kΩ at 25 mA |

**Why an SSR for this design:**
- 4000 VAC internal insulation = no PCB creepage exemption needed
- Zero‑cross switching reduces EMI and inrush current
- No arcing, no contact wear, silent operation
- Input circuit (LED + resistor) directly compatible with ESP32 GPIO
- Available in through‑hole PC mount, easy to hand‑solder
- Widely used in industrial and appliance controls

**For 4‑relay design:** Use 4 separate SSRs (one per channel) or a 4‑channel module (e.g., Omron G3NA‑210B).

## Drive Circuit per Relay (Production‑Grade)

### Schematic (per SSR, K1‑K4)

```
       ESP32 GPIO
          (0 or 5 V)
               |
              === 2.2 kΩ (1/4 W)
               |
              ===  (GPIO pin)
               |
          GND --+---||---+  (cathode to GND, anode to resistor)
               |       |
              LED   1 kΩ  (base resistor, if using transistor)
               |       |
              ===       ===
               |       |
              GND      GND
```

**Simplified (direct, no transistor):**
- ESP32 GPIO -- 2.2 kΩ resistor -- SSR INPUT ANODE
- SSR INPUT CATHODE -- 1 kΩ resistor -- GND
- This limits GPIO current to ~2.5 mA (well within ESP32 absolute max 40 mA)
- SSR energises when GPIO = 5 V, de‑energises when GPIO = 0 V

**With transistor (for extra margin):**
- ESP32 GPIO -- 220 Ω -- transistor BASE (S8050 or 2N2222)
- transistor Emitter -- GND
- transistor COLLECTOR -- 2.2 kΩ -- SSR INPUT ANODE
- SSR INPUT CATHODE -- 1 kΩ -- GND
- This gives ~10 mA base current, ensuring full SSR turn‑on

### Wiring the Output (Mains Side)
- **SSR COM (common terminal)**: Connect to AC_N (neutral) or AC_L (live), consistent for all relays
- **SSR NO (normally open)**: Connect to the switched load (L1‑L4 at J9)
- **SSR NC (normally closed)**: Not used in this design (leave open)
- **Neutral**: Distribute AC_N from J8 pin 4 to all SSR COM terminals and the load neutral terminals

**Example wiring for K1:**
- K1 INPUT: ESP32 GPIO25 -- 2.2 kΩ -- K1 INPUT ANODE
- K1 INPUT CATHODE -- 1 kΩ -- GND rail
- K1 OUTPUT COM: J8 pin 4 (AC_N) or dedicated neutral terminal
- K1 OUTPUT NO: Route to J9 L1 (switched live)
- When GPIO25 = 5 V → K1 conducts → L1 connected to neutral (load energised)
- When GPIO25 = 0 V → K1 off → L1 de‑energised

### 4‑Relay Wiring Summary
| Relay | GPIO | SSR Input | Output NO | Use |
|-------|------|-----------|-----------|-----|
| **K1** | GPIO25 | 2.2 kΩ + 1 kΩ | J9 L1 | Load 1 |
| **K2** | GPIO26 | 2.2 kΩ + 1 kΩ | J9 L2 | Load 2 |
| **K3** | GPIO27 | 2.2 kΩ + 1 kΩ | J9 L3 | Load 3 |
| **K4** | GPIO32 | 2.2 kΩ + 1 kΩ | J9 L4 | Load 4 |

**All COM terminals**: Connected together and to J8 pin 4 (AC_N) or a dedicated neutral terminal block.

### 2. PCB Layout Changes

#### 1. Footprint Swap
- **Remove:** Songle SRD-05VDC-SL-C (K1‑K4), 5‑pin DIP, 19.8 × 15.6 mm
- **Add:** 4× SSR (e.g., Crydom ODN2225), 4‑pin DIP, ~15 × 10 mm body
- **Position:** Same general area (x103‑118, y12‑56), but smaller footprint
- **Pins mapped:**
  - Pin 1 = Input ANODE (connect to GPIO via resistor)
  - Pin 2 = Input CATHODE (connect to GND via resistor)
  - Pin 3 = OUTPUT COM (connect to neutral)
  - Pin 4 = OUTPUT NO (connect to switched load L1‑L4)

#### 2. Creepage/Clearance — Inherently Safe
Since each SSR has **4000 VAC internal insulation** between input and output,
the PCB checker does NOT need same‑relay exemptions. However, good practice
still requires:
- ≥8 mm between INPUT nets (GPIO, resistors) and OUTPUT nets (COM, NO, load)
- ≥8 mm between OUTPUT nets and DevKit SELV (though the SSR provides the barrier)
- The checker `check_board_production.py` can remain strict (≥8 mm everywhere) or be
  relaxed to note the SSR as the primary barrier — either way complies with IEC 60335‑1.

#### 3. Revised Layout Zoning (130 × 70 mm)
```
 y=0mm (top) ──────────────────────────────── y=70mm (bottom)
                                                                    
   K1   K2                       ⓿  ← row 1, y≈12mm              
    │                              │                              
   K3 K4                       ⓿  ← row 2, y≈56mm              
                                                                    
   HLK-PM01 (x78‑112, y8‑28)                                     
   J8 mains terminal (x58‑68, y5‑26)                            
   MOV (x57‑68, y31‑40)                                         
   Cable holes: 20mm@(99,43), 12mm@(80,55)                       
   OLED: x108‑118, y4‑8 (top‑right)                             
   DevKit: x25‑53 (left, SELV)                                  
   5V rail: HLK output, optically isolated from mains via SSR  
```

**Key routing rules:**
- SSRs at x103‑118, y12‑56 (two rows of two)
- Each SSR: INPUT side (GPIO resistors) connects left toward DevKit
- Each SSR: OUTPUT side (COM/NO) connects right toward J9 terminal block
- 8 mm margin kept from OLED, cable holes, HLK, LED
- No relay driver transistors needed (SSR drive is direct from GPIO)
- J9 switched‑load terminal block at x118, y8‑23 (unchanged)
- Optional: small heatsink pad under each SSR if switching >1 A continuous

#### 3. Updated BOM Item
| Item | Production Part | Qty | Notes |
|------|-----------------|-----|-------|
| Solid‑state relay | Crydom ODN2225 (or Panasonic AQ222S) | 4 | 4000 VAC SSR, zero‑cross |
| Input resistor (per relay) | 2.2 kΩ, 1/4 W | 4 | ESP32 GPIO current limit |
| Feedback resistor (per relay) | 1 kΩ, 1/4 W | 4 | SSR input current return |
| Transistor (optional) | S8050 (if using driver) | 4 | Optional, for extra margin |
| Load terminal | TERM‑4X5.08 (J9) | 1 | Switched live outputs L1‑L4 |

#### 4. Checker: `check_board_ssr.py` (Production‑Grade, but Simplified)
Since the SSR provides 4000 VAC internal insulation, the checker can be
**less strict** than the pure‑PCB version, but still enforce basic safety:

```python
# check_board_ssr.py — simplified production version
# NO exemptions for GPIO‑to‑SSR‑input tracks,
# but the SSR itself is the primary barrier.
# All other mains‑SELV gaps ≥8 mm as normal.
```

Key checks:
- ≥8 mm between GPIO resistor tracks and 5 V rail (optional, for safety)
- ≥8 mm between SSR output COM/NO and DevKit SELV pads
- ≥8 mm between SSR input tracks and any mains tracks (AC_L, AC_N, etc.)
- No same‑relay exemptions needed (SSR internal insulation documented)

Alternatively, **omit the checker entirely** for the SSR option and rely on:
- The SSR datasheet 4000 VAC rating
- The PCB keeping ≥8 mm between input and output copper pours
- Standard IEC 60335‑1 end‑product testing (hipot 3000–4000 VAC)

#### 5. Comparison: Option A vs. Option B

| Feature | Option A: Certified Relay | Option B: Solid‑State Relay |
|---------|---------------------------|------------------------------|
| **Component** | Omron G5LE-1 (4000 VAC) | Crydom/ Panasonic SSR (4000 VAC) |
| **Moving parts** | Yes (mechanical) | No (solid‑state) |
| **Typical life** | 10⁵ – 10⁶ operations | 10⁷ – 10⁸ operations |
| **Contact arcing** | Yes (per switching) | None (zero‑cross or random) |
| **Coil/Drive voltage** | 5 VDC, 70 mA peak | 3‑32 VDC logic, 5‑10 mA |
| **Output speed** | Mechanical (~10 Hz max) | Instantaneous (no bounce) |
| **EMI/Noise** | Contact bounce, arc suppression | minimal |
| **Price (each)** | ~$3.50 – $6.00 | ~$4.00 – $8.00 |
| **Gate driver** | Transistor + flyback diode | Direct (2.2 kΩ + 1 kΩ) or with transistor |
| **Best for** | Prototypes needing relay action | High‑reliability, silent operation |

### 5. Migration Path from Prototype (Original Design)
| Step | Action |
|------|--------|
| 1 | Remove K1‑K4 Songle relay footprints from generator |
| 2 | Add 4× SSR footprints (ODN2225 or equivalent) at same positions (x103‑118) |
| 3 | Add input resistors (2.2 kΩ + 1 kΩ) connecting to J4‑J7 GPIO headers |
| 4 | Route OUTPUT COM/NO tracks to J9 L1‑L4 terminal block |
| 5 | Connect all SSR COM terminals together and to J8 pin 4 (AC_N) |
| 6 | Remove relay driver transistors (S8050 + 1 kΩ) — not needed |
| 7 | Run `check_board_ssr.py` or verify ≥8 mm between input/output copper |
| 8 | Update BOM, CPL, NETLIST with SSR part numbers and pinouts |
| 9 | Update READMEs: "Uses solid‑state relays with 4000 VAC reinforced insulation; |
|    GPIO drivers are optocoupler‑free direct‑resistor; ≥8 mm PCB creepage |
|    enforced between input and output tracks." |
| 10 | Test each relay by toggling the ESP32 GPIO and verifying load switching |

### 6. Safety Approval Notes for Option B
- **Primary insulation:** Provided by the SSR's 4000 VAC internal barrier
- **Secondary consideration:** PCB creepage between GPIO‑drive tracks and 5 V rail
- **Tertiary consideration:** PCB creepage between SSR output copper and DevKit GPIOs
- **All three are optional** if the SSR is mounted and wired per its datasheet,
  but good engineering practice still enforces ≥8 mm where copper overlaps.
- **Label the enclosure:** "Solid‑state relays — 4000 VAC reinforced insulation —
  do not open under voltage"
- **Include in end‑product manual:** Switching diagrams, GPIO table, fuse rating
  (recommend 500 mA slow‑blow for SSR driver protection, though typically not
  needed since SSR input current is <30 mA)

### 7. Recommendation Summary

| Choose Option A if: | Choose Option B if: |
|---------------------|----------------------|
| You need mechanical relay action (e.g., pilot lights, audible switching) | You need silent, long‑life operation |
| You want the absolute simplest PCB (no optocouplers) | You want the simplest driver circuit (2 resistors per relay) |
| You’re already using mechanical relays in other product sections | You’re designing for vibration/shock robustness |
| Cost is the primary driver (~$3.50/relay) | Cost is secondary to reliability/silence (~$6/relay) |
| You need DPDT switching per relay | You need only single‑pole switching (SSR NO) is sufficient |

**My recommendation:** **Option B (Solid‑State Relay)** for this design because:
- The driver circuit is simpler (2 resistors per relay, no transistors)
- No mechanical wear or contact arcing concerns
- Zero‑cross switching reduces EMI — beneficial for the ESP32's sensitive GPIOs
- The 4000 VAC internal insulation makes the PCB creepage requirements straightforward
- Silent operation is desirable for a wall‑unit product
- Comparable cost and easier certification case

---
*This design is suitable for production‑grade IEC 60335‑1 compliance when each SSR's 4000 VAC reinforced insulation is respected, the PCB keeps ≥8 mm between input and output copper areas, and the ESP32 GPIO drive is limited to ~2.5 mA via the 2.2 kΩ resistor.*