Эксперемент — Esp32 Devkit C V4 simulation

An interactive Esp32 Devkit C V4 circuit simulation you can run free in your browser on Velxio, by korenovskagk73.

Components

Sketch code

// ================================================================
// GARAGE CLIMATE CONTROL — v5.18
//
// Changes vs v5.17:
//  [F29] Buzzer bit-bang tone via digitalWrite + delayMicroseconds.
//        Velxio blocks LEDC on many GPIOs ("GPIO XX is not usable,
//        maybe conflict with others"). Bit-bang bypasses LEDC and
//        works on any output pin, producing ~2.5 kHz square wave.
//  [F30] Short-press button = siren test 3 s, regardless of MQ-2.
//        Also sets fireArmed = true. Proves alarm works.
//  [F31] Long-press (>1.5 s) button = toggle armed/disarmed.
//  [F32] Log includes test time remaining.
//
// Fire alarm blocks ALL climate immediately (vent/dryer/heater OFF).
// Slider drop below 1500 for 2 s → auto reset.
// ================================================================

#include <Arduino.h>
#include <math.h>

// ---------------- CONFIG ----------------
#define DEMO_MODE 1
#define USE_REAL_INDOOR  false
#define USE_REAL_OUTDOOR false
#define USE_REAL_LDR     true
#define MQ2_ALLOW_AUTO   true

#define INDOOR_TEMP   22.0f
#define INDOOR_HUM    80.0f
#define OUTDOOR_TEMP  20.0f
#define OUTDOOR_HUM   50.0f

// ---------------- PIN MAP ----------------
constexpr uint8_t PIN_DHT_IN    = 4;
constexpr uint8_t PIN_DHT_OUT   = 16;
constexpr uint8_t PIN_LED_VENT  = 2;
constexpr uint8_t PIN_LED_DRY   = 5;
constexpr uint8_t PIN_LED_WAIT  = 18;
constexpr uint8_t PIN_LED_HEAT  = 13;
constexpr uint8_t PIN_LED_LIGHT = 27;
constexpr uint8_t PIN_LDR_IN    = 34;
constexpr uint8_t PIN_LDR_OUT   = 33;
constexpr uint8_t PIN_PIR       = 25;
constexpr uint8_t PIN_BUZZER    = 17;
constexpr uint8_t PIN_MQ2_ANALOG= 32;
constexpr uint8_t PIN_DOOR      = 12;
constexpr uint8_t PIN_CAR       = 14;
constexpr uint8_t PIN_FIRE_BTN  = 21;

// ---------------- THRESHOLDS ----------------
constexpr float DELTA_AH_START    = 0.8f;
constexpr float DELTA_AH_STOP     = 0.5f;
constexpr float TD_MARGIN_START   = 2.0f;
constexpr float SUMMER_COOL_START = 2.0f;
constexpr float SUMMER_COOL_STOP  = 0.5f;
constexpr float RH_VENT_STOP      = 65.0f;

constexpr float RH_DRY_START      = 65.0f;
constexpr float RH_DRY_STOP       = 55.0f;
constexpr float T_DRY_START       = 6.0f;
constexpr float T_DRY_STOP        = 5.0f;
constexpr float DELTA_AH_DRY_MAX  = 0.5f;

constexpr float T_HEAT_START      = -5.0f;
constexpr float T_HEAT_STOP       = -2.0f;

constexpr float WINTER_TOUT_FLOOR = -10.0f;

constexpr int LDR_DARK_ON          = 1000;
constexpr int LDR_DARK_OFF         = 1500;
constexpr int OUT_BRIGHT_ON        = 2400;
constexpr int OUT_BRIGHT_OFF       = 2000;
constexpr int LDR_FEEDBACK_HIGH    = 3000;
constexpr int STICKY_THRESHOLD     = 100;

int      MQ2_FIRE_THRESHOLD     = 2000;
constexpr int MQ2_FIRE_RESET         = 1500;
constexpr int MQ2_STICKY_THRESHOLD   = 100;
constexpr uint32_t BUZZER_BEEP_MS    = 250;
constexpr uint16_t BUZZER_HALF_PERIOD_US = 200;   // 2.5 kHz

constexpr uint32_t FIRE_CONFIRM_MS       = 2000;
constexpr uint32_t FIRE_BTN_DEBOUNCE