62
IN DEGREE PROJECT TECHNOLOGY, FIRST CYCLE, 15 CREDITS , STOCKHOLM SWEDEN 2019 Automated water mixer JUSTUS CONRADI PATRIK TIAINEN KTH ROYAL INSTITUTE OF TECHNOLOGY SCHOOL OF INDUSTRIAL ENGINEERING AND MANAGEMENT

Automated water mixer

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Automated water mixer

IN DEGREE PROJECT TECHNOLOGY,FIRST CYCLE, 15 CREDITS

, STOCKHOLM SWEDEN 2019

Automated water mixer

JUSTUS CONRADI

PATRIK TIAINEN

KTH ROYAL INSTITUTE OF TECHNOLOGYSCHOOL OF INDUSTRIAL ENGINEERING AND MANAGEMENT

Page 2: Automated water mixer

Automated water mixer

Bachelor’s Thesis in Mechatronics

JUSTUS CONRADI AND PATRIK TIAINEN

Bachelor’s Thesis at ITMSupervisor: Nihad SubasicExaminer: Nihad Subasic

TRITA ITM-EX 2019:55

Page 3: Automated water mixer
Page 4: Automated water mixer

AbstractThe aim for this thesis is to explore the possibility to saveboth water and energy in showers. Through a quicker,more responsive and precise shower faucet using digitalthermometers and stepper motors. A faucet has two inputpipes with cold and hot water respectively. To reach a de-sired shower temperature; a single thermometer is needed,to measure the mixed water temperature. Using this infor-mation, two motors will control two valve until the desiredtemperature is reached. To maintain the desired tempera-ture throughout the shower session, the temperature shouldbe continuously monitored and when temperature distur-bance occurs, the valves should compensate for it.

To achieve this a demonstrator was made. The demon-strator uses stepper motors connected to valves to controlthe flow through a hot and cold water pipe. The systemreads the temperature of the output water continuously andmakes appropriate changes to the position of the valves.

Due to safety concerns, no water was used in the testingof the demonstrator. The theoretical response time of thesystem is very short, and the demonstrator can theoret-ically change temperature of the mixed water by around5°Celsius per second.

KeywordsMechatronics, temperature control, flow regulation, steppermotor.

Page 5: Automated water mixer

ReferatAutomatisk vattenblandare

Syftet med denna rapport ar att utforska mojligheternaatt spara bade vatten och energi till duschar, genom ensnabbare, mer responsiv och mer exakt duschblandare. Det-ta ska uppnas genom anvandning av digitala termometraroch stegmotorer. Duschblandaren ska lasa temperaturernaav det blandade vattnet, och justera respektive kran tillsonskad temperatur ar uppnadd. For att bibehalla onskadtemperatur kommer temperaturen kontinuerligt overvakas.Nar storningar i temperatur uppkommer ska duschblanda-ren kompensera for det, och darmed halla en konstant tem-peratur.

For att astakomma detta byggdes en demonstrationsenhet.Denna demonstrationsenhet anvander stegmotorer koppla-de till kranar for att kontrollera flodet genom ett varmt ochett kallt vattenror. Systemet laser konstant temperaturenav det blandade vattnet och gor lampliga andringar av kra-narnas positioner.

Pa grund av sakerhetsrisk anvandes inget vatten vid test-ning av demonstrationsenheten. Den teoretiska responsti-den av systemet ar mycket kort, och demonstrationsenhetenkan teoretiskt andra temperatur av det blandade vattnetmed en hastighet av ungefar 5°Celsius per sekund.

NyckelordMekatronik, temperaturkontroll, flodesreglering, stegmotor.

Page 6: Automated water mixer

Acknowledgements

We would like to thank Nihad Subasic for feedback concerning our idea and ourprocess, Rijad Alisic for help concerning control theory and Seshagopalan Thora-palli Muralidharan for both practical and theoretical help in the workshop. KeylaKearns for proof reading and comments. We would also like thank all fellow stu-dents that have helped us with constructive feedback.

Justus Conradi, Patrik TiainenRoyal Institute of Technology, Stockholm, May 2019

Page 7: Automated water mixer

Contents

1 Introduction 11.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 Idea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.5 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Theory 52.1 Thermodynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.2.1 Stepper motor controllers . . . . . . . . . . . . . . . . . . . . 72.3 Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.3.1 Analogue pins . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.4 Thermometers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.5 Valves and piping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.6 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3 Demonstrator 133.1 Mechanical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3.1.1 Valves and piping . . . . . . . . . . . . . . . . . . . . . . . . 143.1.2 Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.1.3 Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

3.2 Electrical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.2.1 Stepper motor controller . . . . . . . . . . . . . . . . . . . . . 173.2.2 Thermometers . . . . . . . . . . . . . . . . . . . . . . . . . . 173.2.3 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.2.4 Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.3 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4 Results 214.1 Thermometer trials . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.2 Valve assembly trials . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.3 Software simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Page 8: Automated water mixer

5 Discussion and conclusions 255.1 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255.2 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

6 Recommendations and future work 27

Bibliography 29

Appendices 30

A Circuits 31

B JSP 33

C Source code 35

D Thermometer results 43

E Software trials 45

Page 9: Automated water mixer

List of Figures

1.1 General idea of implementation. . . . . . . . . . . . . . . . . . . . . . . 2

2.1 System behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Stepper motor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.3 Stepping procedure, clockwise rotation pattern. . . . . . . . . . . . . . . 82.4 A discretisation of an analogue function. . . . . . . . . . . . . . . . . . . 92.5 Closed loop amplification circuit. . . . . . . . . . . . . . . . . . . . . . . 102.6 Globe valve. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.7 Symbols in JSP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3.1 Complete demonstrator. . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.2 CAD model of the RSK 8473400 globe valve. . . . . . . . . . . . . . . . 143.3 CAD model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.4 Layout of the MP6500. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.5 LM35 integrated temperature sensor. . . . . . . . . . . . . . . . . . . . . 183.6 Interface to control the device. . . . . . . . . . . . . . . . . . . . . . . . 18

A.1 The complete circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31A.2 The circuit for the interface. . . . . . . . . . . . . . . . . . . . . . . . . . 32A.3 The circuit for the LM35. . . . . . . . . . . . . . . . . . . . . . . . . . . 32

B.1 The JSP for the automated water mixer. . . . . . . . . . . . . . . . . . . 33

D.1 A selection of tests conducted on LM35. . . . . . . . . . . . . . . . . . . 43

