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
|
\section{Interfacing thermistor from \scilab}
\subsection{Interfacing the thermistor}
In this section we will explain a \scilab\ script to read the thermistor
values. Based on the acquired values, we will change
the state of the buzzer. The Shield has to be attached to the \arduino\ board
before doing these experiments and the \arduino\ needs to be connected to the computer
with a USB cable, as shown in \figref{arduino}.
The reader should go through the instructions given in
\secref{sec:sci-start} before getting started.
% The {\tt cmd\_analog\_in} command
% will be used to read from thermistor connected to an analog input
% pin. The experiments will be carried out using \scilab.
\begin{enumerate}
\item In the first experiment, we will read the thermistor values and display it in
\scilab\ Console. The code for this experiment is
given in \sciref{sci:therm-read}. As explained earlier in \secref{sec:light-sci},
we begin with serial port initialization. Then, we read the input coming from
analog pin 4 using the following command:
\lstinputlisting[firstline=4,lastline=4]
{\LocTHERMscicode/therm-read.sce}
Note that the one leg of the thermistor on
the Shield is connected to analog pin 4 of \arduino\,
as given in \figref{fig:therm-conn}. The read value is stored in variable {\tt val} and
displayed in the \scilab\ Console by the following command:
\lstinputlisting[firstline=5,lastline=5]
{\LocTHERMscicode/therm-read.sce} where {\tt val} contains
the thermistor values ranging from 0 to 1023. The changes in
the thermistor resistance is sensed as a voltage change between 0 to
5V. The ADC maps the thermistor voltage readings in to values
ranging from 0 to 1023. This means 0 for 0 volts and 1023 for 5
volts. At room temperature you may get the
output of ADC around 500. If a heating or cooling source is available,
one can observe the increase or decrease in the ADC output. To
encourage the user to have a good hands-on, we run these commands in
a {\tt for} loop for 20 iterations.
While running this experiment,
the readers should try holding (or rubbing) the thermistor with their fingertips.
Doing so will transfer heat from the person holding the
thermistor, thereby raising the temperature of the thermistor. Accordingly, they should observe the change in the thermistor
values on \scilab\ Console.
% In the first experiment, \sciref{sci:therm-read} is used to read
% values from thermistor. First the serial port is opened using the
% command {\tt open\_serial} and passing the correct port number to
% it. The command {\tt cmd\_analog\_in} is used to read from the
% analog pin. The pin number is passed to this command as an
% argument. The read value is stored in some variable. The value is
% then displayed on the scilab console. A sleep of 500 millisecond is
% executed using the {\tt sleep} command and then the reading process
% is repeated 20 times by putting it in a {\tt for} loop. After the
% loop is finished the serial port is closed using the {\tt
% close\_serial} command.
\item This experiment is an extension of the previous
experiment. Here, we will use a \scilab\ script to
turn a buzzer on using the thermistor values. This experiment
can be considered as a simple fire alarm circuit that
detects fires based on a sudden change in temperature and
activates the buzzer.
The program for this is available at
\sciref{sci:therm-buzzer}. As explained earlier,
the ADC maps the thermistor voltage readings in to values
ranging from 0 to 1023. This means 0 for 0 volts and 1023 for 5
volts. In this experiment we compare the ADC output value with a user-defined
threshold, which has been set as 550 in this experiment. One may note that
this threshold would vary according to the location and time of performing
this experiment. Accordingly, the readers are advised to change this threshold
in \sciref{sci:therm-buzzer}. For testing purposes, one may note the
normal thermistor readings generated from the execution of \sciref{sci:therm-read}
and set a threshold that is approximately 10 more than these readings.
In this experiment, as soon as the value exceeds 550, the buzzer is turned on. The following lines of code perform this
comparison and sending a {HIGH} signal to digital pin 3 on \arduino:
\lstinputlisting[firstline=6,lastline=10]{\LocTHERMscicode/therm-buzzer.sce}
A delay of half a second is introduced
before the next value is read. While running this experiment,
the readers should try holding (or rubbing) the thermistor with their fingertips.
Doing so will transfer heat from the person holding the
thermistor, thereby raising the temperature of the thermistor.
Accordingly, they should observe whether the threshold of 550 is achieved
and the buzzer is enabled.
\paragraph{Note:} Once the thermistor value reaches 550 (the threshold), the value will remain the same
(unless it is cooled). Therefore, the buzzer will continuously produce the sound, which might be
a bit annoying. To get rid of this, the readers are advised to
execute some other code on \arduino\ like \sciref{sci:therm-read}.
\end{enumerate}
\begin{exercise}
Carry out the exercise below: Convert the ADC output readings to
degree Celsius. There are two ways to do so.
\begin{enumerate}
\item In the first method,
\begin{align}
\frac{1}{T}=A+B*\ln(R)+C*(\ln(R))^3
\label{therm-abc}
\end{align}
equation \ref{therm-abc} can be used if the value of A, B, C and R are
known. The temperature T is in kelvin and thermistor resistance R is
in ohms. The values of A, B and C can be found out by measuring
thermistor resistance against three known values of temperatures. The
values of temperature must be within the operating range and should
typically include the room temperature. Once a set of three values of
T and R are known it will result in three equations with three
unknowns. The values of A, B, C can be found out by solving the three
equations simultaneously. Once the values of A, B, C are known, the
same equation can be used to directly convert resistance to kelvin. It
can be then converted to Celsius. This method is preferred when the
temperature coefficient of thermistor is not known or is known very
approximately. This method is bit cumbersome but can give accurate
temperature conversion.
\item In the second method,
\begin{align}
\frac{1}{T}=\frac{1}{T_0}+\frac{1}{\beta}*\ln\left(\frac{R}{R_0}\right)
\label{therm-beta}
\end{align}
equation \ref{therm-beta} can be used if the value of $\beta$ i.e. the
Temperature Coefficient of Resistance of the thermistor used is
known. The value of $\beta$ can be found in the data sheet of the
thermistor used. $R$ is the resistance of thermistor at temperature
$T$ in kelvin. $R_0$ is the resistance of thermistor at room
temperature $T_0$ in kelvin.
\end{enumerate}
\end{exercise}
\subsection{Scilab Code}
\label{sec:therm-scilab-code}
\addtocontents{cod}{\protect\addvspace{\codclr}}
\begin{scicode}
\ccaption{Read and display the thermistor values} {Read and display
the thermistor values. Available at
\LocTHERMscibrief{therm-read.sce}.}
\label{sci:therm-read}
\lstinputlisting{\LocTHERMscicode/therm-read.sce}
\end{scicode}
\begin{scicode}
\ccaption{Turning the buzzer on using thermistor values}
{Turning the buzzer on using the thermistor values read by
ADC. Available at \LocTHERMscibrief{therm-buzzer.sce}.}
\label{sci:therm-buzzer}
\lstinputlisting{\LocTHERMscicode/therm-buzzer.sce}
\end{scicode}
\section{Interfacing thermistor from Xcos}
In this section, we discuss how to read and use the thermistor values using
Xcos blocks. The reader should go
through the instructions given in \secref{sec:xcos-start} before
getting started.
\begin{enumerate}
\item First we will read the thermistor values and display it. When the
file required for this experiment is invoked, one gets the GUI as in
\figref{fig:therm-read}. In the caption of this figure, one
can see where to locate the file.
As discussed in earlier chapters, we start with the initialization
of the serial port. Next, using {\tt Analog Read} block, we read
the values of thermistor connected on analog pin 4.
Next, we use a scope to plot the values
coming from this pin. When this Xcos file is simulated,
a plot is opened, as shown in \figref{fig:therm-read-output}.
\begin{figure}
\centering
\includegraphics[width=\smfigp]{\LocTHERMfig/therm-read-xcos.png}
\caption[Xcos diagram to read thermistor values]{Xcos diagram to
read thermistor values. This is what one sees when
\LocTHERMscibrief{therm-read.zcos}, is invoked.}
\label{fig:therm-read}
\end{figure}
We will next explain how to set the parameters for this simulation.
To set value on any block, one needs to right click and open the
{\tt Block Parameters} or double click. The values for each block
is tabulated in \tabref{tab:therm-read}. All other parameters are to
be left unchanged.
\begin{table}
\centering
\caption{Xcos parameters to read thermistor}
\label{tab:therm-read}
\begin{tabular}{lp{2.5cm}p{2.2cm}} \hline
Name of the block & Parameter name & Value \\ \hline
ARDUINO\_SETUP & Identifier of Arduino Card & 1 \\
& Serial com port number & 2\portcmd \\ \hline
TIME\_SAMPLE & Duration of acquisition(s) & 100 \\
& Sampling period(s) & 0.1 \\ \hline
ANALOG\_READ\_SB & Analog Pin & 4 \\
& Arduino card number & 1 \\ \hline
CSCOPE & Ymin & 200 \\
& Ymax & 600 \\
& Refresh period & 100 \\ \hline
CLOCK\_c & Period & 0.1 \\
& Initialisation Time & 0 \\ \hline
\end{tabular}
\end{table}
\begin{figure}
\centering
\includegraphics[width=\smfigp]{\LocTHERMfig/therm-read.png}
\caption{Plot window in Xcos to read thermistor values}
\label{fig:therm-read-output}
\end{figure}
While running this experiment,
the readers should try holding (or rubbing) the thermistor with their fingertips.
Doing so will transfer heat from the person holding the
thermistor, thereby raising the temperature of the thermistor. Accordingly, they should observe the change in the thermistor
values in the output plot, as shown in \figref{fig:therm-read-output}.
\item In the second experiment, we will switch on a buzzer
depending on the thermistor readings (ADC output).
When the file required for this
experiment is invoked, one gets the GUI as in \figref{fig:therm-buzzer}.
In the caption of this figure, one can see where to locate the file.
\begin{figure}
\centering
\includegraphics[width=\lgfig]{\LocTHERMfig/therm-buzzer-xcos.png}
\caption[Xcos diagram to read the value of thermistor, which is
used to turn the buzzer on] {Xcos diagram to read the value
of the thermistor, which is used to turn the buzzer on.
This is what one sees when
\LocTHERMscibrief{therm-buzzer.zcos}, is invoked.}
\label{fig:therm-buzzer}
\end{figure}
We will next explain how to set the parameters for this simulation.
To set value on any block, one needs to right click and open the
{\tt Block Parameters} or double click. The values for each block
is tabulated in \tabref{tab:therm-buzzer}. In the CSCOPE\_c block, the
two values correspond to two graphs, one for digital write and other
for analog read values. All other parameters are to be left
unchanged. When this Xcos file is simulated, a plot is opened,
as shown in \figref{fig:therm-buzzer-output}.
\begin{table}
\centering
\caption{Xcos parameters to read thermistor and switch the buzzer}
\label{tab:therm-buzzer}
\begin{tabular}{lp{2.5cm}p{2.2cm}} \hline
Name of the block & Parameter name & Value \\ \hline
ARDUINO\_SETUP & Identifier of Arduino Card & 1 \\
& Serial com port number & 2\portcmd \\ \hline
TIME\_SAMPLE & Duration of acquisition(s) & 100 \\
& Sampling period(s) & 0.1 \\ \hline
ANALOG\_READ\_SB & Analog pin & 4 \\
& Arduino card number & 1 \\ \hline
CMSCOPE & Ymin & 0 300 \\
& Ymax & 1 600 \\
& Refresh period & 100 100 \\ \hline
CLOCK\_c & Period & 0.1 \\
& Initialisation time & 0 \\ \hline
SWITCH2\_m & Datatype & 1 \\
& threshold & 550 \\
& pass first input if field & 0 \\
& use zero crossing & 1 \\ \hline
DIGITAL\_WRITE\_SB & Digital pin & 3 \\
& Arduino card number & 1 \\ \hline
\end{tabular}
\end{table}
\begin{figure}
\centering
\includegraphics[width=\lgfig]{\LocTHERMfig/therm-buzzer.png}
\caption{Plot window in Xcos to read thermistor values and the state of LED}
\label{fig:therm-buzzer-output}
\end{figure}
While running this experiment,
the readers should try holding (or rubbing) the thermistor with their fingertips.
Doing so will transfer heat from the person holding the
thermistor, thereby raising the temperature of the thermistor.
Accordingly, they should observe whether the threshold of 550 is achieved
and the buzzer is enabled.
\paragraph{Note:} Once the thermistor value reaches 550 (the threshold), the value will remain the same
(unless it is cooled). Therefore, the buzzer will continuously produce the sound, which might be
a bit annoying. To get rid of this, the readers are advised to
execute some other code on \arduino\ like the Xcos file shown in
\figref{fig:therm-read}.
\end{enumerate}
|