Skip to main content

Crate mics_6814

Crate mics_6814 

Source
Expand description

§mics-6814

Platform-agnostic, no_std Rust driver for the MiCS-6814 triple gas sensor.

Converts resistance ratios (Rs/R0) from the sensor’s three independent channels into gas concentration estimates (ppm) using calibration curves from the datasheet.

§Supported Gases

GasChannelRange
CORED1–1000 ppm
NO2OX0.05–10 ppm
NH3NH31–500 ppm
EthanolRED10–500 ppm
H2RED1–1000 ppm
CH4RED>1000 ppm
C3H8RED>1000 ppm
C4H10RED>1000 ppm

§Usage

use mics_6814::{voltage_to_rs_r0, measure, ChannelReading, Gas};

// Convert ADC voltage to Rs/R0 ratio
let rs_r0 = voltage_to_rs_r0(
    1.65,       // ADC voltage (V)
    3.3,        // Supply voltage (V)
    56_000.0,   // Load resistor (Ω)
    500_000.0,  // R0 from calibration (Ω)
).unwrap();

// Build a reading and measure CO
let reading = ChannelReading { red: rs_r0, ox: 1.0, nh3: 1.0 };
let co = measure(&reading, Gas::CarbonMonoxide).unwrap();
println!("CO: {:.1} ppm", co.ppm);

§Calibration

R0 must be measured in clean air after the sensor’s warm-up period (~10 minutes). Each channel has its own R0 value.

§Features

  • defmt-03 — enable defmt::Format derives for embedded logging

§License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Re-exports§

pub use calibration::rs_r0_to_ppm;
pub use error::Error;
pub use gas::Channel;
pub use gas::Gas;

Modules§

calibration
error
gas

Structs§

ChannelReading
Raw resistance readings from the three sensor channels.
GasReading
Gas concentration reading in parts per million.

Functions§

measure
Estimate the concentration of a specific gas from a channel reading.
voltage_to_rs_r0
Convert an ADC voltage reading to an Rs/R0 ratio.