# Environmental Control Systems

Deep dive into vertical farm environmental management.

## Overview

Environmental control is the heart of vertical farming. Unlike outdoor agriculture, every parameter is controllable and optimizable.

```
┌─────────────────────────────────────────────────────────────────┐
│                  ENVIRONMENTAL CONTROL SYSTEM                    │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  ┌────────────┐    ┌────────────┐    ┌────────────┐            │
│  │TEMPERATURE │    │  HUMIDITY  │    │    CO2     │            │
│  │   Control  │    │   Control  │    │  Control   │            │
│  │            │    │            │    │            │            │
│  │ HVAC       │    │ Humidifier │    │ Injection  │            │
│  │ Heat Pump  │    │ Dehumid.   │    │ Generator  │            │
│  └─────┬──────┘    └─────┬──────┘    └─────┬──────┘            │
│        │                 │                 │                     │
│        └─────────────────┼─────────────────┘                     │
│                          │                                       │
│                    ┌─────▼─────┐                                │
│                    │  CENTRAL  │                                │
│                    │ CONTROLLER│                                │
│                    └─────┬─────┘                                │
│                          │                                       │
│        ┌─────────────────┼─────────────────┐                     │
│        │                 │                 │                     │
│  ┌─────▼──────┐    ┌─────▼─────┐    ┌─────▼──────┐            │
│  │  LIGHTING  │    │   WATER   │    │ NUTRIENTS  │            │
│  │   Control  │    │  Control  │    │  Control   │            │
│  │            │    │            │    │            │            │
│  │ LEDs       │    │ Irrigation │    │ Dosing     │            │
│  │ Spectrum   │    │ pH adjust  │    │ EC monitor │            │
│  └────────────┘    └────────────┘    └────────────┘            │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘
```

## Temperature Control

### Target Ranges by Crop Type

| Crop Category | Day Temp (°C) | Night Temp (°C) | Differential |
|---------------|---------------|-----------------|--------------|
| Leafy Greens | 18-22 | 15-18 | 3-5°C |
| Herbs | 20-25 | 18-22 | 2-4°C |
| Fruiting | 22-28 | 18-22 | 4-6°C |
| Microgreens | 18-21 | 16-19 | 2-3°C |

### Control Strategies

```typescript
interface TemperatureControl {
  mode: 'manual' | 'scheduled' | 'adaptive' | 'ai_optimized';

  // Setpoints
  daySetpoint: number;
  nightSetpoint: number;

  // Deadband (prevent oscillation)
  deadband: number;  // ±1°C typical

  // Control outputs
  coolingStage: 0 | 1 | 2 | 3;  // Multi-stage cooling
  heatingStage: 0 | 1 | 2 | 3;  // Multi-stage heating
}
```

### HVAC Systems

| System Type | Pros | Cons | Best For |
|-------------|------|------|----------|
| Split AC | Low cost | Limited capacity | Small rooms |
| Mini-split | Zoned control | Moderate cost | Medium facilities |
| Heat Pump | Efficient, heat recovery | Higher upfront | Production facilities |
| Chilled Water | Scalable, precise | Complex, expensive | Large operations |

## Humidity Control

### Vapor Pressure Deficit (VPD)

VPD is the key metric for plant transpiration:

```
VPD = Saturation Pressure - Actual Vapor Pressure

Optimal VPD by Stage:
- Seedling: 0.4-0.8 kPa (high humidity)
- Vegetative: 0.8-1.2 kPa (moderate)
- Flowering: 1.0-1.5 kPa (lower humidity)
```

### VPD Calculation

```typescript
function calculateVPD(tempC: number, humidityPercent: number): number {
  // Saturation vapor pressure (Tetens equation)
  const svp = 0.6108 * Math.exp((17.27 * tempC) / (tempC + 237.3));

  // Actual vapor pressure
  const avp = svp * (humidityPercent / 100);

  // VPD in kPa
  return svp - avp;
}
```

### Humidification Methods

| Method | Droplet Size | Coverage | Energy | Best For |
|--------|-------------|----------|--------|----------|
| Misting | 20-50 µm | Wide | Low | Propagation |
| Ultrasonic | 1-5 µm | Targeted | Low | Small zones |
| Fog | 5-20 µm | Wide | Medium | Large areas |
| Evaporative | N/A | Wide | Low | Arid climates |

### Dehumidification