E.1 Simulated response due to change in the input water temperature. . . . 45E.2 Simulated response due to change in desired temperature. . . . . . . . . 46

Page 10: Automated water mixer

List of Tables

4.1 Valve assembly speed tests. . . . . . . . . . . . . . . . . . . . . . . . . . 22

Page 11: Automated water mixer
Page 12: Automated water mixer

List of acronyms

ADC - Analogue to digital converter.

CAD - Computer-aided design.

CPU - Central processing unit.DAC - Digital to analogue converter.

DC - Direct current.

IDE - Interactive development environment.

JSP - Jackson structured programming.

LED - Light emitting diode.

RAM - Random access memory.

RTD - Resistance temperature detectors.

PROM - Programmable read only memory.

Page 13: Automated water mixer
Page 14: Automated water mixer

Nomenclature

T Output temperature

mc Mass flow cold water

mc Mass flow hot water

Tc Temperature cold water

Th Temperature hot water

Vc Cold valve opening percentage

Vh Hot valve opening percentage

Tref Desired temperature

t Sample time

V Voltage

n Number of bits

Page 15: Automated water mixer
Page 16: Automated water mixer

Chapter 1

Introduction

1.1 Background

Regulatory systems are widely used in water treatment facilities, mostly to controlwater levels, flow and temperature. Sensors are placed at various locations givingthe necessary information to the regulator. The regulator takes the information fromthe sensors, processes it, and sends the output commands to appropriate motors,valves and actuators. These systems can be complex, and expensive to implement,and are therefore mostly used in heavy industry. Home applications are rare. Withrecent low-cost microcomputers, the regulator can be made and programmed at areasonable cost, making regulated systems more viable for consumers. Home waterregulating systems are often primitive. One or two valves control the flow of hotand cold water thus controlling the temperature and flow of the product of the two.With recent developments in energy efficiency and smart home technology, thesesystems inefficiency stand out.

1.2 Purpose

The purpose of this thesis is to research, develop and build a shower mixer with abuilt-in regulatory system, that is faster at adjusting temperature than a human,thus saving water and energy. The research questions to be answered are:

• How can a fast, reliable, simple and easy-to-use product be built?

• How much energy and water can be saved by implementing the proposeddesign?

• How fast can the system be made?

1

Page 17: Automated water mixer

CHAPTER 1. INTRODUCTION

1.3 MethodTo start, the physical properties of the system are to be determined. This can becompleted in many ways; using thermodynamic principles and testing the systemwith given values is the most suitable method. When the physics of the system aredetermined, parts will be researched. Standard parts will be used whenever possible.When all parts have been determined and sourced, their performance will be tested.The performance of all parts combined will reflect the overall performance of thesystem. Finally, a program to control the system will be made.

1.4 IdeaTo regulate the outgoing temperature of water exiting the system, at least twoinputs are needed. Generally, there is one hot water supply and one cold. By usingtwo valves as in Figure 1.1, these two supplies can be controlled by limiting theirrespective mass-flow rates.

Figure 1.1. General idea of implementation. Illustration made in Affinity Designer.

2

Page 18: Automated water mixer

1.5. SCOPE

1.5 ScopeTo keep the project at a manageable size, certain restrictions in scope were made.First and foremost this is a thesis concerning temperature control so the pressureand flow rate control are therefore not in the scope.

The computer-aided design (CAD) model and physical model are to be treatedas prototypes. Therefore, no regard to mass production, visual appeal or assemblywill be made.

Due to safety concerns from the course supervisor, no water can be used in thedemonstrator for testing. However, smaller subsystems with a very low chance ofleaks will be tested. This leads to difficulties in determining the performance of thefinal product. Therefore, it is assumed that the product is the sum of its parts,meaning that the speed of the system is the combined speed of the individual parts.

3

Page 19: Automated water mixer
Page 20: Automated water mixer

Chapter 2

Theory

2.1 ThermodynamicsTo methodically design the control system, a model of the system must be con-structed. The basis of this model is the mixing of the two fluids. This is simplymodelled by averaging the temperatures and flows of water through the valves[1].

T = mc · Tc + mh · Th

mc + mh(2.1)

From Equation 2.1, both hot and cold mass-flow needs to be regulated to determinethe final output temperature. This is a system with two inputs and one output.To simplify the calculations one of the mass-flow-rates is set to constant (for exam-ple, one of the taps is fully open). Now the system has one input and one output,making it simple to control. Since the mass flow through the valve is the controlledvariable, Equation 2.1 is rewritten as:

mc = mh · Th − T · mh

T − Tc(2.2)

However, this limits the output temperatures that are possible to achieve. Forexample, if the cold valve is constant and set to 100% and the hot valve is regulated,the maximum temperature possible is the average between the two. This is avoidedby regulating the two valves individually, meaning if the hot and cold water valvesare both set to 100% and the target temperature is not reached, set the hot watervalve to constant, and start regulating the cold water. This is can be seen in Figure2.1. This approach has an inherent delay in response time but is necessary for thesystem to have a single input.

5

Page 21: Automated water mixer

CHAPTER 2. THEORY

Figure 2.1. How the system should behave in case both valves are 100% open.Illustration made with Affinity Designer.

2.2 MotorsStepper motors use an even number of coils to rotate an outgoing axis. The coilhas a gear-shaped side facing a rotary-gear shaped axis. When a coil is active, therotary gear aligns with it but offsets to the previous and next coil. To rotate themotor, the first coil is deactivated and the second coil is electrified. The rotary gearthen aligns to the second coil and a step is achieved. For example: to rotate themotor in Figure 2.2, a voltage is applied to A1, then B2, then A2 and so on. Thisprocess is illustrated in Figure 2.3. This would cause the rotor to rotate one stepper applied voltage in the clockwise direction. To step the motor counter-clockwise,the coils are electrified in the opposite order. How much the axis rotates per stepdepends on how many teeth the rotary gear has. For instance, a gear with 50 teethhas step angle of 1.8°[2] [3]. The position of the stepper motor can be calculatedsince the angle that every step generates is known, and how many steps have beentaken.

6

Page 22: Automated water mixer

2.2. MOTORS

Figure 2.2. Stepper motor. A1, A2, B1 and B2 are the voltages applied to the coils.Figure made with Affinity Designer.

2.2.1 Stepper motor controllersTo use stepper motors, a stepper motor controller is advantageous. Controllingthe stepper motors can be a complex procedure. It requires precise control of thevoltage across the motor coils. A dedicated board for doing this is used to reduceprocessing done by the microcontroller.

