CO2 Sensor ============ The CO2 sensor is used to measure the concentration of carbon dioxide around it. This sensor has a digital and analog output. The digital output can be used as a way to set limit to when the concentration of CO2 is considered harmful. The setting of this limit is done by fixing the potentiometer on the sensor to the desired calibration. A built-in LED lights up when the CO2 concentration exceeds that limit. As for the analog pin, the sensor can calculate the value of the concentration of CO2 it detects in ppm (parts per million). .. warning:: If you want to perform analog readings using this sensor, you will need to learn about the :ref:`mcpadc`. Connecting the Sensor in Digital Mode -------------------------------------- Wiring ^^^^^^^^^ To use the digital output of the sensor, connect 1. **+** to 5V 2. The - to a ground pin 3. The D pin to an RPi GPIO pin The wiring of the Raspberry Pi to the breadboard and the sensor is shown in the figure below: .. image:: Circuits/co2sensor-digital.jpg :align: center Code ^^^^^^^^^ .. literalinclude:: Code/co2sensor-digital.py :linenos: :language: python Connecting the Sensor in Analog Mode -------------------------------------- Wiring ^^^^^^^^^ The Raspberry Pi doesn’t have an analog input pin. So to read the analogue output of the sensor, we need to use an analog to digital converter (ADC), in this case an :ref:`mcpadc`. Connect the sensor as follows: 1. The VCC to 5V 2. The GND to a ground pin 3. The analog pin to CH0 (pin 1) of the MCP3008 .. image:: Circuits/co2sensor-analog.jpg :align: center Code ^^^^^^^^^ This code reads the concentration of CO2 in ppm: .. literalinclude:: Code/co2sensor-analog.py :linenos: :language: python