H₂S Gas Sensor
STM32G431KB · Firmware v0.1.0
Testing

Signal Analysis & Testing

Noise characterisation, stability metrics, T90 response time, and experimental protocols.

The Three S’s of Sensor Performance

1. Stability (Zero Uncertainty)

The ability of the sensor to maintain a constant output in clean air.

  • Zero drift — slow baseline shift over time or temperature
  • Noise — high-frequency random fluctuations

Firmware implementation: StabilityMonitor — 30-sample circular buffer at 1 Hz. Stability criterion: rate-of-change (newest − oldest sample) ≤ 0.1 mV over the 30-second window.

2. Sensitivity (Slope)

$$S = \frac{V_{span} - V_{zero}}{C_{span}}$$

where $C_{span}$ is the reference concentration (ppm) and voltages are in mV.

Typical H₂S sensitivity with this circuit: ~10 mV/ppm.

3. Selectivity (Cross-Sensitivity)

Common interferents for electrochemical H₂S sensors:

InterferentRelative response (typical)
SO₂+10 to +40%
NO₂−5 to −10%
CO0 to +5%
Humidity±2% per 10%RH change
Temperature±0.5–2% per °C

The SHT45 sensor provides temperature and humidity data for future compensation.

Noise Floor Analysis

With 8× hardware oversampling on a 12-bit ADC (170 MHz clock, 6.5 cycle sample time):

ParameterValue
ADC LSBVDD / 4095 ≈ 0.81 mV/LSB
Oversampling gain×8 → effective ~13.5 bit
Effective resolution~0.29 mV/LSB
Sensor sensitivity~10 mV/ppm
Theoretical resolution~0.03 ppm from noise alone

Practical noise floor will be dominated by TIA Johnson noise and PCB layout, not ADC quantisation.

Experimental Protocols

Experiment A: Stability & Noise (Zero Air)

Objective: Quantify baseline noise and drift.

  1. Power on, warm up 30–60 minutes
  2. Log STABILITY and GAS at 1 Hz for 1 hour
  3. Analyse:
    • Noise (Vpp): max − min over 1-minute windows
    • RMS noise (σ): standard deviation of samples
    • Drift: linear regression slope over the full hour
    • Pass criterion: noise < ½ × expected signal for 1 ppm

Experiment B: Sensitivity & Linearity

Objective: Determine slope, verify linearity.

  1. Zero air for 5 minutes → record average RAW value
  2. Span gas (e.g. 50 ppm) for 5 minutes → record average RAW value
  3. Calculate slope: $S = (ADC_{span} - ADC_{zero}) / 50$
  4. Optionally test mid-point (25 ppm) to check linearity

Experiment C: Response Time (T₉₀)

Objective: Measure the time to 90% of final stable reading.

  1. Establish stable baseline with zero air
  2. Instantly switch to span gas (3-way valve)
  3. Record timestamps from log until signal reaches 90% of final value
  4. $T_{90} = t_{90%} - t_{switch}$

Expected T₉₀ for City Technology / equivalent H₂S sensors: ≤ 30–35 seconds.

MATLAB Analysis Script

%% Gas Sensor — Stability Analysis
filename = 'sensor_data.log';
v_ref = 3.3; adc_res = 4096;

% Parse "RAW:2048" lines
fileID = fopen(filename, 'r');
raw_data = []; t = [];
i = 0;
while ~feof(fileID)
    line = fgetl(fileID);
    if contains(line, 'RAW:')
        tok = regexp(line, 'RAW:(\d+)', 'tokens');
        if ~isempty(tok)
            raw_data(end+1) = str2double(tok{1}{1});
            t(end+1) = i;
            i = i + 1;
        end
    end
end
fclose(fileID);

voltage = (raw_data / adc_res) * v_ref * 1000;  % mV

% Statistics
fprintf('Mean:    %.2f mV\n', mean(voltage));
fprintf('Std Dev: %.3f mV\n', std(voltage));
fprintf('Vpp:     %.2f mV\n', max(voltage) - min(voltage));
p = polyfit(t, voltage, 1);
fprintf('Drift:   %.5f mV/sample\n', p(1));

% Plot
figure; plot(t, voltage); hold on;
plot(t, polyval(p, t), 'r--', 'LineWidth', 1.5);
title('Sensor Signal (mV)'); xlabel('Sample'); ylabel('mV');
legend('Signal', 'Drift trend'); grid on;

Last updated: February 2026