writeup.tex (17599B)
1 \documentclass[a4paper,12pt]{article} 2 3 \usepackage[backend=bibtex]{biblatex} 4 \usepackage{geometry} 5 \usepackage{titling} 6 \usepackage{titlesec} 7 \usepackage[english]{babel} 8 \usepackage[hidelinks]{hyperref} 9 \usepackage{listings} 10 \usepackage{xcolor} 11 \usepackage{graphicx} 12 \usepackage{forest} 13 \usepackage{tikz-qtree} 14 \usepackage[siunitx, european, straightvoltages, cute inductors]{circuitikz} 15 \usepackage{setspace} 16 \usepackage{ragged2e} 17 \usepackage{graphicx} 18 \graphicspath{ {./images/} } 19 20 \addbibresource{ref.bib} 21 22 \definecolor{codegreen}{rgb}{0,0.6,0} 23 \definecolor{codegray}{rgb}{0.5,0.5,0.5} 24 \definecolor{codepurple}{rgb}{0.58,0,0.82} 25 \definecolor{backcolour}{rgb}{0.95,0.95,0.92} 26 27 \lstdefinestyle{mystyle}{ 28 backgroundcolor=\color{backcolour}, 29 commentstyle=\color{codegreen}, 30 keywordstyle=\color{magenta}, 31 numberstyle=\tiny\color{codegray}, 32 stringstyle=\color{codepurple}, 33 basicstyle=\ttfamily\footnotesize, 34 breakatwhitespace=false, 35 breaklines=true, 36 captionpos=b, 37 keepspaces=true, 38 numbers=left, 39 numbersep=5pt, 40 showspaces=false, 41 showstringspaces=false, 42 showtabs=false, 43 tabsize=8 44 } 45 \lstset{style=mystyle} 46 47 \tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30] 48 \tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=0cm, minimum height=1cm, text centered, draw=black, fill=blue!30] 49 \tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30] 50 \tikzstyle{subroutine} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=yellow!30, double distance=1] 51 \tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30] 52 \tikzstyle{arrow} = [thick,->,>=stealth] 53 54 55 \titleformat{\section} {\Huge} {} {0em} {}[\titlerule] 56 \geometry{a4paper,total={170mm,257mm},left=25mm,right=25mm,} 57 58 \author{Lucas Standen} 59 \title{Creating a simple temprature sensing circuit} 60 61 \begin{document} 62 \maketitle 63 64 \newpage 65 \tableofcontents 66 \newpage 67 68 \setlength{\parskip}{1em} 69 70 {\setlength{\parindent}{0cm} 71 \section{System Planning} 72 \subsection{Problem analysis} 73 My circuit will sense temperature, and will be taking into consideration pet owners, worried about their homes over-heating 74 for their pets, this will be especially helpful for owners of sensitive pets such as fish. People who own these pets often 75 leave them at home alone, which can be deadly on summer days, my device plans to alert the owner, and can be attached to other 76 systems such as a cooling system. 77 78 My system, will flash an LED and pulse a buzzer to make it clear that it is too hot, have an indicator to tell 79 the user that something has gone wrong, and have a pin to free to attach to an external system. It will have a 80 adjustment dial to change the threshold, so the user can specify what temperature is too hot. 81 82 \subsection{Who is it for?} 83 My project will be used by pet owners, focussing on fish, to keep the tank at the 84 correct temperature. This is a broad range of people as many people own fish\cite{FISH}. Many fish die due to 85 their tanks getting too hot, especially in the summer, my project is perfect for these fish owners. 86 87 \section{Design specification} 88 \subsection{Design brief} 89 This project will need to achieve a few goals to be deemed as a success, they are as follows: 90 \begin{description} 91 \item[] Display a status LED to tell the user all is working as expected 92 \item[] Check the temperature against a known value 93 \item[] Have the ability to notify the user if the temperature is above the known value 94 \item[] Have the ability to inform the user if the temperature has risen above the known value and then fallen again 95 \item[] To have the system reset easily 96 \end{description} 97 If my project can meet all of these goals it will be a useable temperature sensing system, primarily designed for fish tanks, 98 but could be used in any number of temperature dependant environments. 99 \subsection{System Design} 100 \subsubsection{Specific ideal values} 101 For my system, there will be ideal values that id like to tune for, so my circuit switches on at the correct temperatures, 102 and for the correct amount of time. 103 \begin{center} 104 \begin{description} 105 \item[Temprature that it should turn on at] It should switch at approximately 106 \textbf{\({26}^\circ C \)} 107 with a \textbf{5\%} tolerance. This is just the value I will tune it too, in reality the user could set any value 108 they like. 109 \item[Time it should be on for] It should switch on for \textbf{10} seconds, pulsing from on to off. With it high to low 110 ratio of \textbf{1:1}, so its on for 1 to second and off for another. 111 \end{description} 112 \end{center} 113 \subsubsection{Outline of internal workings} 114 The project will need to do the following things internally to function as outlined in the design brief. These are tasks that 115 will be ran on the microcontroller by the assembly code I need to write. 116 \begin{description} 117 \item[] Read the temperature 118 \item[] Compare the temperature to a known value 119 \item[] The output is a flashing led and buzzer 120 \item[] The output is a flashing led and buzzer 121 \end{description} 122 123 \subsubsection{Outline of component roles} 124 My system will contain the following components to function scouring to my outline of internal workings: 125 \begin{description} 126 \item[Mircocontroller] This will be used to control all the other components \item[Thermistor] This will 127 sense the temperature 128 \item[Potentiomiter] This will set the activation threshold 129 \item[Red, Green and Amber LED's] These will indicate the state of the device 130 \item[Buzzer] This will indicate that it is too 131 hot 132 \item[Button] This will reset the device 133 \end{description} 134 With these components I will make a circuit that can be used to sense and warn a user about 135 high temperatures. The design will revolve around the micro controller, with everything else coming off it as a 136 sub system like so: 137 138 \begin{center} 139 \begin{tikzpicture} 140 \tikzset{edge from parent/.style={draw,edge from parent path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}}} 141 \Tree 142 [.Button 143 [.Microcontroller 144 [.Inputs 145 [.Thermistor ] [.Potentiomiter ] 146 ] [.Outputs 147 [.LED(green) ] [.LED(red) ] [.LED(amber) ] [.Buzzer ] 148 ] 149 ] 150 ] 151 \end{tikzpicture} 152 \end{center} 153 154 As one can see a button will control the Microcontroller, by drawing all the current that the power supply 155 can through the button, one can make the Microcontroller reset. The Microcontroller will have 2 inputs, and 156 4 outputs. The potentiometer will be used to set the threshold in which the warnings begin, this will be done 157 inside the microcontroller, with a subtraction between the Thermistor value, and the potentiometer value. The 158 needed outputs will pulse to be especially clear that something is wrong. 159 160 \subsection{Planning the inner workings} 161 \subsubsection{Flowchart} 162 Here is my code, built into an abstracted flow chart, to make the reading of the program easier. 163 It is spread across 2 pages, to ensure it is big enough to read. 164 165 \begin{tikzpicture}[node distance=2cm] 166 \node (start) [startstop] {Start}; 167 \node (in1) [io, below of=start] {Read temperature}; 168 \node (in2) [io, below of=in1] {Read threshold value}; 169 \node (dec1) [decision, below of=in2, yshift=-2cm] {Is the temperature too hot?}; 170 \node (sub1) [subroutine, right of=dec1, xshift=6cm] {Flash}; 171 \node (proc1) [process, below of=dec1, yshift=-2cm, xshift=6cm] {Reset the status flag}; 172 173 174 \draw [arrow] (start) -- (in1); 175 \draw [arrow] (in1) -- (in2); 176 \draw [arrow] (in2) -- (dec1); 177 \draw [arrow] (dec1) -- node[anchor=north] {Yes} (sub1); 178 \draw [arrow] (sub1) |- (start); 179 \draw [arrow] (dec1) |- node[anchor=east] {No} (proc1); 180 \draw [arrow] (proc1) |- (start); 181 \end{tikzpicture} 182 \newpage 183 \begin{tikzpicture}[node distance=2cm] 184 \node (flash) [subroutine, below of=dec1, yshift=-4cm] {Flash}; 185 \node (proc2) [process, below of=flash] {Set counter to 5}; 186 \node (out1) [io, below of=proc2] {Set LED and buzzer on}; 187 \node (proc3) [process, below of=out1] {Wait 1 second}; 188 \node (proc4) [process, below of=proc3] {Decrement 1 from the counter}; 189 \node (dec2) [decision, below of=proc4, yshift=-1cm] {Is counter == 0}; 190 \node (out3) [io, below of=dec2, yshift=-1cm] {Set LED and buzzer off}; 191 \node (return) [subroutine, below of=out3] {Return}; 192 \node (out2) [io, right of=dec2, xshift=6cm] {Set LED and buzzer off}; 193 \node (proc5) [process, above of=out2] {Wait 1 second}; 194 195 \draw [arrow] (flash) -- (proc2); 196 \draw [arrow] (proc2) -- (out1); 197 \draw [arrow] (out1) -- (proc3); 198 \draw [arrow] (proc3) -- (proc4); 199 \draw [arrow] (proc4) -- (dec2); 200 \draw [arrow] (dec2) -- node[anchor=north] {No} (out2); 201 \draw [arrow] (dec2) -- node[anchor=east] {Yes} (out3); 202 \draw [arrow] (out3) -- (return); 203 \draw [arrow] (out2) -- (proc5); 204 \draw [arrow] (proc5) |- (out1); 205 \end{tikzpicture} 206 207 208 209 \subsubsection{How will it function outside of the microcontroller?} 210 Bellow is the diagram for my circuit, it works mostly via the code on the 211 micro controller, so this is just connecting things between live and the microcontroller. 212 \begin{flushleft} 213 \begin{circuitikz} 214 \draw (-8,5) to[short,o-o] (8,5){}; % power rail 215 \draw (0,5) node[vcc]{5V}; 216 217 \draw (-8,-6) to[short,o-o] (8,-6){}; % ground rail 218 \draw (0,-6) node[ground]{}; 219 220 \draw (0,3) to[short,o-] (7,3){}; % push button 221 \draw (7,3) to[push button,-o] (7,-6){}; 222 223 \ctikzset{multipoles/thickness=4} 224 \ctikzset{multipoles/external pins thickness=2} 225 \draw (0,0)node[dipchip, 226 num pins=18, external pins width=0.3, 227 external pad fraction=3, 228 scale=1.8, 229 rotate=90](Micro){ 230 \rotatebox{-90}{PICAXE 18m2}}; % micro controller 231 232 \draw (-7, 5) to[thermistor,a=\tiny{100K},o-o] (-7,0){}; % thermistor 233 \draw (-7, 0) to[resistor,a=\tiny{100K},o-o] (-7,-6){}; % thermistor divider resistor 234 235 \draw (-7, 0) to[short, o-] (-6,0){}; %thermistor divider wire 236 \draw (-6, 0) to[short, -] (-6,3){}; 237 \draw(-6, 3) to[short, -] (-4, 3){}; 238 \draw (-4, 3) to[short, -] (Micro.pin 18){}; 239 240 \draw (-8, 5) to[potentiometer, a=\tiny{10K}, -] (-8, -2){}; 241 \draw (-8, -2) to[short, -] (-8, -6){}; 242 243 \draw (-7.5, 1.5) to[short, o-] (-5, 1.5){}; % potentiometer wire 244 \draw (-5, 1.5) to[short,-] (-5, 4){}; 245 \draw (-5, 4) to[short,-] (-3, 4){}; 246 \draw (-3, 4) to[short, -] (Micro.pin 17){}; 247 248 249 \draw (Micro.pin 14) to[short,-o] (0,5){}; %microcontroller live 250 \draw (Micro.pin 5) to[short,-o](0,-6){}; %microcontroller ground 251 252 \draw (Micro.pin 6) to[empty led] (1, -4){}; %output red 253 \draw (Micro.pin 7) to[buzzer] (2, -6){}; %output buzzer 254 \draw (Micro.pin 8) to[empty led] (3, -4){}; %output amber 255 \draw (Micro.pin 9) to[empty led] (4, -4){}; %output green 256 257 \draw (1,-4) to[resistor,-o,a=\tiny{220}] (1,-6){}; % output resistor 258 \draw (3,-4) to[resistor,-o,a=\tiny{220}] (3,-6){}; % output resistor 259 \draw (4,-4) to[resistor,-o,a=\tiny{220}] (4,-6){}; % output resistor 260 \end{circuitikz} 261 \end{flushleft} 262 The way this works is the potential divider on the 263 left feeds into the micro controller which performs a comparison between it and the potentiometer, using the ADC 264 pins on the pic chip. The button seen on the right is being used as a reset switch, for a short time, it can 265 cut short circuit the system, cutting power to the microcontroller, effectively acting as a reset switch. The 266 outputs at the bottom are in order; a red LED that flashes when the circuit detects it is too hot; a buzzer that 267 flashes at the same time; an amber LED that turns on after the flashing has stopped to inform the user that it 268 was too hot at some point; and a green status LED to inform the user that all is working. 269 270 \subsubsection{The code controlling everything else} 271 Bellow is the code for the micro controller. It is 58 lines long and commented. It contains 12 unique instructions. 272 \lstinputlisting[]{./final.asm} 273 This code starts with an initialisation section, that sets the micro controller's input and output pins to do 274 the correct things. Then it defines a subroutine that flashes the LED and buzzer and sets the status led. And 275 finally the main function runs in a loop to continue checking if it is too hot. 276 \subsubsection{Errors in code} 277 Through out the development of project, a few errors came up in my code, I fixed them, however here is a documented 278 list of them 279 \subsubsection{Forgetting to specify the output register} 280 \lstinputlisting[]{./final.1.err} 281 this error was fixed by adding ", w" to the end of the line (before the comment), as it had been missing an argument 282 before this point. 283 \subsubsection{Bit test file, skip if set or skip if clear} 284 While this didn't stop my code from compiling, it did stop the code from working properly, with it triggering when it 285 was the right temperature, and stopped when it was too hot. It was a simple fix however, all that needed to change 286 was to change a C to an S. 287 288 \section{System Realisation} 289 After designing and writing the functionality, code, and the circuit it was time to build it. Here is the finished results. 290 \subsection{Circuit realisation} 291 292 \includegraphics[width=\textwidth]{off.jpg.jpeg} 293 294 Here is my finished design prototyped on a bread board, I have cut the wires to an adequate length to ensure it is cleanly made. 295 I left the potential divider uncut, as I changed what value components I was using many times throughout building. In this photo 296 an external (off breadboard) thermistor is being used. 297 298 I decided to use a multi-turn potentiometer instead of a traditional one, this allowed me and the end user, to calibrate the 299 system to far smaller amounts. 300 301 \subsection{Calibrating the sensors and testing the system} 302 To calibrate my system I used water at a known temperature and a thermometer to measure. I then tuned my potentiometer to the adequate 303 value to ensure the circuit functioned as intended. 304 305 Here is the circuit at a normal state with water at \({20}^\circ C \). 306 \\ 307 \\ 308 \includegraphics[width=\textwidth]{normal.jpg.jpeg} 309 \\ 310 As one can see the green LED is on at the correct time! 311 \\ 312 \includegraphics[width=\textwidth]{offtemp.jpg.jpeg} 313 \\ 314 After adding more hot water one can see it switch to the higher point. 315 \\ 316 \includegraphics[width=\textwidth]{hotLED.jpg.jpeg} 317 \\ 318 As the temperature rises above the \({26}^\circ C \) switching threshold the red LED begins to blink. 319 \\ 320 \includegraphics[width=\textwidth]{hightemp.jpg.jpeg} 321 \\ 322 \includegraphics[width=\textwidth]{formerhot.jpg.jpeg} 323 \\ 324 As one can see after it falls back to a low temperature the amber status LED comes on to let the user know 325 it has been too hot. 326 \\ 327 \includegraphics[width=\textwidth]{lowtemp.jpg.jpeg} 328 \\ 329 This temperature caused the amber LED to come on after being at \({26}^\circ C \) previously. 330 \\ 331 \subsection{Results} 332 As shown in the previous sections the circuit has worked as intended, it switches at a user defined temperature, which for testing 333 purposes I have set to \({26}^\circ C \). The tuning process is easy and simple to work with, only requiring the turning of a potentiometer. 334 This could be set out of box in a production setting, or it could be tweaked by the use to their needs. 335 336 As intended It triggered at \({26}^\circ C \), in reality it was probably slightly out but not to a noticeable margin. 337 338 It also was triggered for the full 10 seconds as planned, with everything being accurate enough to not have any noticeable errors/inconsistencies. 339 340 \section{System Evaluation} 341 \subsection{What could go better?} 342 To make this system better I would have liked to make it test temperatures using a difference amplifier to compare to another known temperature as this 343 would have let me compare to room temperature, instead of set constants, this would be more helpful if the use case was slightly changed, to show relative 344 temperature, which would be helpful in a factory to show temperatures next to a machine. This however was out of the scope of this project, as I was 345 attempting to use a microcontroller to do all comparisons, a difference amplifier would have removed the need for the microcontroller, making the project 346 irrelevant. 347 348 I also would have liked it if I could have added more features to the code, perhaps in some way adding an interrupt service to allow for further user control. 349 Perhaps as a simple clear amber status LED. 350 351 Finally I was not overly happy with my solution to resetting the microcontroller, I chose to, for a short time, short circuit the power rails of my bread board, 352 to cut power from the microcontroller, if I were to make any edits to this system I would have replaced this with a simple MOSFET system that could keep it 353 powered until a button was pressed. This sadly wasn't possible due to time constraints on this project. This is also caused a flaw in the 18M2 picaxe chip. The 354 original 16F88 has a reset pin, that could have been used to clear the microcontroller's state , this isn't available on the 18M2 chip. 355 356 \subsection{Conclusions} 357 Overall, including short comings, I am happy with my system. It completed my design brief of a simple temperature sensing system in a simple way. I believe this 358 could be used for its goal of triggering alarms when fish tanks of other similar items, reach an unsafe temperature. 359 360 \newpage 361 362 \printbibliography 363 } 364 \end{document}