mq135
π Overview
mq135 is a minimal, #![no_std] Rust driver for the MQ135 air quality sensor.
Itβs designed for embedded systems using the embedded-hal ADC traits.
The MQ135 sensor detects air quality by measuring gases like COβ, NHβ, Benzene, and Smoke via analog voltage readings. This driver converts those readings into gas concentration (PPM).
β¨ Features
- β Calibration support in clean air
- β Measures PPM values for multiple gases (COβ, NHβ, Benzene, Smoke)
- β
Uses generic
embedded-haltraits for wide MCU compatibility - β
No standard library (
#![no_std]), perfect for microcontrollers - β Easy-to-use API for quick integration
π¦ Usage
First, add the crate to your dependencies:
[]
= "0.1" # replace with latest version
= "0.2" # or your compatible version
= "0.2" # for math in no_std environment
Example code snippet:
use ;
// `adc` must implement `embedded_hal::adc::OneShot`
// `pin` is the ADC input pin connected to MQ135 sensor output
let mut sensor = new; // RL load resistance in Ohms
// Calibrate the sensor in clean air before readings
sensor.calibrate_in_clean_air.unwrap;
// Get gas concentration in PPM
let co2_ppm = sensor.read_gas_ppm.unwrap;
println!;
π§ͺ Calibration
Calibration is necessary to set the baseline sensor resistance (R0) in clean air. This ensures accurate gas concentration measurements.
π¬οΈ Supported Gases
| Gas | Description |
|---|---|
| COβ | Carbon Dioxide |
| NHβ | Ammonia |
| Benzene | Aromatic Hydrocarbon |
| Smoke | General Smoke Levels |
βοΈ Dependencies
embedded-halβ Hardware abstraction layer for embedded deviceslibmβ Math functions compatible withno_stdenvironments
π License
This project is licensed under the MIT License Β© 2025 Prabesh Shrestha.
π€ Contributions
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Thank you for using mq135! Happy coding and clean air monitoring! πΏ