Stepper motor controllers generally interfaces with the stepper motor via a numberof pins, A1, A2, B2 and B1 in Figure 2.2. To rotate the motor a single step, thestepper motor controller does the procedure described in section 2.2 Motors andFigure 2.3. To interface with the microcontroller a number of pins are used. The“step” pin is pulsed by the microcontoller to send a command to rotate the motor asingle step. To achieve a constant rotation, the step pin is pulsed at a set interval.Most stepper motor controllers also have pins for direction of rotation, sleep modeand step mode. The step mode pins refers to the process of microstepping, meaninga step can be divided to enable more precise control. This is done by applyingdifferent voltages to the coil pairs at the same time [4].

7

Page 23: Automated water mixer

CHAPTER 2. THEORY

Figure 2.3. Stepping procedure, clockwise rotation pattern. A1, A2, B1 and B2 arethe voltages applied to the coils. Figure drawn in Affinity Designer

2.3 MicrocontrollerTo control the motors, given the values read by the thermometers, a microcontrolleris needed. A microcontroller is essentially a small computer. The microcontrollerand a PC share most components, the difference being their size and capabilities [5].

Most computers, including microcontrollers, need random access memory (RAM),a central processing unit (CPU) and programmable read only memory (PROM) tofunction [6]. The CPU is a very large collection of programmable transistors, thisis the component containing all logic operators needed to make calculations, andis able to interface with other components through input and output pins. TheCPU needs a program to perform, this program is located in the PROM, and ismade by the human programmer. The programmer constructs the program andwrites it to PROM. The main difference between the PROM and RAM is the speedand stability. RAM is much faster than PROM, making it more suitable for tasksrequiring fast read and write speeds. In general, the program is loaded from thePROM into the RAM and is ran from RAM by the CPU. The CPU is also able towrite to RAM. This is used to store, for example, the values of program variables.RAM needs constant power to retain its state, PROM does not [5].

2.3.1 Analogue pins

A microcontroller is a purely digital device, meaning it can only input, process andoutput discrete values. These values are represented by the binary numeral system.A system is needed to convert between discrete and continuous functions since mostthings in the physical world are continuous

Some microcontrollers have “analogue pins”, meaning they emulate the shape ofan analogue signal using discrete values. To make this possible, the microcontroller

8

Page 24: Automated water mixer

2.4. THERMOMETERS

is equipped with an Analog to Digital Converter (ADC). This device reads analoguevoltages as binary numbers at a fixed time interval. This creates a list of numbersthat can be interpreted as a discretisation of the input function, according to Figure2.4 [6].

Figure 2.4. A discretisation of an analogue function. Figure drawn in AffinityDesigner

Similarly, the microcontroller is equipped with an Digital to Analogue Converter(DAC), which converts a series of numbers (representing a function) to voltagesthat can be output through a pin.

A shorter sample time and a higher number of bits will clearly make the discretisa-tion more similar to the continuous function, therefore improving the result.

2.4 ThermometersTo detect a temperature electronically, several methods are used, however, they allrely on one principle: change in voltage due to temperature. The analogue pinson a microcontroller are able to detect these changes in voltage. A few methods ofreading this temperature dependent voltage are:

• Temperature dependent resistors: A material that changes resistance depend-ing on temperature. Using Kirchhoff’s and Ohm’s laws, the changing re-sistance is detected, either using a voltage divider or a Wheatstone bridge.Examples of such resistors are resistance temperature detectors (RTD) andthermistors [7].

• Thermocouples: A component that utilises the thermoelectric effect. A smallvoltage is created when two rods made from dissimilar metals change temper-atures [8].

• Semiconductor sensors: Two transistors with different properties create a volt-age between them when the temperature changes [9].

9

Page 25: Automated water mixer

CHAPTER 2. THEORY

All electrical components have some resistance, therefore, passing a current througha component will always cause heating. Self heating is present in all electronic tem-perature sensors. This causes an error in the read temperature. This error variesamong temperature sensors [10].

The voltages created by these components are often very small, in the mV range.For obtaining usable voltages for a 5V, 10-bit ADC the output voltage requiresamplification. An operational amplifier simply scales all incoming voltages by a setfactor. An schematic of an operational amplifier is in Figure 2.5.

RTDs and thermistors offers a small size and good accuracy, but they require aWheatstone bridge to detect the small voltages they produce. Thermocouples arelarge and relativly inaccurate, but they are affordable. Semiconductor sensors aresmall and accurate, but require complex circuit to generate a usable voltage, how-ever, they are usually packaged as part of an integrated circuit [8].

Figure 2.5. Closed loop amplification circuit. Illustration made with Affinity De-signer.

2.5 Valves and pipingSweden and most EU countries use the British pipe standard (BSP). The standardinvolves both parallel and tapered joints. At least 41 unique sizes are available. Forhome use, the G 1/2 size thread is common. “G” meaning gas and “1/2” meaning1/2 inch size [11].

10

Page 26: Automated water mixer

2.5. VALVES AND PIPING

Many different ways of regulating flow through a pipe are available. The most com-mon way is to use a valve, that is to say, converting a rotating motion to a linearmotion in order to limit the flow through a pipe.

The needle valve uses a cone shape to slow down or stop the flow. It enablesprecise control of the flow and requires low torque to operate. The downside is thatthe pipe through the valve is small and it can not withstand high pressures [12].

Globe valves, as seen in Figure 2.6, are widely used in many applications, includinghome use. Globe valves can withstand high pressure and the flow can be regulatedcontinuously, they also offer a near-linear relation between stem angle and flow.They are also relatively cheap to produce [2] [13].

Figure 2.6. A Globe valve [14]

11

Page 27: Automated water mixer

CHAPTER 2. THEORY

2.6 SoftwareTo make a computer program as easy to understand, modify and expand as possibleJackson Structured Programming (JSP) can be used. With this method programfunctions are illustrated as blocks with added symbols for sequence, iteration andselection. Sequence is that the program does the instruction once before proceed-ing to the next. Iteration is that the instruction is repeated several times until apredefined state has been achieved. Selection is a choice dependant on one or morevariables [15]. The symbols used in JSP are illustrated in Figure 2.7 .

Figure 2.7. Symbols in JSP. Illustration made with Affinity Designer.

12

Page 28: Automated water mixer

Chapter 3

Demonstrator

3.1 Mechanical

