Introduction: Using an Atlas Scientific CO2 Sensor With an Arduino
In this tutorial, we will show you how to connect an Atlas Scientific EZO-CO2™ Embedded NDIR Carbon Dioxide Sensor to an Arduino Uno. There are multiple ways to connect Atlas Scientific sensors to an Arduino, but for ease of use; We will be using a very basic, easy to follow setup that will get our CO2 sensor running in UART mode in no time!
With all the talk of CO2 these days, you would think it would be easy to detect. The Atlas Scientific EZO-CO2 sensor is a compact Non-Dispersive Infrared (NDIR) sensor that gets right to the point, giving you the CO2 readings in ppm. With internal temperature and humidity compensation.
The Atlas Scientific EZO-CO2 Sensor detects gaseous CO2, it does not read dissolved CO2.
Please do not submerge this sensor in water as will cause severe internal damage.
Be sure to check out the Datasheet for the EZO-CO2 sensor, by clicking HERE.
1x Arduino Uno
4x Different colored male/female jumper cables
Step 1: Wiring the Arduino
When connecting a sensor to an Arduino or even a Raspberry Pi, try to remember that organization is key, which is why we are using 4 different colored jumper cables. Sure, we all know that Red is VCC and Black is ground. However, over the years we have seen many users use the same-colored jump cables throughout their entire project. I know all-blue looks cool… but it’s very easy to get lost in your own mess. For this tutorial, we are going to use Red, Black, White, and Green.
The colors of the jumper cables chosen for this tutorial match the wires within the EZO-CO2 cable housing. Organization is key!
White = Rx, Green = Tx, Black = GND, Red = VCC
OK let's get right to it!
Let’s start by placing the white jumper cable into pin 3 on the Arduino Uno board. Then, place the green jumper cable into pin 2 on the Arduino Uno board. These two jumper cables are important as they will allow both the EZO-CO2 sensor and the Arduino Uno board to communicate with each other. (image number 2 above)
Next, place the red jumper cable into the 5V pin. And finally, place the black jumper cable into any of the 2 GND or ground pins near the 5V pin. These two jumper cables will now supply power and a ground line from the Arduino Uno to the EZO-CO2 Sensor. (image number 2 above)
Now that all four of the jumper cables have been placed, your Arduino board should look a lot like some sort of spider monster. (image number 3 above)
We are almost done! Now that the Arduino Uno board is all set up, lets move onto the EZO-CO2 Sensor itself.
Step 2: Wiring the EZO-CO2 Sensor
The Atlas Scientific EZO-CO2 Sensor comes with a 5 pin male header inserted into the cable housing. If your 5 pin male header has not been inserted into the cable housing, please do so now.
Next, following the above image (number 1), connect the female ends of the jumper cables onto the 5 pin male header. Remember…organization is key!
Connect each jumper cable to its corresponding pin (or in this case color)
RX – White to White, TX – Green to Green, GND – Black to Black, VCC – Red to Red
For this tutorial, we will not be using the Alarm pin on the EZO-CO2 Sensor. You can just ignore the last “blue” pin on the sensor's cable housing.
Make sure all your jumper cables are fully connected on both the EZO-CO2 Sensor and on the Arduino Uno board as shown in image number 2, before moving on to the next step.
Step 3: Now You’re Playing With Power
Using the USB cable type A – B male/male, connect one end into your PC and the other into the Arduino Uno board… you’ll know which end goes where, trust me!
Once the USB cable has been connected at both ends, you will notice the LEDs on the Arduino are now lit up and blinking. Looking at the back of your EZO-CO2 Sensor, it should also be lit up and blinking.
All Atlas Scientific Sensors have two working modes, UART and I2C. Each of these modes are identified by a color. If your sensor is blinking green you are in UART mode. If the sensor is blue you are in I2C mode.
By default, all Atlas Scientific Sensors should come in UART mode. However, If your EZO-CO2 Sensor is blue (I2C mode) refer to the Datasheet on how to change modes.
We are all finished with the wiring, now comes the fun part.
Step 4: Flashing the Code
If you do not already have the Arduino IDE software installed onto your computer, please do so now, as we’ll be using it for the last section of this tutorial. You can download the Arduino IDE software by clicking HERE.
Generally, in this part of the tutorial, we would show you how to write the code for the EZO-CO2 Sensor, but who the heck has the time for all that?! So instead, let’s just download it directly by clicking HERE!
Extract the sample code *.ino file and run it. The Arduino IDE software will inform you that the *.ino file needs to be placed within its own sketch folder, just click OK to continue. You should now be in the Arduino IDE software.
We’re almost ready to take readings from the EZO-CO2 Sensor, but before we do, we must make sure that the Arduino IDE software knows which board we are using. Go to Tools > Board > Arduino AVR Boards > and make sure that Arduino Uno is selected.
Finally, you must tell the software which COM port on your computer the Arduino Uno board is connected to. Go to Tools > Port > and choose the correct COM port.
Now that everything has been properly set up, and the code is ready to go, press the upload button (located at the top left) and it will upload the code directly to your Arduino Uno board.
Now, you can start taking readings from the EZO-CO2 Sensor. From within the Arduino IDE Software, open the Serial Monitor (located at the top right) and make sure to set it to append carriage return only and set the baud rate to 9600.
When the EZO-CO2 Sensor is first powered on the sensor must warm up before it can output readings. The warm-up process takes 10 seconds to warm up completely.
During the first 10 seconds of operation, the output will be: *warm
Be sure to check out the EZO-CO2 Sensor Datasheet for commands and other useful information.