-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCO2_monitor.tex
368 lines (287 loc) · 37.2 KB
/
CO2_monitor.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author: Alf Köhn-Seemann %
% Email: [email protected] %
% License: CC BY-SA 4.0 %
% Website: https://github.com/alfkoehn/CO2_monitor %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[12pt,a4paper]{article}
%allows to type the umlaute directly
\usepackage[utf8]{inputenc}
%for including graphics
\usepackage{graphicx}
%for links (only for self-repo)
%\usepackage[dvipdfm]{hyperref}
\usepackage{hyperref}
% to have [2-5] instead of [2,3,4,5]
\usepackage{cite}
% nice rules/lines (useful in tabulars)
\usepackage{booktabs}
\usepackage[x11names]{xcolor}
% for source code listings
\usepackage{listings}
% for writing the eurosymbol
\usepackage{eurosym}
% for e.g. align
\usepackage{amsmath}
% make iso-today format
% would also work: \usepackage[yyyymmdd]{datetime2}
\def\myisodate{\leavevmode\hbox{\the\year-\twodigits\month-\twodigits\day}}
\def\twodigits#1{\ifnum#1<10 0\fi\the#1}
%abbreviations used in bibliography
%\newcommand{\PoP}[0]{Phys. Plasmas}
\newcommand*{\mathcolor}{}
\def\mathcolor#1#{\mathcoloraux{#1}}
\newcommand*{\mathcoloraux}[3]{%
\protect\leavevmode
\begingroup
\color#1{#2}#3%
\endgroup
}
\newcommand{\inchsign}{^{\prime\prime}}
\newcommand{\coo}{\ensuremath{\mathrm{CO_2}~}}
\definecolor{mycodegreen}{rgb}{0,0.6,0}
\definecolor{mycodegray}{rgb}{0.5,0.5,0.5}
\definecolor{mycodepurple}{rgb}{0.58,0,0.82}
\definecolor{mycodebackcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{myArduinoStyle}{
backgroundcolor=\color{mycodebackcolour}, % choose background color
basicstyle=\ttfamily\scriptsize, % font & font size: small > footnotesize > scriptsize > tiny
commentstyle=\color{mycodegreen}\textit, % comment style
keywordstyle=\color{magenta}\bfseries, % keyword style
numberstyle=\tiny\color{mycodegray}, % style for line numbers
stringstyle=\color{mycodepurple}, % string literal style
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
breaklines=true, % sets automatic line breaking
captionpos=b, % sets caption-position to bottom
frame=single, % adds a frame around code
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
language=C, % language of code
numbers=left, % where to put line numbers (none, left, right)
numbersep=5pt, % distance from line numbers to code
rulecolor=\color{black}, % if not set, frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
showspaces=false, % show spaces adding particular underscores (overrides 'showstringspaces')
showstringspaces=false, % underline spaces within strings only
showtabs=false, % show tabs within strings adding particular underscore
tabsize=4, % sets default tabsize to 4 spaces
% title=\lstname % show filename of files included with \lstinputlisting; also try caption instead of title
}
\lstset{style=myArduinoStyle} % enables the style 'mystyle', call it with another style to switch to another style
%style for bibliography
%\bibliographystyle{unsrt.bst}
\bibliographystyle{unsrtDOI.bst}
% doi+url: plainnat, unsrtnat, abbrvnat
\begin{document}
\title{A CO$_2$ monitor as an introductory microelectronics project helping to slow-down the spread of the corona virus and ensuring a healthy learning and working environment}
\author{A.~K\"{o}hn-Seemann, \href{mailto:[email protected]}{[email protected]}}
\date{\myisodate}
\maketitle
\begin{abstract}
This paper describes the setup of a simple yet reliable \coo monitor which is based on open-source microelectronics hardware. The monitor is intended to be used in class rooms, lecture halls or offices and can be constructed as a joint students project. It was motivated by recent discussions on the role of aerosols being part of exhaled air to spread the corona virus. The aerosol concentration in air is correlated with the \coo concentration. Measuring the latter can thus help to slow-down the spread of the corona-virus. The program code used for the \coo monitor and this documentation is available as a GitHub repository to allow for updates and improvements.
\\ \quad \\ First full version released on 2020-09-22.
\\ \quad \\ License for this document: \href{https://creativecommons.org/licenses/by-sa/4.0/}{CC BY-SA 4.0}
%\\ \quad \\ \textbf{version: \myisodate} \\ \quad \\ \textbf{FOR INTERNAL USE ONLY}
\end{abstract}
%\pacs{52.25.Xz, 52.35.Hr, 52.35.Mw, 52.50.Sw, 52.55.Hc, 52.70.Ds, 52.70.Gw, 52.70.Kz}
% 47.11.Bc for finite difference methods
% Comment out if separate title page not required
%\maketitle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Introduction %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}\label{s:intro}
It is generally accepted that the \coo concentration in a class room has an influence on students' activities, their ability to study and learn~\cite{TWARDELLA2012,GAIHRE2014}, or on their health and thus attendance~\cite{SHENDELL2004}. The same applies of course to office environments~\cite{ALLEN2016}. The major source of \coo in a class room is the exhaled air of the students (and teachers)~\cite{PERSILY2017}. It thus increases over time but can also be relatively easy controlled by proper ventilation. Monitoring the \coo concentration over time provides thus a simple way to ensure a productive and healthy learning environment.
In addition to \coo, exhaled air consists of aerosols (among other things). It is now generally accepted that the aerosols of patients being infected with SARS-CoV-2, might contain viable virus concentrations which are large enough to cause further infections if somebody else inhales those aerosols~\cite{LEDNICKY2020,MORAWSKA2020,KOHANSKI2020,SETTI2020}. Note that this seems to happen even if the infected patients show no symptoms of SARS-CoV-2~\cite{FURUKAWA2020} or not yet any symptoms~\cite{SUN2020}. It is thus not surprising that the vast majority of SARS-CoV-2 virus transmissions seems to happen indoors~\cite{QIAN2020} and that closing schools and universities, for example, were found to have a significant effect on the spread of the virus~\cite{BRAUNER2020}. Face masks can help to reduce the aerosol outflow and thus also slow down the infection rates~\cite{HOWARD2020,MITTAL2020}.
With half-life periods of the virus on aerosols on the order of 1 hour~\cite{DOREMALEN2020}, it becomes evident that proper ventilation, strongly reducing the aerosol concentration, can help to prevent hidden infections, i.e.\ infections where the infected person is not (yet) aware of their infection but already contagious. This is further stressed by a case study from a seafood market in south China~\cite{ZHANG2020}, a restaurant also from China~\cite{LI2020}, or from a choir in the US~\cite{MILLER2020}. Note that ventilation was already recommended as a proper measure against the spread of a different pandemic, the Spanish flu, more than 100 years ago~\cite{SOPER1919}.
Since aerosols and \coo are both parts of exhaled air, measuring the \coo concentration in a room provides an easy accessible indicator for the aerosol concentration~\cite{HARTMANN2020,BHAGAT2020}. In recent recommendations from national authorities, it was suggested to use the \coo concentration as an indicator when ventilation is required~\cite{VOSS2020,BMA2020a,RKI2020}. A relevant example for the positive effect of proper ventilation based on the \coo concentration in a room is the stopping of a tuberculosis outbreak at the Taipei University in Taiwan: only after the air circulation in every room was improved such that the \coo concentration stayed around $600\,\mathrm{ppm}$ (the outdoor value is approximately $400\,\mathrm{ppm}$), the outbreak came to a halt and stopped completely~\cite{DU2020}.
While commercial \coo monitors do exist~\cite{ARANET2020,TFA2020,WOEHLER2020}, these might be considered too expensive for usage in large quantities in schools or universities and/or currently have long delivery times (since their potential help in slowing down the spread of the SARS-CoV-2 virus seems to become more and more accepted). Here we present a simple and cost effective, yet reliable way to monitor the \coo concentration. Widely available microelectronic components are used which can be easily programmed via open source software platforms allowing to modify and extend the examples presented in this paper. Students can build the detectors in class as a joint project which might serve to raise interest in electronics or the underlying physical and chemical processes~\cite{WATZKA2011}.
This work was inspired by a project of the \textit{Hochschule Trier}~\cite{BIRKENFELD2020}, where the design and construction of a \coo measuring device is suggested as a students' project, allowing to discuss a variety of scientific topics during the course of the project. In addition, a few posts from different forums served as an inspiration~\cite{BOYLES2020,METROPOL2020,OMBRA2020,ZENTRIS2020}. Furthermore, a small number of projects hosted and maintained as GitHub repositories and webpages using the same \coo detector are available~\cite{MKETZ2020,NETZBASTELN2020,PAULVHA2020,RUHE2020}. We would like to recommend the interested reader in particular to the repository by paulvha~\cite{PAULVHA2020} as it contains a rather large number of examples and to an article published in the \textit{Make Magazin}~\cite{MAKEMAGAZIN2020} which contains a full description including the assembly of a \coo monitor similar to the one presented in this paper.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CO2 monitor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The \coo monitor}\label{s:co2monitor}
The \coo monitor is based on the microelectronic sensor SCD30 which measures the \coo concentration and also provides measurements of the ambient temperature and relative humidity~\cite{SENSIRION2020B}. Using Arduino as a programing language and some microcontroller, it is straightforward to get the sensor running and outputting data, thanks to the examples available in the libraries provided by SparkFun~\cite{SPARKFUN2020}. Using the Arduino IDE~\cite{ARDUINOIDE2020}, which is available for all major operating systems, the corresponding libraries can be simply included via the library manager.
To make the \coo monitor visually appealing, we decided to output the measurement to an OLED display (which is inexpensive and available in a large variety of sizes and configurations). Due to the widespread usage of such displays, they can also be directly included via the library manager in the Arduino IDE. Alternatively, an LCD display can be used which has the advantage of being larger in diameter but having a reduced resolution at a similar price. Note that we recommend to use LCD-displays with I2C-modules to make the wiring and/or soldering less complicated (connecting 4 cables instead of 16).
In addition to just showing some numbers, we have included a red LED at the prototype installation which lights up as soon as some threshold value of the \coo concentration is reached, indicating the need for ventilation. One could also think of a traffic light design, where first a yellow LED lights up at a slightly lower threshold value. The \textit{Federation of European Heating, Ventilation and Air Conditioning associations (REHVA)} recommends to issue a warning, corresponding to an orange light, when a value of $800\,\mathrm{ppm}$ is reached and prompt to trigger some action like ventilation, corresponding to a red light, when $1000\,\mathrm{ppm}$ are reached~\cite{REHVA2020}. The \textit{Federal Ministry of Labour and Social Affairs} of Germany also states a threshold value of $1000\,\mathrm{ppm}$ that should not be passed~\cite{BMA2020}. Note that a value of approximately $410\,\mathrm{ppm}$ is the typical \coo concentration of fresh air~\cite{NOAA2020}.
As a microcontroller we decided to use the low-cost open source NodeMCU ESP8266 board~\cite{NODEMCU2020}, as it offers enough flexibility to further extend the functionality of the \coo monitor. Of particular interest might be the WiFi capability allowing for example to write the measured values to a web-server where they can then be accessed via a web-browser or an app on a smartphone.
\begin{figure}[t]
\centering
\includegraphics[height=.55\textwidth]{figs/CO2monitor_version1_2.jpg}
\hspace{1em}
\includegraphics[height=.55\textwidth]{figs/CO2monitor_version1_1.jpg}
\caption{Assembled and working prototype of the \coo monitor, \textit{(left)} with a measured \coo concentration below the threshold and \textit{(right)} above it (note the red LED).}
\label{f:CO2_monitor_photo}
\end{figure}
A prototype of the \coo monitor is shown in Fig.~\ref{f:CO2_monitor_photo}. As one can see, it is not enclosed in some box to still allow easy access for modifications. The idea of this prototype was rather to show that the general principle of the \coo monitor is working and not to provide a polished final product. The prototype is ready to be used in a class room or lecture hall, although it might be worth to mount everything into a box which is not only visually more appealing but provides also some protection.
As a next step one might want to replace the breadboard by a stripboard which of course requires some soldering but results in a more robust device. Instead of designing a case for the \coo monitor, it is possible to use cases which were originally designed for a Raspberry Pi or an Arduino Uno. Furthermore, the LEDs as an indicator for the level of the \coo concentration can be replaced by a smiley face on the OLED display whose happiness correlates with the \coo concentration: a higher level results in a more sad face. Figure~\ref{f:CO2_monitor_version2} shows a photography of such an assembly, referred to as \coo monitor version 2. More details about different assembly variations are discussed in Section~\ref{s:assembly}.
\begin{figure}[t]
\centering
\includegraphics[width=.8\textwidth]{figs/CO2monitor_version2.jpg}
\caption{Assembled \coo monitor, version 2. Note the usage of a stripboard and a casing originally designed for an Arduino Uno. In addition to the actual value, the \coo concentration is indicated by the happiness of a smiley face shown next to the numbers on the OLED display.}
\label{f:CO2_monitor_version2}
\end{figure}
\subsection{Positioning in a room}
The \coo monitor should be placed at a position in a room where it is not exposed to flowing air as this would distort the measured \coo concentration (see Section~\ref{s:SCD30}). This means that it should, for example, not be placed in-between a window and a door if both are used for efficient cross ventilation%
\footnote{Altough cross ventilation is more efficient than impact ventilation (``querlüften'' vs. ``stoßlüften''~\cite{GUARDIAN2020}) one has to take care that behind the open door in Fig.~\ref{f:CO2_monitor_positioning} another open window is needed otherwise one could release part of the classroom air and its potentially infectious aerosols into the corridor which connects different classrooms or lecture halls~\cite{STAHMER2020}.}.
Figure~\ref{f:CO2_monitor_positioning} indicates the optimal positioning in such a situation. It should also not be positioned too close to the students' or teachers' heads as they could temporarily trigger very high values being displayed on the \coo monitor if directly exhaling onto it. A position slightly above everybody's head seems to be best as this would also allow everybody to have a look at it. The latter fact could in principle lead to some students' closely following every change on the \coo monitor instead of paying attention to the class or lecture. An easy solution would be to show only \coo concentrations rounded to $100\,\mathrm{ppm}$, for example print
``\texttt{CO$_2$ in 100 ppm: 8}'' to a display~\cite{STAHMER2020}.
\begin{figure}[tb]
\centering
\includegraphics[height=.4\textwidth]{figs/CO2monitor_positioning.png}
\caption{Optimal position of the \coo monitor in a room where ventilation by an air flow across the room (cross ventilation) can be applied.}
\label{f:CO2_monitor_positioning}
\end{figure}
Also be aware that classrooms and lecture halls often provide only a small number of wall sockets. One would thus need either a long enough power cable or a power bank (USB charger) which can also be included in the case of the \coo monitor itself.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Required parts}
The \coo monitor as presented here consists of a number of parts for which it is not important to use the exact same model. The only component which should not be replaced is the \coo measuring device, the SCD30. Note that the program code discussed in Sec.~\ref{s:code} is tailored for the NodeMCU ESP8266, replacing that component would thus require small adjustments to the code.
The parts used for the prototype of the \coo monitor are listed in Table~\ref{t:parts}. The display can be easily replaced by an OLED of larger size. One could also use multiple displays, which would require to take care of proper addressing the displays and thus add a little bit of complexity to the code (and to the assembly).
\begin{table}\label{t:parts}
\center
\begin{tabular}{cccc}\toprule
Element & Quantity & Price \\\hline
SCD30 (\coo sensor) & 1 & $45\,$\euro \\
NodeMCU ESP8266 & 1 & $5\,$\euro \\
$0.91\inchsign$ OLED display & 1 & $5\,$\euro \\
red LED & 1 & $0.2\,$\euro \\
$220\,\mathrm{\Omega}$ resistor & 1 & $0.1\,$\euro \\
mini breadboard & 1 & $4\,$\euro \\
breadboard cables & 10 & $4\,$\euro \\
pin header & 1 & $0.5\,$\euro \\
micro USB cable & 1 & $3\,$\euro \\
\bottomrule
\end{tabular}
\caption{Components used for the \coo monitor as presented in this paper (note that the prices were obtained in 09/2020 and may vary).}
\end{table}
The usage of a breadboard was motivated by educational purposes as this allows very easy assembly without the need to solder anything. It can, however, directly be replaced by a stripboard or completely omitted and use only cables or pin headers (which would require some soldering).
Note that the prices as listed in the table can be pushed down (significantly for some of the components) when ordering larger quantities.
For the prototype design of the \coo monitor we have decided to leave out a proper casing. One could either use a standard-sized case, or design one and print it for example on a 3D printer or re-use/recycle some old boxes. It is however important to correctly position the SCD30 inside the box: as described in a manufacturer's document~\cite{SENSIRION2020A}, the sensor is ideally placed as close as possible to the box's outer shell and to a large opening to be properly exposed to the ambient. The box should be as small as possible to get fast response times to changes in the ambient air. The SCD30 should also be isolated from direct air flow, as the corresponding changes in pressure (due to the air flow) would lead to increased noise and thus reduced accuracy in the measurements. It is also recommended to not directly place the sensor above heat sources like for example microcontrollers.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CO2 Sensor: NDIR %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The \coo sensor}\label{s:SCD30}
The SCD30 has been chosen because it performs direct measurements of the \coo concentration. Cheaper sensors often measure the concentration of volatile organic compounds (VOC) and then assume a correlation between the two quantities. This can, however, lead to wrong values of the \coo concentration since VOC can be emitted from a variety of chemicals. Although VOCs are also known to cause health problems, here we are explicitly interested in the \coo concentration, as discussed in Sec.~\ref{s:intro}. For a discussion about monitoring VOC and \coo concentration with self-assembled devices we would like to point the interested reader
to e.g.\ Ref.~\cite{CHIESA2019}.
\subsection{Technical specifications}
According to the datasheet of the SCD30~\cite{SENSIRION2020B}, the \coo sensor has a measurement range of $0 - 40,000\,\mathrm{ppm}$ with an accuracy of $\pm 30\,\mathrm{ppm}$.
The supply voltage needs to be between $3.3$ and $5\,\mathrm{V}$ which allows to use a variety of microcontrollers. The drawn current is specified to be on average $19\,\mathrm{mA}$ with a maximum value of $75\,\mathrm{mA}$. With a sensor lifetime of $15$ years, the SCD30 offers a reliable system to permanently monitor the \coo concentration.
\subsection{Nondispersive infrared technique}
\begin{figure}[ht]
\center
\includegraphics[width=.65\textwidth]{figs/NDIR_principle_v1.png}
\caption{Sketch of a sensor using the nondispersive infrared technique to measure \coo concentration.}
\label{f:NDIR_sketch}
\end{figure}
The \coo concentration is measured using the so-called \textit{nondispersive infrared} technique (NDIR) which is the most common sensor type used in industry to measure the \coo concentration~\cite{CHEN2003,SHEN2019,PETERSEN2018}. Its principle is sketched in Fig.~\ref{f:NDIR_sketch}. A light source (a light bulb is used here) emits infrared light which travels through a tube filled with a sample of the surrounding air. The spectrum of the emitted light includes the $4.26\,\mu\mathrm{m}$ absorption band of \coo which is unique to the typical components of air and the light is absorbed by them. At the end of the tube, the remaining light hits an optical filter that allows only that specific wavelength of $4.26\,\mu\mathrm{m}$ to pass. A CMOS detector then collects the remaining light and measures its intensity $I_1$. The difference between the intensity of light emitted by the source $I_0$ and received by the detector at this specific wavelength is due to the \coo molecules in the tube which then allows to calculate the \coo concentration using the Beer-Lambert law:
\begin{equation}
I_1 = I_0 e^{-\kappa C l},
\end{equation}
where $\kappa$ is the absorption coefficient of \coo, $C$ its concentration, and $l$ the length of the tube. A second tube without the optical filter in-front of the CMOS detector is used as a reference tube to compensate variations of $I_0$. Using folded optics, i.e.\ waveguides, for the tube allows for a very compact size of the overall sensor on the order of just a few centimeters.
\subsection{Calibration}\label{s:SCD30calibration}
The SCD30 is sold as a fully calibrated sensor and thus requires in principle no calibration before its usage. According to the manual~\cite{SENSIRION2020C}, the sensor is set to automatically perform a self-calibration. This requires, however, to expose the sensor to fresh air on a regular basis. In particular during the first 7 days of operation, it has to be exposed to fresh air for one hour every day~\cite{SENSIRION2020C}. Since this is a requirement which is unrealistic to fulfill for our use case, we decided to follow a different approach: instead of the \textit{automatic self-calibration (ASC)}, a \textit{forced recalibration (FRC)} can be performed after triggering it by the user. According to our observations, the SCD30 shows only very little drift over time, such that an FRC is only required once or twice per year (or after installing the SCD30 sensor into some device as it might have experienced some mechanical stress).
To perform the FRC, the \coo monitor simply needs to be placed outside somewhere where it is exposed to fresh air. Note that the sensor itself should not experience strong winds as this would deteriorate the measurements. The whole sensor should be in thermodynamic equilibrium before starting the FRC so it is best to operate it for a time of approximately $10\,\mathrm{min}$ before starting the FRC (for more details about the code, see Section~\ref{s:code}).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Assembling %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Assembly}\label{s:assembly}
\begin{figure}[ht]
\center
\includegraphics[height=.48\textwidth]{figs/CO2_detector_bb.png}
\caption{Schematic of a prototype of the \coo monitor (version 1).}
\label{f:CO2_fritzing}
\end{figure}
The \coo monitor can be assembled in various ways, first we will restrict ourselves to the case of a simple prototype design on a breadboard as shown in Fig.~\ref{f:CO2_fritzing}. The connection between the NodeMCU (with the ESP8266) and the SCD30 sensor is as follows:\\
\begin{tabular}{rcl}\toprule
NodeMCU & & SCD30\\\hline
\texttt{GND} & $\mathcolor{black}{\boldsymbol{\longrightarrow}}$ & \texttt{GND}\\
$3.3\,\mathrm{V}$ & $\mathcolor{red}{\boldsymbol{\longrightarrow}}$ & \texttt{VIN}\\
\texttt{D2/GPIO4} & $\mathcolor{orange}{\boldsymbol{\longrightarrow}}$ & \texttt{RX/SDA}\\
\texttt{D1/GPIO5} & $\mathcolor{Yellow3}{\boldsymbol{\longrightarrow}}$ & \texttt{TX/SCL}\\
\texttt{GND} & $\mathcolor{black}{\boldsymbol{\longrightarrow}}$ & \texttt{SEL}\\
\bottomrule
\end{tabular}\\
\quad\\
The NodeMCU ESP8266 board then needs to be connected to the OLED display as follows:\\
\begin{tabular}{rcl}\toprule
NodeMCU & & OLED display\\\hline
\texttt{GND} & $\mathcolor{black}{\boldsymbol{\longrightarrow}}$ & \texttt{GND}\\
$3.3\,\mathrm{V}$ & $\mathcolor{red}{\boldsymbol{\longrightarrow}}$ & \texttt{VCC}\\
\texttt{D2/GPIO4} & $\mathcolor{orange}{\boldsymbol{\longrightarrow}}$ & \texttt{SDA}\\
\texttt{D1/GPIO5} & $\mathcolor{Yellow3}{\boldsymbol{\longrightarrow}}$ & \texttt{SCL}\\
\bottomrule
\end{tabular}\\
\quad\\
It is of course also possible to directly connect the respective \texttt{SDA} and \texttt{SCL} pins of the OLED and the SCD30, as shown in Fig.~\ref{f:CO2_fritzing}, instead of connecting those pins between the SCD30 and the NodeMCU. The red LED is connected with its anode, the longer leg, to pin \texttt{D8/GPIO15} of the NodeMCU and with its cathode, the shorter leg, via a $220\,\Omega$ resistor (to limit the current) to ground.
As discussed in Section~\ref{s:co2monitor}, different assemblies of the \coo monitor are possible. Figure~\ref{f:CO2_monitor_version3} shows what we refer to as \textit{version 3} in various stages of the assembly process. Compared to version 2, a larger OLED display is used, which requires to updates its size at the beginning of the program code, see Listing~\ref{lst:global_constants}. As can be seen, the breadboard from version 1 is replaced by a stripboard onto which the necessary components need to be soldered. The casing is the same as in version 2 (which was originally intended to be used for an Arduino Uno). The side wall closest to the SCD30 has been omitted to ensure that the gas atmosphere inside the casing is the same as outside (a few holes drilled into that wall should have had the same effect). A portable battery charger, a power bank, is used as a power supply allowing for mobile usage of the \coo monitor across the day.
\begin{figure}[t]
\centering
\includegraphics[width=.85\textwidth]{figs/CO2monitor_version3.jpg}
\caption{\coo monitor, version 3, in various stages of the assembly process. As compared to version 2, see Fig.~\ref{f:CO2_monitor_version2}, a larger OLED display is used, the SCD30 is mounted in a different way, and a slightly smaller stripboard is used.}
\label{f:CO2_monitor_version3}
\end{figure}
A different assembly is shown in Fig.~\ref{f:CO2_monitor_version4}, where a picture frame and an 4-row LCD display is used. The picture frame comes at a price of approximately $2\,$\euro\ and the LCD display is available at this size for approximately $10\,$\euro. The thickness of the picture frame allows to mount the other electronic components in it resulting in a visually appealing device. The finite thickness also allows to simply put the picture frame on a table/desk (or any other flat surface).
\begin{figure}[t]
\centering
\includegraphics[width=.85\textwidth]{figs/CO2monitor_version4.jpg}
\caption{\coo monitor, version 4. As compared to version 2 and 3, see Figs.~\ref{f:CO2_monitor_version2} and \ref{f:CO2_monitor_version3}, an LCD display is used which and mounted in a picture frame which allows to hide the other electronics due to its thickness of several centimeters.}
\label{f:CO2_monitor_version4}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The program code}\label{s:code}
Arduino is used as programming language in this project due to its widespread usage and large numbers of libraries available for various hardware components. The Arduino IDE library manager allows to directly install a proper Arduino library for the SCD30. Alternatively, the library is available as a GitHub repository~\cite{SPARKFUN2020}. For a tutorial on how to install libraries within the Arduino IDE, see Ref.~\cite{SPARKFUN2020A}.
As for the NodeMCU and the OLED display, the Arduino IDE library manager is able to provide the required libraries.
The source code for the \coo monitor as described in this paper is available on GitHub~\cite{KOEHN2020}, in order to be able to update and extend it. Nevertheless, we have also included the code in this paper, to provide a complete description of the project. At the very beginning of the code, some switches are set defining the general behavior of the program, as can be seen in Listing~\ref{lst:switches}.
\lstinputlisting[firstline=35, lastline=50, caption={General behavior of the program is set via some switches.}, label={lst:switches}]%
{code/CO2_monitor.ino}
The \texttt{include} statements to import the required libraries are shown in Listing~\ref{lst:include}. The \texttt{Adafruit\_GFX.h} and \texttt{Adafruit\_SSD1306.h} libraries are used for an OLED display (if one is connected) and are required to be installed via the library manager of the Arduino IDE beforehand (alternatively, they are also available on GitHub~\cite{ADAFRUIT2020A} for manual installation). The \texttt{LiquidCrystal\_I2C.h} library is used for the LCD display (if one is connected) and is also required to be installed via the library manager (or directly from GitHub~\cite{RICKMAN2020}). Note that the OLED and/or LCD display size needs to be set correctly and can vary. The \texttt{SparkFun\_SCD30\_Arduino\_Library.h} also needs to be installed via the library manager (or manually from the GitHub repository~\cite{SPARKFUN2020}).
\lstinputlisting[firstline=53, lastline=87, caption={Load required libraries.}, label={lst:include}]%
{code/CO2_monitor.ino}
A switch is included in the header of the code allowing to enable or disable WiFi capabilities (by setting the variable \texttt{WIFI\_ENABLED} respectively to \texttt{true} or \texttt{false}). The libraries required for using WiFi are only included if the corresponding switch is set to \texttt{true}. In this example, we decided to use the \texttt{ESPAsyncWebServer}~\cite{MENODEV2020B}, based on \texttt{ESPAsyncTCP}~\cite{MENODEV2020A}, for a webserver supposed to run on the ESP8266 because asynchronous networks, as provided by these two libraries, allow us to handle more than just one connection at a time (which is important if used in a classroom environment). During the time of writing this article, these libraries require manual installation, i.e.\ getting a \texttt{zip} file from the GitHub repositories and include those zip files manually as libraries in the Arduino IDE.
Hardware configurations, including the size of the display used, and some global constants are set after the include statements, as shown in Listing~\ref{lst:global_constants}.
\lstinputlisting[firstline=90, lastline=130, caption={Set some configurations.}, label={lst:global_constants}]%
{code/CO2_monitor.ino}
Due to the complexity of the code, we decided to encapsulate certain parts in separate functions and use the technique of function prototyping and declaration. The function prototypes are shown in Listing~\ref{lst:function_prototypes}.
\lstinputlisting[firstline=133, lastline=147, caption={Function prototypes.},label={lst:function_prototypes}]%
{code/CO2_monitor.ino}
Following the function prototypes, hardware declarations are executed, as shown in Listing~\ref{lst:hardware_declarations}.
\lstinputlisting[firstline=150, lastline=163, caption={Hardware declarations.}, label={lst:hardware_declarations}]%
{code/CO2_monitor.ino}
To display the values measured by the SCD30 sensor on a website, we use global variables in the code, as shown in Listing~\ref{lst:prepare_website}. The complete html code for the website is loaded via including it as a library.
\lstinputlisting[firstline=166, lastline=185, caption={Prepare website.}, label={lst:prepare_website}]%
{code/CO2_monitor.ino}
The code for the webpage itself is shown in Listing~\ref{lst:website_html}.
\lstinputlisting[caption={Code for the webpage.}, label={lst:website_html}, language=html]%
{code/Webpageindex.h}
As usual, the function declarations are all located at the end of the code but are briefly discussed first before coming to the main \texttt{setup()} and \texttt{loop()} functions. The function to print the data obtained from the SCD30 to the serial console is shown in Listing~\ref{lst:printSerial}. Since it is possible to use an OLED and/or LCD display to show the measured data, a separate function for each case is included in the code, see Listing~\ref{lst:printOLED} and Listing~~\ref{lst:printLCD}
\lstinputlisting[firstline=486, lastline=496, caption={Function which prints data to the serial console.},label={lst:printSerial}]%
{code/CO2_monitor.ino}
\lstinputlisting[firstline=497, lastline=527, caption={Function which prints data to an OLED display.}, label={lst:printOLED}]%
{code/CO2_monitor.ino}
\lstinputlisting[firstline=530, lastline=570, caption={Function which prints data to an LCD display.}, label={lst:printLCD}]%
{code/CO2_monitor.ino}
Depending on the the \coo concentration, the OLED display shows an emoji with the level of happiness being correlated to the value of the \coo concentration. The corresponding function to draw that face is given in Listing~\ref{lst:printOLEDampel}. For the LCD display, a warning is shown if the \coo concentration is too high, the corresponding code is shown in Listing~\ref{lst:printLCDampel}.
\lstinputlisting[firstline=573, lastline=709, caption={Function which prints smileys to the OLED display depending on the value of the \coo concentration.}, label={lst:printOLEDampel}]%
{code/CO2_monitor.ino}
\lstinputlisting[firstline=712, lastline=731, caption={Function which prints a warning to the LCD display depending on the value of the \coo concentration.}, label={lst:printLCDampel}]%
{code/CO2_monitor.ino}
Listing~\ref{lst:setup} shows the \texttt{setup} function of the code, where the serial monitor is initialized, followed by the diode, optionally the WiFi, the OLED display, and then the SCD30. Finally, the webserver and the functions required to update the data on the webpage are prepared.
\lstinputlisting[firstline=192, lastline=317, caption={General setup function.}, label={lst:setup}]%
{code/CO2_monitor.ino}
The calibration and setup of the SCD30 is put into a separate function, shown in Listing~\ref{lst:SCD30setup}. An additional function, given in Listing~\ref{lst:SCD30_FRC}, performs the forced recalibration of the SCD30 discussed in Section~\ref{s:SCD30calibration}.
\lstinputlisting[firstline=405, lastline=438, caption={Setup code for the SCD30.}, label={lst:SCD30setup}]%
{code/CO2_monitor.ino}
\lstinputlisting[firstline=441, lastline=483, caption={Function to perform a forced recalibration of the SCD30.}, label={lst:SCD30_FRC}]%
{code/CO2_monitor.ino}
The main code, the \texttt{loop} function, is given in Listing~\ref{lst:main}. First, the data is obtained from the SCD30 sensor and then passed to a function outputting it to the serial monitor and then to another function, printing it on an OLED and/or LCD display. The data is then copied into the corresponding global variables to prepare the next update for the webpage. Finally, it is checked if the \coo concentration is above a critical threshold: a red LED indicates too high a value in our example, in addition some reaction on the OLED/LCD display is shown (one could also think of an acoustic signal and some visual change on the webpage).
\lstinputlisting[firstline=320, lastline=399, caption={Main loop which is executed repeatedly.}, label={lst:main}]%
{code/CO2_monitor.ino}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% acknowledgments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Acknowledgments}
The author is indebted to the efforts of the open-source software community.
\bibliography{CO2_monitor}
\end{document}