Automated Cleanroom Airlock System Comprehensive Technical Documentation, Wiring Schematic, Code & Real-World Implementation 1. Executive Project Overview In modern pharmaceutical manufacturing, microchip fabrication, and biosecurity isolation facilities, maintaining controlled environmental purity is paramount. The Automated Cleanroom Airlock System powered by the ESP32 microcontroller creates a secure, automated buffer zone between contaminated external environments and sterile cleanrooms. The system continuously regulates door access, enforces automated motion-triggered sealing, activates high-RPM HVAC air sanitization, monitors ambient temperature and humidity, and ensures safe clearance before allowing exit. 2. System Architecture & Operation Workflow 1 Entry Request & Outer Door Unlocking: Pressing the designated outer entry push button signals the ESP32 to rotate the outer Servo Motor, opening the entry door. 2 Human Entry & Auto-Closure: The PIR Motion Sensor inside the airlock chamber detects human movement upon entry. The ESP32 immediately triggers the outer Servo Motor to close and seal the door. 3 HVAC Air Sanitization Cycle: The NEMA 17 Stepper Motor (driven via A4988) activates at high RPM to drive the air filtration blower. Simultaneously, the DHT22 sensor continuously reads ambient temperature (target: 20-25°C) and relative humidity (target: 30-45%). 4 Safe Clearance & Exit Authorization: Once environmental parameters stabilize within safe limits, the RGB LED changes to GREEN, and the exit push button is unlocked. 5 Exit Clearance & Auto System Reset: Pressing the exit button opens the inner Servo door. As the individual steps out, the HC-SR04 Ultrasonic Sensor measures clearance distance (>50cm), automatically closes the inner door, and resets the system state machine to idle. 3. Complete Hardware Component Bill of Materials (BOM) Component Name Quantity Functional Role in System ESP32 NodeMCU Development Board 1 Central Microcontroller handling logic state machine and sensor feedback. NEMA 17 Stepper Motor & A4988 Driver 1 Set High-RPM HVAC Air Sanitization Blower mechanism. SG90 / MG996R Servo Motors 2 Automated Outer (Entry) and Inner (Exit) door mechanisms. PIR Motion Sensor (HC-SR501) 1 Detects human presence inside the airlock chamber. HC-SR04 Ultrasonic Sensor 1 Measures exit distance clearance for safe door closure. DHT22 Temperature & Humidity Sensor 1 Real-time environmental safety validation inside airlock. ESP32 Cleanroom Airlock System Page 1 of 5 4. Circuit Wiring & Pin Mapping Specification 5. Complete Firmware Source Code (ESP32 C++) #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <ESP32Servo.h> #include <DHT.h> // Pin Definitions #define PIR_PIN 13 #define TRIG_PIN 5 #define ECHO_PIN 18 #define DHT_PIN 4 #define DHT_TYPE DHT22 #define STEP_PIN 26 #define DIR_PIN 27 #define ENTRY_SERVO_PIN 14 #define EXIT_SERVO_PIN 12 #define ENTRY_BTN_PIN 34 #define EXIT_BTN_PIN 35 #define RGB_RED_PIN 25 #define RGB_GREEN_PIN 33 Component Name Quantity Functional Role in System 16x2 I2C LCD Display Module 1 Displays live system state, temperature, humidity, and operational messages. Common Cathode RGB LED 1 Visual status indication (RED: Sanitizing / GREEN: Clear / BLUE: Idle). Push Buttons & 10kΩ Resistors 2 Sets Entry request and Exit request triggers with pull-down resistors. Component Pin ESP32 GPIO Pin Power / Additional Wiring Connection PIR Sensor OUT GPIO 13 5V VCC, GND HC-SR04 TRIG / ECHO GPIO 5 / GPIO 18 5V VCC, GND DHT22 DATA GPIO 4 3.3V VCC, GND (10k Pull-up resistor) A4988 STEP / DIR GPIO 26 / GPIO 27 VMOT to 12V External PSU, VDD to 5V, GND Entry Servo PWM Signal GPIO 14 5V VCC, GND Exit Servo PWM Signal GPIO 12 5V VCC, GND I2C LCD SDA / SCL GPIO 21 / GPIO 22 5V VCC, GND Entry Button / Exit Button GPIO 34 / GPIO 35 3.3V VCC via 10k Pull-down to GND RGB LED (Red / Green / Blue) GPIO 25 / GPIO 33 / GPIO 32 Common Cathode to GND (220Ω Resistors on Anodes) ESP32 Cleanroom Airlock System Page 2 of 5 #define RGB_BLUE_PIN 32 // Peripherals Setup LiquidCrystal_I2C lcd(0x27, 16, 2); DHT dht(DHT_PIN, DHT_TYPE); Servo entryServo; Servo exitServo; // State Machine enum SystemState { IDLE, ENTRY, SANITIZING, SAFE_EXIT, RESETTING }; SystemState currentState = IDLE; void setup() { Serial.begin(115200); pinMode(PIR_PIN, INPUT); pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT); pinMode(STEP_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT); pinMode(ENTRY_BTN_PIN, INPUT); pinMode(EXIT_BTN_PIN, INPUT); pinMode(RGB_RED_PIN, OUTPUT); pinMode(RGB_GREEN_PIN, OUTPUT); pinMode(RGB_BLUE_PIN, OUTPUT); dht.begin(); lcd.init(); lcd.backlight(); entryServo.attach(ENTRY_SERVO_PIN); exitServo.attach(EXIT_SERVO_PIN); entryServo.write(0); // Door Closed exitServo.write(0); // Door Closed setRGB(0, 0, 255); // Blue Idle } void loop() { switch (currentState) { case IDLE: lcd.setCursor(0,0); lcd.print("AIRLOCK: READY "); lcd.setCursor(0,1); lcd.print("PRESS ENTRY BTN "); setRGB(0, 0, 255); if (digitalRead(ENTRY_BTN_PIN) == HIGH) { currentState = ENTRY; } break; case ENTRY: lcd.setCursor(0,0); lcd.print("DOOR 1 OPENED "); entryServo.write(90); if (digitalRead(PIR_PIN) == HIGH) { delay(1500); entryServo.write(0); // Auto Close currentState = SANITIZING; } break; case SANITIZING: lcd.setCursor(0,0); lcd.print("SANITIZING AIR.. "); setRGB(255, 0, 0); // Red Warning digitalWrite(DIR_PIN, HIGH); // High RPM Blower Cycle for(int i=0; i<400; i++) { digitalWrite(STEP_PIN, HIGH); ESP32 Cleanroom Airlock System Page 3 of 5 delayMicroseconds(500); digitalWrite(STEP_PIN, LOW); delayMicroseconds(500); } float temp = dht.readTemperature(); float hum = dht.readHumidity(); lcd.setCursor(0,1); lcd.print("T:" + String(temp,1) + "C H:" + String(hum,0) + "% "); if (temp >= 20.0 && temp <= 25.0 && hum >= 30.0 && hum <= 45.0) { currentState = SAFE_EXIT; } break; case SAFE_EXIT: lcd.setCursor(0,0); lcd.print("AIRLOCK SAFE! "); lcd.setCursor(0,1); lcd.print("PRESS EXIT BTN "); setRGB(0, 255, 0); // Green Clear if (digitalRead(EXIT_BTN_PIN) == HIGH) { exitServo.write(90); // Open Inner Door delay(2000); currentState = RESETTING; } break; case RESETTING: long duration, distance; digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW); duration = pulseIn(ECHO_PIN, HIGH); distance = duration * 0.034 / 2; if (distance > 50) { // Clearance confirmed exitServo.write(0); lcd.clear(); lcd.print("SYSTEM RESETTING"); delay(1000); currentState = IDLE; } break; } } void setRGB(int r, int g, int b) { analogWrite(RGB_RED_PIN, r); analogWrite(RGB_GREEN_PIN, g); analogWrite(RGB_BLUE_PIN, b); } 6. Industrial Real-World Applications 🔬 Semiconductor & Microchip Fabrication Facilities In silicon wafer manufacturing, even a 0.1-micron dust particle can destroy an entire integrated circuit batch. Automated airlocks enforce strict air sanitization and differential pressure control before cleanroom entry. ESP32 Cleanroom Airlock System Page 4 of 5 🧪 Pharmaceutical Cleanrooms & Bio-Safety Labs Maintains sterile bio-containment boundaries in drug synthesis laboratories and Level 3/4 virology research labs, ensuring airborne pathogens do not escape or contaminate batches. 🏥 Hospital Isolation Wards & ICUs Protects immunocompromised patients and prevents airborne viral diseases from spreading across hospital wards by maintaining regulated negative/positive pressure airlock zones. ESP32 Cleanroom Airlock System Page 5 of 5