4 — ESP32-S3 simulation

An interactive ESP32-S3 circuit simulation you can run free in your browser on Velxio, by 25040118.

Components

Sketch code

/*
 * 婴儿床安睡监测系统 —— ESP32-S3 / Velxio 仿真
 *
 * 屏幕 ILI9341(240x320): CS=10 DC=8 RST=9 MOSI=11 SCK=12(MISO 不用,脚 13 让给按键)
 * SHT31 温湿度         : SDA=4  SCL=5
 * MPU6050 六轴         : SDA=4  SCL=5(与 SHT31 共用 I2C,地址 0x68)
 * AD8232 心电          : AOUT=1
 * 声音传感器           : AOUT=2
 * 光敏                 : SIG=6
 * 风扇 L293D           : EN=7  IN1=15 IN2=16
 * 加热块 MOSFET        : SIG=17
 * WS2812 24 灯         : DIN=18(安睡模式下随摇篮曲变化)
 * 有源蜂鸣器           : SIG=21(安睡模式下播放摇篮曲)
 * 环境灯 Grove RGB LED : DIN=3(WS2813 单总线)
 * 摇篮舵机             : SIG=14(安睡模式开启后 0°→90°→0° 缓慢往复)
 * 4x4 矩阵按键         : R1~R4=38,39,47,13  C1~C4=35,36,37,45
 * ESP32-CAM 联动       : 5V/GND,TX=40->CAM RX,RX=48<-CAM TX
 * 网页服务             : 内置 HTTP 服务器,STA 连不上自动开热点 SafeSleep/safesleep
 * HX711 称重           : DOUT=41 SCK=42(接反/接偏会自动扫描纠正)
 */

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Wire.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <WiFi.h>
#include <WebServer.h>

// ---------------- 引脚 ----------------
#define PIN_TFT_CS    10
#define PIN_TFT_DC     8
#define PIN_TFT_RST    9
#define PIN_TFT_MOSI  11
#define PIN_TFT_SCK   12

// 4x4 矩阵按键:行 R1~R4 / 列 C1~C4(8 根线)
#define PIN_KP_R1  38
#define PIN_KP_R2  39
#define PIN_KP_R3  47
#define PIN_KP_R4  13   // 原 TFT MISO,ILI9341 只写不读,可挪用
#define PIN_KP_C1  35
#define PIN_KP_C2  36
#define PIN_KP_C3  37
#define PIN_KP_C4  45

#define PIN_SDA  4
#define PIN_SCL  5

#define PIN_ECG  1
#define PIN_SND  2
#define PIN_LDR  6

#define PIN_FAN_EN   7
#define PIN_FAN_IN1 15
#define PIN_FAN_IN2 16
#define PIN_HEAT    17

#define PIN_LED     18
#define LED_COUNT   24
#define PIN_BUZZER  21

#define PIN_LAMP     3   // Grove RGB LED (WS2813) DIN
#define PIN_SERVO   14   // 摇篮舵机 PWM(信号线接 GPIO14)

#define PIN_CAM_TX  40   // ESP32-S3 TX -> ESP32-CAM RX
#define PIN_CAM_RX  48   // ESP32-S3 RX <- ESP32-CAM TX

#define PIN_HX_DT   41
#define PIN_HX_SCK  42

// ---------------- 阈值 ----------------
constexpr float TEMP_HOT   = 28.0f;   // 高于此值开风扇
constexpr float TEMP_TARGET = 20.0f;  // 加热目标温度
constexpr float TEMP_BAND   = 2.0f;   // 比例带:18~20℃ 之间功率线性下降
constexpr float TEMP_SAFE_MAX = 26.0f;// 超温保护:强制关加热 + 风扇全速
constexpr float HUM_WET    = 75.0f;   // 湿度报警
constexpr float BPM_HIGH   = 110.0f;  // 心率报警
constexpr int   SND_LOUD   = 2500;    // 声音过大
constexpr int   LDR_DARK   = 400;     // 光敏过低
constexpr float WEIGHT_MIN_KG = 0.40f;// 低于此重量视为婴儿不在床

constexpr float HX711_COUNTS_PER_GRAM = 420.0f;   // 模块属性 Counts per gram
constexpr long  HX711_TARE_OFFSET     = 50000;    // 模块属性 Tare offset

// 自动识别时扫描的空闲引脚(避开 USB 19/20 与 PSRAM 35~37)
const uint8_t HX_CANDIDATES[] = {42, 41, 40, 48};
const int HX_CAND_COUNT = sizeof(HX_CANDIDATES) / sizeof(HX_CANDIDATES[0]);

// ---------------- 器件对象 ----------------
Adafruit_ILI9341 tft = Adafruit_ILI9341(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST);
Adafruit_SHT31   sht;
Adafruit_MPU6050 mpu;
Adafruit_NeoPixel strip(LED_COUNT, 

More projects by 25040118