The complete demonstrator is shown in Figure 3.1. Below are chapters on how thisdesign was reached.

Figure 3.1. Complete demonstrator. Photo.

13

Page 29: Automated water mixer

CHAPTER 3. DEMONSTRATOR

3.1.1 Valves and pipingDifferent kinds of valves were evaluated for their strengths, weaknesses and relevanceto the requirements. To achieve the required flow of water to control the outputtemperature of the system, the valves need to fulfil some criteria. These are asfollows:

• Have a wide spectrum between 0% and 100% flow.

• The relation between how much the tap is open and the flow needs be contin-uous, and preferably linear.

• The valves must require low torque to open and close.

• It should withstand pressures up to eight bar.

The globe valve RSK 8473400 from Trio Perfecta features standard G 1/2 threadsand angled inputs. This valve enables the motors to be mounted at an angle withrespect to the wall mount. The construction can therefore be made more compact.This Globe valve can be viewed in Figure 3.2. Compare to Figure 2.6 for additionalreference.

Figure 3.2. CAD model of the RSK 8473400 globe valve. Figure made with SolidEdge ST10 and Adobe Photoshop

To connect the valves, two 90° pipes and one T-junction were chosen. The T-junction is where the water is mixed and sent out to the shower hose. The 90° pipesare 90°Elbow Threaded Fitting from Conex-Banninger and the T-juncion is a RSPro Stainless Steel Threaded Fitting, Tee from RS PRO. They all use the standardG 1/2 thread. Their configuration can be viewed in Figure 3.3.

14

Page 30: Automated water mixer

3.1. MECHANICAL

3.1.2 MotorsThe main function of this machine is to rotate the two valves. This must be doneaccurately and quickly. To control the valves, the motors have to be able to rotateto specific positions, both clockwise and counter-clockwise. Motors with these fea-tures are stepper motors and servo motors. The circuit for the stepper motors areshown in Appendix A Figure 1.

Stepper motors were chosen since they can be controlled fairly accurately and theyare cheap compared to servomotors. Gearing can also be applied to increase accu-racy and torque, while decreasing speed. [2].

Tamagawa Seiki model number TS3214N16 meets the demands. It has a stepangle of 1.8°, rotates both clockwise and counter-clockwise and has decent enoughtorque [16].

15

Page 31: Automated water mixer

CHAPTER 3. DEMONSTRATOR

3.1.3 ConstructionTo facilitate the construction, maintenance and repair of the product standard com-ponents were chosen where possible. All piping has the same size and thread.

The final configuration of parts was made to be as simple as possible, with onlythree standard piping components connecting to two valves with two motors. Theframe in the demonstrator is made from 3.5 mm laser cut acrylic glued together.In this model custom spur gears were made from the same material, however theycan easily be replaced with standardised parts. A picture of the CAD model canbe seen in Figure 3.3.

Figure 3.3. CAD model. Made with Solid Edge ST 10 and Adobe Photoshop

16

Page 32: Automated water mixer

3.2. ELECTRICAL

3.2 Electrical

3.2.1 Stepper motor controllerThe MP6500 Stepper Motor Driver was chosen as the controller for the steppermotors. It has 16 pins, but only 10 are needed for the stepper motors to perform asintended in this application. The used pins are shown in as filled circles in Figure3.4. The stepper motor driver allows a current of 1,5 A. B2, B1, A1 and A2 corre-spond to B2, B1, A1 and A2 in Figure 2.2. These circuits are shown in ApppendixA.

Figure 3.4. Layout of the MP6500. Made with Affinity Designer

3.2.2 ThermometersFor the system to be responsive to sudden changes in temperature and adjust ac-cordingly, the thermometers need to have a low thermal time constant. To fit inthe pipes they also need to be small and easily isolated from exposure to water.

The LM35 Precision Centigrade Temperature Sensor from Texas instruments isa semiconductor type thermometer. The difference in the transistors causes a volt-age of 8,8 mV/°C. In the integrated circuit this voltage is amplified and linearisedto a stable, and easy to work with 10 mV/°C. The LM35 is calibrated to the Cel-sius scale, meaning the output is zero V at 0°C, and 250 mV at 25°C. Some otherproperties of the LM35 include:

• Ensured accuracy of 0,5°C, with a typical accuracy of 0,25°C around roomtemperature.

• Less than 60 µA current draw.

• Low self heating, negligible in moving water.

• Linear temperature response.

17

Page 33: Automated water mixer

CHAPTER 3. DEMONSTRATOR

The LM35 outputs a high enough voltage to be used by a 5 V 10-bit ADC with-out amplification, and still be accurate enough for this application. It also offers asmall size of less than six mm3 [17]. The circuit for the LM35 is shown in Figure3.5. How the LM35 is connected in this application is shown in Appendix A Figure 3.

Figure 3.5. The LM35 integrated temperature sensor circuit.[17]

3.2.3 InterfaceTo set the desired output temperature, two buttons were used. A single press ofa button changes the value by 1 °C. To communicate the current temperature inrelation to the set temperature, three different coloured light emitting diodes (LED)were used. Red meaning the output is too hot, green meaning it is ± 1 °C fromthe set temperature, and yellow meaning the output is too cold. A schematic viewof the interface is available in Figure 3.6, and wiring diagram can be viewed inAppendix A Figure 3.

Figure 3.6. Interface to control the device. Three LED’s and two buttons. Illustra-tion made with Affinity Designer.

18

Page 34: Automated water mixer

3.3. SOFTWARE

3.2.4 MicrocontrollerAn Arduino Uno was used to read the temperature, process and step the steppermotors. The Arduino is a programmable controller board based on the ATmega328Pmicrocontroller. The board is programmed using a PC with the Arduino InteractiveDevelopment Environment (IDE), and the program is loaded to the PROM with aUSB cable. The Arduino Uno features include:

• A 16 Mhz processor.

• 14 Digital input/output pins.

• 6 Analogue input pins.

• A 5V 10-bit ADC.

• 35 kb of PROM.

In total the thermometer, LED’s, buttons and stepper motor controllers require 10of the available pins. The 35 kb of on-board flash memory and the 16 Mhz CPUare more than enough for this application [6].

3.3 SoftwareThe main function of the software is to rotate the motors to the correct positions.It does this by continually reading the mixed temperature and stepping one of themotors while the temperature is not within a certain range. If the program detectsthat one valve is fully open, it switches to the other. As stated in section 2.1, Ther-modynamics, the program only has to keep track of a single valve at a given time.

