Safety boundary
This guide describes a monitoring and notification prototype. It must not be treated as a certified gas alarm, fire alarm or replacement for a code-compliant installation. Use a listed, independently certified detector for life-safety protection, keep a separate carbon-monoxide alarm in the living area, and have gas work inspected by a qualified technician. Never test with a live gas release.
System architecture
The proposed system has five layers: gas and environmental sensing, a local controller, a fail-safe actuator, MQTT telemetry and a local audible alarm. The ESP32 can supervise readings and publish status, but the safety action must remain local. A network outage, broker failure or firmware crash must not prevent a certified alarm from sounding or a properly designed shutoff from reaching its safe state.
| Layer | Example component | Design requirement |
|---|---|---|
| Controller | ESP32-WROOM development board | Use a regulated supply and watchdog recovery |
| Gas sensing | Certified detector or calibrated sensor module | Do not claim ppm accuracy without a datasheet and calibration procedure |
| Alarm | Local buzzer and visual indicator | Continue operating when Wi-Fi is unavailable |
| Shutoff | Approved normally-closed valve and driver | Confirm valve compatibility and current draw with the manufacturer |
| Telemetry | MQTT over TLS | Use authentication, least privilege and retained state carefully |
Sensor selection and calibration
Low-cost MQ-series modules are useful for experimentation but are not automatically suitable for a life-safety product. Their heater temperature, cross-sensitivity, warm-up time, humidity response and calibration curve vary by model. A raw ADC value is not a reliable gas concentration. If a sensor is used for research, record its part number, heater supply, warm-up period, clean-air reference and the manufacturer’s Rs/R0 curve. Label the output as an indication rather than a certified concentration.
The ESP32 ADC is nominally 12-bit, but board attenuation, reference variation, noise and supply quality affect the result. Average samples, reject impossible values, and log the raw value alongside the processed value. Do not select an emergency threshold from a generic internet number; use the detector manufacturer’s instructions and the applicable local requirements.
Fail-safe relay and power design
The controller must not drive a solenoid directly. Use a correctly rated transistor or relay driver, a flyback diode for a DC coil, a fuse close to the supply and a wiring method appropriate for the vehicle. A normally-closed shutoff valve can move to the closed state when control power is lost, but the complete assembly must be verified: valve behavior, reset behavior, manual override, inrush current and thermal limits all matter.
For a simple power estimate, use:
Average current = sensor current + controller current + alarm average current + valve duty-cycle current
For example, if the controller uses 80 mA, the sensor 150 mA, the alarm averages 20 mA and the valve uses 400 mA for 10% of the time, the estimated average is 290 mA before converter losses. This is a planning estimate, not a battery-safety rating. Add startup current and temperature derating, then size the fuse and conductors from the actual manufacturer data.
MQTT and local alarm logic
Publish health, sensor status, alarm state and firmware version as separate topics. Use TLS and unique credentials per device. A practical state machine is:
- Warm up and validate the sensor.
- Sample and filter readings locally.
- Require a valid alarm condition for a defined confirmation interval.
- Sound the local alarm and move the shutoff to its safe state.
- Publish the event and continue retrying without blocking the safety loop.
- Require a deliberate manual reset after the area has been ventilated and inspected.
Do not let a remote MQTT command open a valve after an alarm without a physical inspection and a deliberate local reset. Rate-limit notifications, protect the broker and ensure that retained alarm messages are not mistaken for a current measurement.
Deep sleep and verification
Deep sleep is usually unsuitable while a gas sensor needs continuous heater operation. Use it only for a separate low-power monitoring path whose wake-up behavior and detection latency have been validated. Test power loss, Wi-Fi loss, broker loss, sensor disconnection, stuck ADC values, watchdog reset, relay-driver failure and false alarms. Test the complete installation with the vehicle stationary, ventilation paths clear and a qualified person responsible for gas safety.
Sources and assumptions
Use the exact ESP32, sensor, valve, power-converter and detector datasheets for the final design. The component names and current values above are examples, not universal specifications. This article is an engineering planning guide and does not certify a gas detection or shutoff system.