```
Sources of Humidity:
├── Plant transpiration: 95%+ of water uptake
├── Irrigation: Evaporation from growing media
├── Human activity: Breathing, sweating
└── Fresh air: Outdoor humidity

Removal Methods:
├── HVAC: Condenses on evaporator coil
├── Dedicated dehumidifier: Efficient for high loads
├── Desiccant: Continuous, no condensate
└── Ventilation: If outdoor humidity lower
```

## CO2 Enrichment

### Why Enrich?

```
Ambient CO2:    ~420 ppm
Optimal Growth: 800-1200 ppm
Maximum Benefit: 1500 ppm

Photosynthesis increases ~30-50% with enrichment
```

### CO2 Sources

| Source | Cost | Control | Safety | Best For |
|--------|------|---------|--------|----------|
| Tank (compressed) | Medium | Excellent | Safe | Small/medium |
| Generator (propane) | Low | Good | Heat/humidity | Sealed rooms |
| Fermentation | Very low | Poor | Safe | Hobby |
| Air capture | High | Excellent | Safe | Large scale |

### Control Strategy

```typescript
interface CO2Control {
  targetPpm: number;
  hysteresis: number;  // ±50 ppm typical

  // Only enrich when lights on
  enrichDuringLightsOnly: boolean;

  // Integration with ventilation
  pauseDuringVentilation: boolean;

  // Safety limits
  maxPpm: 2000;  // Worker safety
  alarmPpm: 1800;
}
```

## Lighting Systems

### Light Spectrum

```
Wavelength Ranges:
├── UV-A (315-400nm): Compact growth, secondary metabolites
├── Blue (400-500nm): Vegetative growth, compact structure
├── Green (500-565nm): Canopy penetration
├── Red (620-700nm): Photosynthesis, flowering
└── Far-Red (700-800nm): Shade avoidance, flowering

Optimal Ratios (general):
- Vegetative: Blue 30%, Red 60%, Other 10%
- Flowering: Blue 20%, Red 70%, Other 10%
```

### LED Fixture Types

| Type | Spectrum | Efficiency | Cost | Best For |
|------|----------|------------|------|----------|
| Full Spectrum | White + Red/Blue | Good | Low | General |
| Red/Blue | Optimized peaks | High | Medium | Leafy greens |
| Tunable | Adjustable | Good | High | Research, multi-crop |
| Sunlight Replica | Full PAR + UV | Excellent | Very High | Premium produce |

### Light Metrics

```
PPFD (µmol/m²/s): Instantaneous light intensity
DLI (mol/m²/day): Daily light integral = PPFD × hours × 3600 / 1,000,000

Targets by Crop:
├── Microgreens: DLI 8-12
├── Lettuce: DLI 12-17
├── Basil: DLI 15-20
├── Tomatoes: DLI 22-30
└── Cannabis: DLI 40-65
```

## Nutrient Delivery

### Solution Management

```typescript
interface NutrientSolution {
  // Primary monitoring
  ec: number;  // Electrical Conductivity (mS/cm)
  ph: number;  // Target 5.5-6.5

  // Temperature
  tempC: number;  // Target 18-22°C

  // Dissolved oxygen
  doPpm: number;  // Target >6 ppm

  // Macro nutrients (ppm)
  nitrogen: number;    // 150-250
  phosphorus: number;  // 30-60
  potassium: number;   // 150-300
  calcium: number;     // 150-250
  magnesium: number;   // 40-80
  sulfur: number;      // 50-100
}
```

### Dosing Systems

```
┌─────────────────────────────────────────────────────────────┐
│                    DOSING SYSTEM                             │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  Stock Solutions                                             │
│  ┌─────┐  ┌─────┐  ┌─────┐  ┌─────┐  ┌─────┐  ┌─────┐     │
│  │  A  │  │  B  │  │CalMag│  │pH Up│  │pH Dn│  │Sili │     │
│  └──┬──┘  └──┬──┘  └──┬──┘  └──┬──┘  └──┬──┘  └──┬──┘     │
│     │        │        │        │        │        │          │
│     ▼        ▼        ▼        ▼        ▼        ▼          │
│  ┌────────────────────────────────────────────────────┐    │
│  │                  DOSING PUMPS                       │    │
│  │   Peristaltic pumps: Precise, low maintenance      │    │
│  └────────────────────────────────────────────────────┘    │
│                          │                                  │
│                          ▼                                  │
│  ┌────────────────────────────────────────────────────┐    │
│  │                  MIXING TANK                        │    │
│  │   - EC sensor                                       │    │
│  │   - pH sensor                                       │    │
│  │   - Temperature sensor                              │    │
│  │   - Level sensor                                    │    │
│  └────────────────────────────────────────────────────┘    │
│                          │                                  │
│                          ▼                                  │
│  ┌────────────────────────────────────────────────────┐    │
│  │                  GROWING ZONES                      │    │
│  └────────────────────────────────────────────────────┘    │
│                                                              │
└─────────────────────────────────────────────────────────────┘
```