The program calculates the position of the valves by counting how many stepshave been taken.

The JSP for the program can be viewed in Appendix B. The full source code forthe Arduino written in C is available in Appendix C.

19

Page 35: Automated water mixer
Page 36: Automated water mixer

Chapter 4

Results

4.1 Thermometer trialsThe LM35 was tested in pipes to research how fast it could detect changes in watertemperature and reach a stable level. Five sets of tests were completed with twoiterations each. Each test was performed with water from a normal tap set tothe warmest or the coldest temperature possible. The thermometer was allowed toreturn to room temperature before testing. The tests were as follows:

• Room temperature to hot water.

• Room temperature to cold water.

• Hot water to cold water

• Cold water to hot water.

• Hot water then adding small amounts of cold water to simulate a temperaturedrop.

The results were saved to a PC from the Arduino using the serial port, the datawas plotted and is shown in Appendix C, Thermometer data.

From the graphs shown in Appendix D, it is clear that the LM35 has a very shortthermal time constant. It can change read temperature by more than 20 °C inunder 50 ms.

In conculsion, the LM35 has a short thermal time constant using the flow throughthis system. This corresponds to a negligible response time.

21

Page 37: Automated water mixer

CHAPTER 4. RESULTS

4.2 Valve assembly trialsThe speed of the valve assembly is critical to the system. To evaluate the perfor-mance of the motors and valves, tests were made. Firstly the maximum speed of theassembly was determined. If the speed is too great for a given torque the steppermotor skips steps. The maximum speed is therefore the speed the motor can rotatewithout skipping. The required torque, and therefore the maximum speed variesduring opening and closing of the valve. This was however neglected and a singlefixed speed was used.

Secondly, the positions of 0% and 100% were determined. The motors were ro-tated between the two positions to find the opening and closing times. Since themotors are rotating with a constant angular velocity the opening and closing of thevalve is considered linear.

Tests were made to evaluate the speed of the valve assembly. The valve was fullyclosed and then rotated to fully open. The motors were stepped as fast as possiblewithout skipping steps. The time to perform this and the number of steps wererecorded.

Table 4.1. Valve assembly speed tests.

Direction Time StepsCW 31 770

CCW 33 642CW 27 620

CCW 31 769CW 28 720

CCW 29 721CW 30 743

CCW 30 786CW 32 684

CCW 30 760

From Table 4.1 it is evident that the time and number of steps required for a fullopening is inconsistent. This is due to irregularities around the extremes of themotion. To make this more consistent, 0% and 100% were set arbitrarily, since itis the ratio between the mass flows that affect the resulting temperature. For thisdemonstrator the 0% was set to closed, meaning no water can pass through thevalve. 100% was set to one full rotation from the closed state.

22

Page 38: Automated water mixer

4.3. SOFTWARE SIMULATION

From Table 4.1 the the angular velocity was calculated by averaging the speeds.The angular velocity of the valve assembly was calculated to 43,25°/s given the stepangle of 1,8°. Assuming that the hot and cold water supplies are at the standardised4°C and 50 °C respectively, the mixer would be able to change output temperatureby 5,52 °C/s. If the input temperatures are not according to the standard, forexample, 10 °C and 40 °C, the speed of the system would be reduced to 3,60 °C/s.

4.3 Software simulationTo confirm that the Software functioned properly, simulations were made. Since nowater was used, the output temperature was calculated using Equation 2.1. Thetemperature of each pipe was set using two potentiometers. The mass flow throughthe pipes was calculated using the positions of the vavles. By using potentiometers,disturbances in the input water could be simulated. The results are plotted in Ap-pendix E Figure 1. The plot also shows that different valves are used to change thetemperature depending on their position and if the output temperature is lower orhigher then the desired temperature. This is also shown in Appendix E Figure 2.The system reacts firstly by closing the cold valve due to the hot valve being fullyopened and the desired temperature being higher then the output. This confirmshow the system was designed in Section 3.3 Software and in the JSP in Appendix B.

The simulation shows the theroetical response of the system. The simulation ne-glects the thermal time constant of the LM35 and the computation speed of theArduino.

23

Page 39: Automated water mixer
Page 40: Automated water mixer

Chapter 5

Discussion and conclusions

5.1 Discussion

Since both the thermometers and the Arduino are very fast in comparison to bothhumans and to the rest of the system, their speed is neglected and it is assumedthat the system performs according to chapter 4 Results.

Since the performance of a human regulating the temperature is unknown, someassumptions about the speed of the system compared to the speed of a human haveto be made. Humans are very fast at turning the valves, but have no way of knowingwhat effects their actions will have on the temperature. A game of over and undercompensating begins where the final temperature is dialed in. When a disturbancein temperature occurs, the game begins all over. The system described in this thesiswould find the correct temperature on the first try, and if a disturbance appears itwould sense it and compensate for it immediately. This fact reduces energy loss andincreases showering comfort. The system also gives a clear indication through theLEDs when the water is at the set temperature. This reduces time spent waitingfor the shower to heat up.

As was stated in 1.5, Scope, the results are theoretical. The tests made were incontrolled conditions, and the final product was not tested with water. It is nottested how the parts interact, if any feedback loops are created or any other unfore-seen component interaction.

In practice, all parts have tolerances and do not always perform as they one wouldexpect in theory. The valves have some play in the thread, causing a number ofsteps to only move the slack, and not actually move the plug. The spur gears arealso a source for the same type of error. If the gears do not align perfectly, thedriven gear has to move before the gears touch. This error could either be reducedby compensating for it in the programming, buying better quality valves and gearsor can be accepted as within the margin of error.

25

Page 41: Automated water mixer

CHAPTER 5. DISCUSSION AND CONCLUSIONS

If the thermometer is not adequately isolated an error can occur. Thermal con-duction through the pipes can cause the thermometers to read an erroneous tem-perature.

Using this control system, the motors move with a constant angular velocity. An-other approach to this problem would be to use control theory. A proportional,derivative and integrating (PID) controller could be used. This method sets thevalve positions given the error between the output temperature and the set tem-perature. The controller then calculates the position of the valves and moves themotors.

5.2 ConclusionA self-regulating, fast shower mixer can be built using one LM35 temperature sen-sors, two stepper motors and two globe valves. All controlled by an Arduino Unowith the help of two stepper motor controllers.

Energy can be saved by reaching the correct temperature right away without hav-ing to change is several times, and showing the user when the set temperature isachieved. Exactly how much energy is saved requires additional research involvingtesting with people.

