Add Library and Code
parent
60a4e50858
commit
131e7e4407
81
Library-and-Code.md
Normal file
81
Library-and-Code.md
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
# Library and Code
|
||||||
|
The prototype firmware was developed using the Arduino IDE together with the ESP32 board support
|
||||||
|
package and the corresponding sensor libraries. Each sensor requires a specific library to simplify hardware
|
||||||
|
configuration, communication, and data acquisition. The following sections summarize the main software
|
||||||
|
components and execution flow for each supported sensor.
|
||||||
|
|
||||||
|
## GP2Y1010AU0F Dust Sensor
|
||||||
|
### Required Libraries and Object Definitions
|
||||||
|
The GP2Y1010AU0F does not require a dedicated Arduino library because it provides an analog output.
|
||||||
|
The firmware uses the standard Arduino library:
|
||||||
|
```
|
||||||
|
#include <Arduino.h>
|
||||||
|
```
|
||||||
|
The sensor is accessed directly through an ADC-capable GPIO and a GPIO used to control the internal
|
||||||
|
infrared LED.
|
||||||
|
### Important Pin Definitions
|
||||||
|
The firmware defines:
|
||||||
|
* One ADC pin connected to the sensor output.
|
||||||
|
* One digital output pin connected to the LED control input.
|
||||||
|
These pins are initialized during the setup phase before measurements begin.
|
||||||
|
|
||||||
|
### Data Processing
|
||||||
|
The ADC reading is converted into sensor voltage and then into an estimated dust concentration using the
|
||||||
|
calibration equation implemented in the firmware. The calculated value may be displayed on the Serial
|
||||||
|
Monitor or transmitted to another system.
|
||||||
|
|
||||||
|
## LMV324-Based Sound Detector
|
||||||
|
### Required Libraries and Object Definitions
|
||||||
|
The Sound Detector also provides an analog output and therefore does not require a dedicated Arduino
|
||||||
|
library.
|
||||||
|
```
|
||||||
|
#include <Arduino.h>
|
||||||
|
```
|
||||||
|
### Important Pin Definitions
|
||||||
|
The firmware defines an ADC input connected to the module Envelope output.
|
||||||
|
### Data Acquisition
|
||||||
|
Sound intensity is measured using
|
||||||
|
```
|
||||||
|
analogRead()
|
||||||
|
```
|
||||||
|
which samples the analog voltage generated by the Sound Detector.
|
||||||
|
### Data Processing
|
||||||
|
The measured ADC value is converted into voltage and used as an indication of the detected sound level.
|
||||||
|
Since the module is not factory calibrated in dB SPL, the measured voltage represents relative sound
|
||||||
|
intensity.
|
||||||
|
## Sensirion SCD30 Sensor
|
||||||
|
### Required Libraries and Object Definitions
|
||||||
|
The SCD30 requires the following Arduino libraries:
|
||||||
|
```
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <SensirionI2cScd30.h>
|
||||||
|
```
|
||||||
|
The sensor object is created as:
|
||||||
|
```
|
||||||
|
SensirionI2cScd30 scd30_sensor;
|
||||||
|
```
|
||||||
|
### Important Pin Definitions
|
||||||
|
The I²C interface is configured using:
|
||||||
|
```
|
||||||
|
#define I2C_SDA_PIN 20
|
||||||
|
#define I2C_SCL_PIN 21
|
||||||
|
```
|
||||||
|
These GPIOs provide the SDA and SCL communication lines between the ESP32 and the SCD30.
|
||||||
|
|
||||||
|
### Data Acquisition
|
||||||
|
The firmware first verifies that new data is available using:
|
||||||
|
```
|
||||||
|
scd30_sensor.getDataReady()
|
||||||
|
```
|
||||||
|
When data is ready, the measurements are retrieved using:
|
||||||
|
```
|
||||||
|
scd30_sensor.readMeasurementData()
|
||||||
|
```
|
||||||
|
### Data Processing
|
||||||
|
The library returns calibrated values directly in engineering units:
|
||||||
|
* CO₂ (ppm)
|
||||||
|
* Temperature (°C)
|
||||||
|
* Relative Humidity (%RH)
|
||||||
|
No additional ADC conversion or mathematical processing is required before the values are displayed or
|
||||||
|
transmitted.
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user