## Air Circulation

### Airflow Requirements

```
Purposes:
├── Temperature uniformity
├── Humidity distribution
├── CO2 distribution
├── Plant strengthening (thigmomorphogenesis)
└── Disease prevention

Velocity Targets:
├── At canopy: 0.3-0.5 m/s
├── Avoid dead spots
├── Avoid excessive wind stress
```

### Fan Types

| Fan Type | Use | Placement |
|----------|-----|-----------|
| Circulation | Air mixing | Throughout canopy |
| Oscillating | Variable airflow | Above canopy |
| Exhaust | Heat/humidity removal | High in room |
| Intake | Fresh air, CO2 dilution | Low in room |

## Sensor Networks

### Sensor Placement

```
Zone Layout with Sensors:

    ┌─────────────────────────────────┐
    │    [T/H]           [T/H]        │  [T/H] = Temp/Humidity
    │      ●───────────────●          │
    │      │     [CO2]     │          │  [CO2] = CO2 sensor
    │      │       ●       │          │
    │  ┌───┴───────────────┴───┐      │  [PAR] = Light sensor
    │  │      [PAR]  [PAR]     │      │
    │  │        ●      ●       │ Zone │  [EC]  = EC sensor
    │  │    ▓▓▓▓▓▓▓▓▓▓▓▓▓▓    │      │
    │  │    ▓▓ Plants ▓▓▓▓    │      │  [pH]  = pH sensor
    │  │    ▓▓▓▓▓▓▓▓▓▓▓▓▓▓    │      │
    │  │  [EC] [pH]           │      │
    │  │    ●   ●   (reservoir)│      │
    │  └───────────────────────┘      │
    │                                  │
    └─────────────────────────────────┘

Recommended Density:
- T/H: 1 per 20-50 m²
- CO2: 1 per zone (at plant height)
- PAR: 2-4 per zone (canopy level)
- EC/pH: At each reservoir
```

### Calibration Schedule

| Sensor | Frequency | Method |
|--------|-----------|--------|
| Temperature | Monthly | Reference thermometer |
| Humidity | Monthly | Saturated salt test |
| CO2 | Quarterly | Cal gas (fresh air ref) |
| PAR | Annually | Reference meter |
| EC | Weekly | Cal solution |
| pH | Weekly | pH 4.0, 7.0 buffers |

## Alert System

### Alert Thresholds

```typescript
interface AlertThresholds {
  temperature: {
    warning: { low: targetMin - 2, high: targetMax + 2 };
    critical: { low: targetMin - 5, high: targetMax + 5 };
  };
  humidity: {
    warning: { low: 50, high: 80 };
    critical: { low: 40, high: 90 };
  };
  co2: {
    warning: { low: 600, high: 1600 };
    critical: { high: 2000 };  // Safety
  };
  ec: {
    warning: { low: targetEc - 0.3, high: targetEc + 0.3 };
    critical: { low: targetEc - 0.5, high: targetEc + 0.5 };
  };
  ph: {
    warning: { low: 5.0, high: 7.0 };
    critical: { low: 4.5, high: 7.5 };
  };
}
```

### Alert Escalation

```
Level 1: In-app notification
    ↓ (no response 5 min)
Level 2: SMS/Push notification
    ↓ (no response 15 min)
Level 3: Phone call
    ↓ (no response 30 min)
Level 4: Emergency contact
```

## Best Practices

### Daily Operations

1. **Check sensors** - Verify readings match reality
2. **Inspect plants** - Catch issues before sensors
3. **Review logs** - Look for trends
4. **Maintain equipment** - Filters, pumps, fans

### Preventive Maintenance

| Equipment | Weekly | Monthly | Quarterly |
|-----------|--------|---------|-----------|
| Sensors | Visual check | Calibrate | Replace if needed |
| Filters | Replace/clean | Deep clean | - |
| Pumps | Check flow | Lubricate | Service |
| HVAC | Check operation | Filter | Coil cleaning |
| LEDs | Wipe | Check spectrum | Power audit |
