mq2_pcf8563
Rust crate for reading MQ-2 gas sensor (ADC) + HZ-8563/PCF8563 RTC (I²C) on Arduino Uno / AVR.
Features:
- Clean-air baseline calibration
- Gas index calculation with smoothing
- Timestamped logging via serial
- High-gas alert threshold
Hardware Connections
- MQ-2: VCC → 5V, GND → GND, AOUT → A0
- HZ-8563/PCF8563: VCC → 5V, GND → GND, SDA → A4, SCL → A5
- 4.7kΩ pull-up resistors on SDA and SCL to 5V (required for reliable I²C)
Installation
[]
= "0.1.0"
For development/testing with Arduino Uno, also add arduino-hal (git dep):
[]
= "https://github.com/Rahix/avr-hal"
= "e5c8f37fe48419956e722490a82b9ca9b9fc61a2"
= ["arduino-uno"]
Usage Example
See the examples/basic_logger.rs for a complete runnable binary that:
- Calibrates the sensor
- Logs timestamp + raw + index
- Prints alert when index exceeds threshold
The example uses arduino-hal (git-dependency) and is not part of the published crate on crates.io. Its for development and testing only.
LLM Usage Declaration
Parts of the gas_index function (scaling and curve ideas)
and the pad2/pad4 formatting helpers were inspired or adapted
from suggestions generated by LLM tools (Grok/ChatGPT).
All code was manually reviewed, tested, and refined by me.
License
Licensed under either of
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Contribution
Contributions are welcome! You can help by:
- Reporting Issues
- Found a bug or unexpected behavior? Open an issue on GitHub.
- Suggesting Features
- Ideas for improvements, new sensors, or functionality are always appreciated.
- Submitting Pull Requests
- Fork the repository and make changes in a separate branch.
- Ensure your code compiles and follows the project style.
- Include clear commit messages and, if applicable, update documentation.
- Testing
- Test any new features or fixes on an Arduino with the MQ-2 sensor and PCF8563 RTC (or compatible hardware).