upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions
TP401 Class Reference

API for the Grove TP401 Air Quality Sensor. More...

Detailed Description

The Grove TP401 Air Quality Sensor module is useful for monitoring air purity indoors. It can detect CO and a wide range of other harmful gases, but, due to a limited detection range, it should be used only when qualitative results are needed. Example applications are air recirculation, ventilation systems, and refreshing sprayers. The sensor is linear and should be roughly sensitive to 0-20 ppm CO from 0-4 V. Note: the sensor requires 2-3 minutes to warm up initially and 48 hours of operation to stabilize completely.

tp401.jpeg
// Give a qualitative meaning to the value from the sensor
std::string
airQuality(uint16_t value)
{
if(value < 50) return "Fresh Air";
if(value < 200) return "Normal Indoor Air";
if(value < 400) return "Low Pollution";
if(value < 600) return "High Pollution - Action Recommended";
return "Very High Pollution - Take Action Immediately";
}
int main ()
{
upm::TP401* airSensor = new upm::TP401(0); // Instantiate new grove air quality sensor on analog pin A0
cout << airSensor->name() << endl;
fprintf(stdout, "Heating sensor for 3 minutes...\n");
// wait 3 minutes for sensor to warm up
for(int i = 0; i < 3; i++) {
if(i) {
fprintf(stdout, "Please wait, %d minute(s) passed..\n", i);
}
sleep(60);
}
fprintf(stdout, "Sensor ready!\n");
while(true) {
uint16_t value = airSensor->getSample(); // Read raw value
float ppm = airSensor->getPPM(); // Read CO ppm (can vary slightly from previous read)
fprintf(stdout, "raw: %4d ppm: %5.2f %s\n", value, ppm, airQuality(value).c_str());
usleep(2500000); // Sleep for 2.5s
}
delete airSensor;
return 0;
}

Public Member Functions

 TP401 (int gasPin)
 
 ~TP401 ()
 
std::string name ()
 
float getPPM ()
 
- Public Member Functions inherited from Gas
 Gas (int gasPin)
 
 ~Gas ()
 
virtual int getSampledWindow (unsigned int freqMS, int numberOfSamples, uint16_t *buffer)
 
virtual int findThreshold (thresholdContext *ctx, unsigned int threshold, uint16_t *buffer, int len)
 
virtual int getSampledData (thresholdContext *ctx)
 
virtual int getSample ()
 
virtual void printGraph (thresholdContext *ctx, uint8_t resolution)
 

Additional Inherited Members

- Protected Attributes inherited from Gas
mraa::Aio m_aio
 

Constructor & Destructor Documentation

TP401 ( int  gasPin)

TP401 constructor

Parameters
gasPinAnalog pin where the sensor is connected
~TP401 ( )

TP401 destructor

Member Function Documentation

std::string name ( )
inline

Returns the name of the sensor

Returns
Name of the sensor
float getPPM ( )

Returns one sample in parts per million (ppm) of CO in the air based on the following sensor calibration: 0-4 V is roughly 0-20 ppm CO

Returns
New sample converted to ppm CO

Here is the call graph for this function:

Inheritance diagram for TP401:
Inheritance graph
[legend]
Collaboration diagram for TP401:
Collaboration graph
[legend]

The documentation for this class was generated from the following files: