CO2 level classroom sensor

Looking at the current challenge of ventilating a classroom properly, i thought that an arduino could do that quite nicely.

I researched a little on the internet and found this post by Zentris using

  • a nodeMCU ESP 8266 board
  • an Sensiron SCD30 CO2 sensor (NDIR ==> thus quite accurate)
  • and some displays, that I had no access to.

I ordered all components only to find out that I had no clue what to do next. Some more research revealed an existing library for the SCD30 sensor from sparkfun.

I found an old Grove-LCD RGB display in my arduino box and felt ready to go.

Then came the wiring. How to connect the SCD30 to the nodeMCU? After again some research, here is the correct set up

red: 3V - 3V
brown: GND - GND
blue: SDA - D2/GPIO4 (nodeMCU)
yellow: SCL - D1/GPIO5 (node MCU)

As also the display was using the i2l bus system, I added
yellow: SCL - SCL
blue: SDA - SDA
black: GND - GND

There is conflicting information on whether or not you can use the VIN port on the nodeMCU as 5V power supply, thus I used a second USB port via the funduino for that.

In the preferences of the Arduino package, add the proper board library:
http://arduino.esp8266.com/stable/package_esp8266com_index.json

On the software side: some libraries need to be included

  • SparkFun SCD30 Arduino Libary
  • Grove LCD RGB backlight

And that’s it. I will paste the code below. It is very raw and I hope to be able to connect it to an epaper and to beam the data to a webserver.

if you have any insights, I would appreciate you sharing them.

all the best, Thomas

/*
Reading CO2, humidity and temperature from the SCD30
By: Nathan Seidle
SparkFun Electronics
Date: May 22nd, 2018
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

Feel like supporting open source hardware?
Buy a board from SparkFun! CO₂ Humidity and Temperature Sensor - SCD30 - SEN-15112 - SparkFun Electronics

This example prints the current CO2 level, relative humidity, and temperature in C.

Hardware Connections:
Attach RedBoard to computer using a USB cable.
Connect SCD30 to RedBoard using Qwiic cable.
Open Serial Monitor at 115200 baud.
*/

#include <Wire.h>

/* Include RGB Library */

#include “rgb_lcd.h”

rgb_lcd lcd;

const int colorR = 0;
const int colorG = 255;
const int colorB = 0;

#include “SparkFun_SCD30_Arduino_Library.h” //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
SCD30 airSensor;

void setup()
{
Serial.begin(115200);
Serial.println(“SCD30 Example”);
Wire.begin();

if (airSensor.begin() == false)
{
Serial.println(“Air sensor not detected. Please check wiring. Freezing…”);
while (1)
;
}

//The SCD30 has data ready every two seconds

// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);

lcd.setRGB(colorR, colorG, colorB);

// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print(“CO2 in ppm”);

lcd.setCursor(0, 1);
lcd.print(“temp. in C”);

delay(1000);

}

void loop()
{
if (airSensor.dataAvailable())
{
Serial.print(“co2(ppm):”);
Serial.print(airSensor.getCO2());

Serial.print(" temp(C):");
Serial.print(airSensor.getTemperature(), 1);

Serial.print(" humidity(%):");
Serial.print(airSensor.getHumidity(), 1);

Serial.println();
}
else
Serial.println(“Waiting for new data”);

delay(500);

// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(11, 0);
lcd.print(airSensor.getCO2());
lcd.setCursor(11, 1);
// print the temperature in the second row:

lcd.print(airSensor.getTemperature(), 1);

if (airSensor.getCO2() >= 1000)
{
lcd.setRGB(255, 0, 0);
}

else if (airSensor.getCO2() < 1000)
{
lcd.setRGB(0, 255, 0);
}

delay(500);
lcd.noDisplay();
// Turn on the display:
lcd.display();

}