If the input temperatures are according to standard and the motors are allowedto spin at their maximum angular velocity, the system can theoretically changetemperature at a rate of 5,52 °C/s.

26

Page 42: Automated water mixer

Chapter 6

Recommendations and future work

As mentioned in section 1.5, Scope, the prototype is not constructed to fit the stan-dardised bathroom which will be a requirement for the future product. Therefore,the pipes for hot and cold water need to be reconstructed to be meet current stan-dards.

To increase the speed of the system, the motors are the largest bottleneck. Strongerstepper motors or servo motors would speed up the system significantly.

As mentioned in section 2.4, Thermometers, the LM35 temperature sensor hasan accuracy of 10 mV/°C. With the ADC in the Arduino this means a tempera-ture sensitivity of approximately 0,5°C. This is within the margins needed for thisproject, but with an amplifier the voltage can be raised to take advantage of the fullrange of the ADC. With an appropriate amplifier the temperature sensitivity couldbe around 0,25 °C. This would be a simple addition, if greater accuracy is needed.

Flow-rate or pressure sensors could be implemented to expand the functionalityof the product. In the current configuration it is assumed that the user alwayswants maximum flow-rate. This would require reading an additional three analoguevalues and programming appropriate actions depending on their values. The addedcomplexity may require a more powerful and/or larger microcontoller.

A waterproof case must be made for the device to be safe in a bathroom envi-ronment. The current configuration of parts could be rearranged to better fit insidea visually pleasing milled aluminium case.

At present the frame for the prototype is made from laser cut 3,5 mm acrylic andglued together. To make the product much cheaper it is proposed that 1 mm steelplate is used. The steel plate would be either water cut or stamped, and bent atright angles to make the frame.

27

Page 43: Automated water mixer
Page 44: Automated water mixer

Bibliography

[1] T. Lu, D. Attinger, and S.M. Liu. “Large-eddy simulations of velocity andtemperature fluctuations in hot and cold fluids mixing in a tee junction withan upstream straight or elbow main pipe”. eng. In: Nuclear Engineering andDesign 263 (2013), pp. 32–41. issn: 0029-5493. doi: 10.1016/j.nucengdes.2013.04.002.

[2] Machine Design. Which Motors Are the Best: Servos or Steppers? url: https://www.machinedesign.com/motion-control/which-motors-are-best-servos-or-steppers. (accessed: 30-04-2019).

[3] P.J. Siripala and Y. Ahmet Sekercioglu. “A generalised solution for generatingstepper motor speed profiles in real time”. eng. In: Mechatronics 23.5 (2013),pp. 541–547. issn: 0957-4158. doi: 10.1016/j.mechatronics.2013.04.004.

[4] Motion Controll tips. What are Stepper drivers and how do they work? url:https://www.motioncontroltips.com/faq-what-are-stepper-drives-and-how-do-they-work. (Accessed: 14-02-2019).

[5] Sam Sattel. How do microcontrollers work? url: https://www.autodesk.com/products/eagle/blog/how-microcontrollers-work/. (accessed: 26-05-2019).

[6] Arduino. Introduction to the Arduino Board. url: https://www.arduino.cc/en/reference/board. (Accessed: 14-02-2019).

[7] Andrea De Marcellis, Giuseppe Ferri, and Paolo Mantenuto. “A novel 6-decades fully-analog uncalibrated Wheatstone bridge-based resistive sensor in-terface”. eng. In: Sensors and Actuators B: Chemical 189 (2013), pp. 130–140.issn: 09254005. doi: http://dx.doi.org/10.1016/j.snb.2013.02.014.

[8] Wika. Temperature sensors. url: https://en.wika.com/landingpage_temperature_sensor_en_co.WIKA. (accessed: 14-02-2019).

[9] Capgo. Introduction to Semiconductor Temperature Sensors. url: http://www.capgo.com/Resources/Temperature/Semiconductor/Semi.html. (ac-cessed: 26-05-2019).

29

Page 45: Automated water mixer

BIBLIOGRAPHY

[10] Mitar Simic et al. “Multi-sensor system for remote environmental (air andwater) quality monitoring”. eng. In: 2016 24th Telecommunications Forum(TELFOR). IEEE, 2016, pp. 2–3. isbn: 9781509040865. doi: 10.1109/TELFOR.2016.7818711.

[11] Apollo International. Brittish Standard Pipe Thread. url: http : / / www .apollointernational.in/bsp-thread-chart.php. (accessed: 26-05-2019).

[12] Forbes Marshall. Types of Valves. url: https://www.forbesmarshall.com/fm_micro/news_room.aspx?Id=seg&nid=145. (accessed: 14-02-2019).

[13] S.K. Sreekala and S. Thirumalini. “Study of flow performance of a globe valveand design optimisation”. In: Journal of Engineering Science and Technology12.9 (2017), pp. 2403–2409. issn: 18234690.

[14] Globe Valve Diagram. 2009. url: https://sv.m.wikipedia.org/wiki/Fil:Globe_valve_diagram.svg. (accessed: 12-02-2019).

[15] Kjall Backman. Structured Programing with C++. eng. bookboon, 2012. isbn:978-87-403-0099-4.

[16] Tamagawa Seiko. 2-Phase Step Motors. url: https://www.tamagawa-seiki.com/products/stepmotor/2-phase-step.html. (accessed: 26-05-2019).

[17] Texas Instrumnets. LM35 Datasheet. url: http://www.ti.com/lit/ds/symlink/lm35.pdf. (accessed: 11-04-2019).

30

Page 46: Automated water mixer

Appendix A

Circuits

Figure A.1. The complete circuit. Figure made with Affinity Designer.

31

Page 47: Automated water mixer

APPENDIX A. CIRCUITS

Figure A.2. The circuit for the interface. Figure made with Affinity Designer.

Figure A.3. The circuit for one LM35. Figure made with Affinity Designer.

32

Page 48: Automated water mixer

Appendix B

JSP

Figure B.1. The JSP for the automated water mixer. Figure made with AffinityDesigner.

33

Page 49: Automated water mixer
Page 50: Automated water mixer

Appendix C

Source code

