Introduction: Measure CO2 Levels With Ardunio and K-30 Sensor

Arduino boards are great for collecting data from sensors. This Instructable explains how to connect the Ardunio to the SenseAir K-30 CO2 sensor module.

Why the K-30?

If you're reading this, you already know the advantages of using the Arduino board. But why the K-30?

  • The K-30 is an non-dispersive infrared (NDIR) CO2 sensor. Unlike electrochemical CO2 sensors, NDIR sensors use light to measure the wavelength of CO2 molecules. Electrochemical sensors last a few years. With normal care, the K-30 will last upwards of 15 years. Click here to learn more about NDIR sensors.
  • NDIR sensors tend to be more accurate and have a faster response rate than electrochemical sensors.
  • The K-30 is easy to talk to. It uses an industry-standard UART TXD-RXD connection.

All this having been said, electrochemical sensors are cheaper. If you only want to know if CO2 levels are high/medium/low, a low-cost electrochemical sensor is a reasonable alternative. But if you want to accurately measure CO2 levels in parts-per-million over time, the K-30 is a great sensor.

Step 1: Collect the Parts You'll Need

1. Arduino UNO, MEGA or MEGA256 boards are available from Digikey and many other suppliers.

2. Power. While the Arduino's 5V power is theoretically able to power the K-30, the sensor needs 300mA minimum to operate the light inside the sensor. The problem is, if you power the Arduino from your PC's USB port, the K-30 has to share power with the Arduino, your mouse, and any other devices on the USB bus. The power to the sensor will drop under 300mA, and it won't operate properly.

You have 2 options:

  1. Use a powered USB hub as shown in Step 3.
  2. Power the K-30 with a separate 6-9VDC, 500mA external power supply. If you don't have a wall adapter like this around, you can use a 4 doubleAA battery box as shown in Step 4.

3. USB cable to connect your Android to your computer

4. Wire jumpers with jumper clips to connect to the K-30

5. Tail pin headers such as Digikey part number 952-2262-ND to connect to the Arduino board

6. K-30 0-10,000ppm (1%) CO2 sensor. The easiest way to buy a K-30 is to go to They have the sensors in stock for immediate delivery.

There are 2 things you'll need to know before you make a purchase.

1. The K-30 uses automatic background calibration (ABC) logic. This means that in order to self-calibrate, the sensor needs to be exposed to normal outdoor air (~400ppm) every 7.5 days. If you are going to use the sensor in a factory or an indoor greenhouse, you should order the sensor with ABC turned off.

2. The K-30 does not come with a Molex connector on the module. If you're very good at soldering on PCBs, you can add one yourself. However, this will void the warranty. A better solution is to call CO2Meter and ask them to ship you a K-30 with a Molex connector pre-installed. While this isn't a stock item, if they get enough phone calls they might make it one ;-)

Step 2: Start With Blink

If you've never fired up your Arduino board, the best way to become familiar with the Graphical User’s Interface (GIU) is to verify your Arduino board is operating properly. Create an Arduino project and run the example Blink. This simple test program confirms that a number of connection details and that the GUI are working properly.

Caution: Do not connect the Arduino board to the USB port until the Arduino software is installed. Otherwise Windows will install a generic driver and the Arduino will not operate.

Step 1: Install Arduino software on your computer. From this page select the Windows Installer.

Step 2: To run the Blink example follow these instructions:

Note that the MEGA Arduinos have a LED on board. The Arduino UNO may require a LED and resistor be added as specified in the tutorial.

Once Blink runs properly, you can connect the K-30 sensor.

Step 3: Connect Using a Powered USB Hub

If you're using a powered USB hub, life is simple. You can connect PWR from the 5V connector on the Arduino board directly to the sensor, then connect the Arduino to the powered USB hub. If you skip using the powered USB hub and start getting crazy readings from the sensor, it will be because you got impatient and skipped this step.


  • Pin 13 TXD to RXD on K-30
  • Pin 12 RXD to TXD on K-30
  • 5V to 5V on K-30
  • GND connected to GND on K-30

Step 4: Connect the K-30 Using External Power

If you don't have a powered USB hub, you need to use a wall adapter or battery box. Make the connections as shown:

UNO / MEGA / 2560

  • Pin 13 TXD to RXD on K-30
  • Pin 12 RXD to TXD on K-30
  • GND connected to (-) terminal on battery/power supply and GND on K-30


  • TXD to Pin 12 RXD on Arduino
  • RXD to Pin 13 TXT on Arduino
  • 5V POS to (+) on battery/power supply
  • GND connected to GND Arduino, (-) terminal on battery/power supply

Step 5: About Serial Connections

When you connect TXD-RXD, you have to cross the wires over between the Arduino and the K-30. See the image.

If you're thinking "I'm not dumb...everyone knows that" I apologize. But I guarantee every engineer has made this bone-headed mistake at least once. Don't be a statistic ;-)

Step 6: Creating Your Ardunio Project

    The simplest way to talk to the sensor is to use the library that comes with the Arduino board. This statement

    SoftwareSerial K_30_Serial(12,13)

    inside the AN-126_K-Series.ino file sets up a virtual serial port using pin 12 for RXD and pin 13 for TXD on Arduino boards.

    1. Select the AN-126_K-Series.ino file below and save it to your desktop.
    2. Open it, select all, and copy.
    3. Open a new Android blank sketch and paste the code into it.
    4. To compile, from the Arduino GUI select Sketch > Verify/Compile
    5. Verify that your Arduino board is recognized correctly:
      1. Select Tools. Set Board to Arduino UNO or MEGA.
      2. Confirm that the processor matches your Arduino: UNO, MEGA or MEGA 2560.
    6. To run the code, select Sketch > Upload.

    To view the program operating, select Tools > Serial Monitor. You should see the window on the next page.

    Step 7: Your Tools > Serial Monitor Should Display This Output

    Step 8: Troubleshooting

    If your connections are good and the sensor has sufficient power, you should be reading CO2 levels from the sensor in real-time. To test, try blowing on the sensor and see how long it takes to respond. Next, try opening a window and leaving the sensor alone in the room for a few minutes. It should drift down to outdoor air levels, or approximately 400ppm. Note that if ABC calibration is turned on, it will take 7.5 days of continuous operation before the sensor self-calibrates.

    If you're not reading CO2 levels, troubleshoot in this order:

    1. Disconnect the sensor and running Blink to verify everything is working properly

    2. Check your connections

    3. Verify you have enough power to the sensor

    4. Make sure you've correctly copied and pasted the .ino file.

    If you are getting goofy CO2 readings, in almost every case it is because the K-30 sensor isn't getting enough power.

    Step 9: What's Next?

    So you're read the CO2 levels at your desk for a few minutes, blown on the sensor, and watched the output. But now you're bored. What can you do next?

    Connect an LCD to display your CO2 levels.

    Create a Web app that monitors CO2 levels

    The choices are endless. Have fun!

    Sensors Contest 2017

    Participated in the
    Sensors Contest 2017