/∗∗The Arduino code to c o n t r o l the p o s i t i o n o f the s t epper motors∗∗Authors : Conradi , Justus and Tiainen , Patr ik∗ Pro j e c t name : Automatic water mixer∗Course : MF133X−Bache lors examination in mechatronics∗TRITA number : TRITA−ITM−EX 2019:55∗ Unive r s i ty : KTH−Royal I n s t i t u t e o f Technology .∗ Last modi f i ed : 2019−05−15.∗∗ Desc r ip t i on : This program uses the p o s i t i o n o f two potent iometer s to∗ s imulate the temperature o f two input p ipe s to a water mixer .∗ I t uses t h i s in fo rmat ion to move two s tepper motors∗ connected to two va lve s . The va lve s move u n t i l a∗ s e t temperature i s ach ieved .∗/

// input and output p ins

i n t s l e epho t = 13 ;i n t buttonplus = 3 ;i n t buttonminus = 4 ;i n t ye l low = 5 ;i n t green = 6 ;i n t red = 7 ;i n t s l e e p c o l d = 12 ;i n t d i rho t = 9 ;i n t s tephot = 11 ;i n t d i r c o l d = 8 ;

35

Page 51: Automated water mixer

APPENDIX C. SOURCE CODE

i n t s t epco ld = 10 ;i n t v o l t a g e i n t e r f a c e = 2 ;

i n t potenhot = A0 ;i n t potenco ld = A1 ;i n t thermoout = A5 ; // unused LM35

// D e c l a i r i n g v a r i a b l e s

f l o a t n r c o l d s t e p s ; //How many s t ep s the co ld water va lve has takenf l o a t n r h o t s t e p s ; //How many s t ep s the warm water va lve has taken// the temperature o f the waterf l o a t tempcold ;f l o a t temphot ;f l o a t tempout ;i n t targettemp = 25 ;// the temperature c o n t r o l l e d by the buttonsi n t l a s t b u t t o n s t a t e p l u s = 0 ;i n t l a s tbut tons ta t emin = 0 ;i n t temprange = 0 . 2 5 ;

f l o a t mc ;f l o a t mh;

f l o a t temperror ;

// cons tant s f o r making the code more reada lbe

i n t hotmotor = 1 ;i n t coldmotor = 2 ;f l o a t maxsteps = 200 ;i n t Open = 1 ;i n t Close = 2 ;

void setup ( ) { // The setup , runs once −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−// Inc lud ing l i b r a r i e s

#inc lude <math . h>

// s e t t i n g i n p u i t and output p inspinMode ( s l eephot , OUTPUT) ; // S leep 1pinMode ( buttonplus , INPUT) ; // i n c r e a s e targettemppinMode ( buttonminus , INPUT) ; // dec r ea s e targettemppinMode ( yel low , OUTPUT) ; // Yellow LEDpinMode ( green , OUTPUT) ; // Green LED

36

Page 52: Automated water mixer

pinMode ( red , OUTPUT) ; // Red LEDpinMode ( s l e epco ld , OUTPUT) ; // S leep 2pinMode ( dirhot , OUTPUT) ; // d i r e c t i o n 1pinMode ( d i r co ld , OUTPUT) ; // d i r e c t i o n 2pinMode ( s tepco ld , OUTPUT) ; // Stepp 2pinMode ( v o l t a g e i n t e r f a c e , OUTPUT) ; // Voltage f o r thermometerspinMode ( potenhot , INPUT) ; // the two potent iometer spinMode ( potencold , INPUT) ;pinMode ( thermoout , INPUT) ;

// Begin s e r i a l communicationS e r i a l . begin ( 9 6 0 0 ) ;

whi l e ( n r c o l d s t e p s <= maxsteps ) { // open the co ld va lve to 100%stepmotor (Open , coldmotor ) ;

d i g i t a l W r i t e ( yel low , HIGH) ;d i g i t a l W r i t e ( green , HIGH) ;d i g i t a l W r i t e ( red , HIGH) ;S e r i a l . p r i n t l n ( tempout ) ;S e r i a l . p r i n t l n ( targettemp ) ;

}

}

void loop ( ) { // The main program loop −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

d i g i t a l W r i t e ( v o l t a g e i n t e r f a c e , HIGH) ;// s e t t i n g pin 13 to always high , to supply the i n t e f a c e with power

d i g i t a l W r i t e ( s l eephot , LOW) ;// Turn on s l e e p on both motors whi l e they aren ’ t movingd i g i t a l W r i t e ( s l e epco ld , LOW) ;

readbuttons ( ) ;// read ing the pushbuttons and i n c r e a s i n g// dec r ea s ing the t a r g e t temperature .calctemp ( ) ;// Ca l cu l a t e s the output temperature depending on va lve p o s i t i o n and// input temperatures .

37

Page 53: Automated water mixer

APPENDIX C. SOURCE CODE

temperror = tempout − targettemp ;// Ca l cu l a t ing how f a r o f f the c o r r e c t temperature we arei f ( temperror > 0 .25 | | temperror < −0.25) {// The span in which the mixer should r e a c t

whi l e ( temperror > 0 && n r h o t s t e p s != 0 && n r c o l d s t e p s >= 200) {stepmotor ( Close , hotmotor ) ;readbuttons ( ) ;calctemp ( ) ;temperror = tempout − targettemp ;d i s p l e d ( ye l low ) ;S e r i a l . p r i n t l n ( tempout ) ;S e r i a l . p r i n t l n ( targettemp ) ;

}

whi le ( temperror < 0 && n r h o t s t e p s <= 200 ) {stepmotor (Open , hotmotor ) ;readbuttons ( ) ;calctemp ( ) ;temperror = tempout − targettemp ;d i s p l e d ( red ) ;S e r i a l . p r i n t l n ( tempout ) ;S e r i a l . p r i n t l n ( targettemp ) ;

}

whi le ( temperror < 0 && n r h o t s t e p s >= 200 && n r c o l d s t e p s != 0) {stepmotor ( Close , coldmotor ) ;readbuttons ( ) ;calctemp ( ) ;temperror = tempout − targettemp ;d i s p l e d ( red ) ;S e r i a l . p r i n t l n ( tempout ) ;S e r i a l . p r i n t l n ( targettemp ) ;

}

whi le ( temperror > 0 && n r h o t s t e p s >= 200 && n r c o l d s t e p s <= 200) {stepmotor (Open , coldmotor ) ;readbuttons ( ) ;calctemp ( ) ;temperror = tempout − targettemp ;d i s p l e d ( ye l low ) ;S e r i a l . p r i n t l n ( tempout ) ;S e r i a l . p r i n t l n ( targettemp ) ;

38

Page 54: Automated water mixer

}d i s p l e d ( green ) ;

}S e r i a l . p r i n t l n ( tempout ) ;

S e r i a l . p r i n t l n ( targettemp ) ;

i f ( d i g i t a lRead ( buttonplus ) && dig i ta lRead ( buttonminus ) ) {c l o s e a l l ( ) ;

}

S e r i a l . p r i n t l n ( tempout ) ;S e r i a l . p r i n t l n ( targettemp ) ;

}

// Functions −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

i n t stepmotor ( i n t d ir , i n t motor ) { //A func t i on that s t ep s a motor .// Inputs are what d i r e c t i o n and what motor to s tep .

i f ( motor == hotmotor ) {i f ( d i r == Open) {

d i g i t a l W r i t e ( s l eephot , HIGH) ;d i g i t a l W r i t e ( d i rho t , HIGH) ;

d i g i t a l W r i t e ( s tephot , HIGH) ;de lay ( 2 5 ) ; // The speed o f the motord i g i t a l W r i t e ( s tephot , LOW) ;de lay ( 2 5 ) ;r e turn n r h o t s t e p s ++;

}e l s e i f ( d i r == Close ) {

d i g i t a l W r i t e ( s l eephot , HIGH) ;d i g i t a l W r i t e ( d i rho t , LOW) ;

d i g i t a l W r i t e ( s tephot , HIGH) ;de lay ( 2 5 ) ;d i g i t a l W r i t e ( s tephot , LOW) ;de lay ( 2 5 ) ;

39

Page 55: Automated water mixer

APPENDIX C. SOURCE CODE

re turn nr ho t s t ep s −−;}

}e l s e i f ( motor == coldmotor ) {

i f ( d i r == Open) {

d i g i t a l W r i t e ( s l e epco ld , HIGH) ;d i g i t a l W r i t e ( d i r c o l d , HIGH) ;

d i g i t a l W r i t e ( s t epco ld , HIGH) ;de lay ( 2 5 ) ;d i g i t a l W r i t e ( s t epco ld , LOW) ;de lay ( 2 5 ) ;r e turn n r c o l d s t e p s ++;

}e l s e i f ( d i r == Close ) {

d i g i t a l W r i t e ( s l e epco ld , HIGH) ;d i g i t a l W r i t e ( d i r c o l d , LOW) ;

d i g i t a l W r i t e ( s t epco ld , HIGH) ;de lay ( 2 5 ) ;d i g i t a l W r i t e ( s t epco ld , LOW) ;de lay ( 2 5 ) ;r e turn n r c o l d s t e p s −−;

}}

}

void readbuttons ( ) {// A func i t on to change the t a r g e t temperature us ing two buttons

i n t but tons ta t ep lu s = d ig i t a lRead ( buttonplus ) ;i n t buttonstatemin = d ig i ta lRead ( buttonminus ) ;

i f ( bu t tons ta t ep lu s != l a s t b u t t o n s t a t e p l u s && targettemp < temphot + 1 ) {i f ( bu t tons ta t ep lu s == HIGH) {

targettemp++;

}

}l a s t b u t t o n s t a t e p l u s = but tons ta t ep lu s ;

40

Page 56: Automated water mixer

i f ( buttonstatemin != la s tbut tons ta t emin && targettemp > tempcold − 1) {i f ( buttonstatemin == HIGH) {

targettemp−−;}

}l a s t b u t t o n s t a t e p l u s = but tons ta t ep lu s ;l a s tbut tons ta t emin = buttonstatemin ;

}

f l o a t calctemp ( ) {// A func t i on to c a l c u l a t e the outgoing temperature dependign on// the p o s i t i o n s o f the va lve s and temperatures o f the// potent iometer s

f l o a t Vin0 = analogRead ( potenhot ) ;f l o a t Vin1 = analogRead ( potenco ld ) ;

// reads temperatures o f the input p ipe stempcold = Vin0 ∗ 0 .488 / 50 ;temphot = 40 + Vin1 ∗ 0 .488 / 15 ;

// Adjust ing the input vo l tage to r e p r e s en t a temperature

mc = n r c o l d s t e p s / maxsteps ;mh = n r h o t s t e p s / maxsteps ;// c a l c u l a t i n g the percentage o f mass f low o f the r e s p e c t i v e va lve s

tempout = ( tempcold ∗ mc + temphot ∗ mh) / (mc + mh) ;// Ca l cu l a t ing the output temperature based on mass f low and temperaturere turn tempout ;

}

void c l o s e a l l ( ) {// Closes both va lve s to t h e i r s t a r t i n g pos

whi l e ( n r c o l d s t e p s > 0) {stepmotor ( Close , coldmotor ) ;S e r i a l . p r i n t l n ( n r c o l d s t e p s ) ;

}

41

Page 57: Automated water mixer

APPENDIX C. SOURCE CODE

whi le ( n r h o t s t e p s > 0) {stepmotor ( Close , hotmotor ) ;S e r i a l . p r i n t l n ( n r h o t s t e p s ) ;

}

}

void d i s p l e d ( i n t c o l ) {// l i g h t i n g an LED with ” c o l ” as input

i f ( c o l == green ) {// Disp lay ing a green LED i f temperature i s with in range

d i g i t a l W r i t e ( green , HIGH) ;d i g i t a l W r i t e ( ye l low , LOW) ;d i g i t a l W r i t e ( red , LOW) ;

}e l s e i f ( c o l == red ) {// Disp lay ing a red LED i f temperature i s hot

d i g i t a l W r i t e ( green , LOW) ;d i g i t a l W r i t e ( ye l low , LOW) ;d i g i t a l W r i t e ( red , HIGH) ;

}e l s e i f ( c o l == ye l low ) {// Disp lay ing a red LED i f temperature i s co ld

d i g i t a l W r i t e ( green , LOW) ;d i g i t a l W r i t e ( ye l low , HIGH) ;d i g i t a l W r i t e ( red , LOW) ;

}

}

42

Page 58: Automated water mixer

Appendix D

Thermometer results

Figure D.1. A selection of tests conducted on LM35. Graphs made in MatLab.

43

Page 59: Automated water mixer
Page 60: Automated water mixer

Appendix E

Software trials

Figure E.1. Simulated response due to change in the input water temperature.Graphs made in MatLab.

45

Page 61: Automated water mixer

APPENDIX E. SOFTWARE TRIALS

Figure E.2. Simulated response due to change in desired temperature. Graphsmade in MatLab.

46

Page 62: Automated water mixer

TRITA TRITA-ITM-EX 2019:55

www.kth.se