7
+ Herbert Jaeger ALPhA Immersion Workshop July 27 – 29, 2017 Department of Physics Indiana University – Purdue University Ft. Wayne, Indiana All Rights Reserved by the Author 2017 Harnessing the Power of Arduino for the Advanced Lab (Final Version)

Arduino Workshop 2017-Rev2 - Manchester University...30 SUMMER 2017 Figure 1: Circuit diagram for the thermistor. Since the Arduino’s analog input can only handle postive voltages,

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Arduino Workshop 2017-Rev2 - Manchester University...30 SUMMER 2017 Figure 1: Circuit diagram for the thermistor. Since the Arduino’s analog input can only handle postive voltages,

P

P

+

–Herbert Jaeger

ALPhA Immersion Workshop July 27 – 29, 2017 Department of Physics Indiana University – Purdue University Ft. Wayne, Indiana

All Rights Reserved by the Author 2017

Harnessing the Power of Arduino for the Advanced Lab (Final Version)

Page 2: Arduino Workshop 2017-Rev2 - Manchester University...30 SUMMER 2017 Figure 1: Circuit diagram for the thermistor. Since the Arduino’s analog input can only handle postive voltages,

SUMMER201729

ARDUINOCONTROLSTHETEMPERATURE

Objectives 1.ToconstructanelectronicthermometerusingathermistorasthesensorandtheArduinoasthemicrocontroller.

2.Tousethethermistorthermometerasthefeedbackelementinatemperaturecontroller.

BackgroundThe resistance of a metal wire changes with temperature. Knowing how the resistancechanges with temperature, the wire can be used to measure temperature by relatingtemperature to resistance. Platinumwire is particularly useful as a temperature-sensitiveelement in a thermometerbecause it is very stable andhas ahighmeltingpointof around1770˚C. However, thermometers made frommetals have the disadvantage of being ratherinsensitive.Forexample,theresistanceofaplatinumwirechangesbyabout30%fora100˚Ctemperaturechange.

Theresistanceofasemiconductorsuchasthesiliconusedinasolidstatediodeoratransistorchangesappreciably,evenwithsmalltemperaturechanges.Forthisreason,semiconductorsmake sensitive temperature sensors. A device employing a semiconducting material as atemperature sensor is called a thermistor. The resistance of a commercial thermistormaychangebyafactorof100ifitstemperaturechangesby100˚C.

Fromtheoreticalconsiderationsandexperienceit isknownthattheresistanceRthermistorofathermistorisrelatedtotheabsoultetemperature,T,by

(1)

whereAandBareconstantscharacteristicofagiventhermistor.ThecircuitshowninFigure1isusedtorelatethethermistorresistancetoavoltagefortheArduinomicrocontroller.Thevoltageattheoutputofthefirstop-ampisrelatedtothepotentiometervoltageby

(2)

Rthermistor = A eBT

Vout = −RthermistorR

Vpot

Page 3: Arduino Workshop 2017-Rev2 - Manchester University...30 SUMMER 2017 Figure 1: Circuit diagram for the thermistor. Since the Arduino’s analog input can only handle postive voltages,

30 SUMMER2017

Figure1:Circuitdiagramforthethermistor.

Since the Arduino’s analog input can only handle postive voltages,Vpotmust be a negativevoltage.TheexactvalueofVpotwilldependonthetermistorresistanceandyourchoiceofthevalue forR. ForagivenchoiceofRandaconstantadjustmentof thepotoutputvoltage isproportionaltothethermistorresistance,Rthermistorintheop-amp’sfeedback.Heretheop-ampfunctionsasanohmmeter.Thesecondop-ampactsasavoltagefollowerandisusedtoavoidloadingtheanaloginputoftheArduino.

The resistance of the thermistor decreases as temperature increases. Accordingly, themagnitude of the output voltage of the circuit decreases as temperature increases. In thisexercise we are interested in temperatures between room temperature and 100˚C. If wechooseRequaltothethermistorresistanceatroomtemperaturethenthemagnitudeoftheoutputattemperaturesaboveroomtemperaturewillalwaysbelessthanVpot.

ThethermistorresistanceisgivenbyR=AeB/Tandtheoutputvoltageisproportionaltothethermistorresistance.Accordingly,theoutputvoltagecanbewritten

(3)

TheconstantsCandBmustbedeterminedbycalibration.ThentheabsolutetemperaturecanbecalculateduponmeasuringVout.

CalibrationofthethermistorthermometerQualitycontrolinthemanufactureofthermistorsissuchthatallthermistorsofagiventypewillnothavethesamevaluesofCandB.ItisuptotheusertodetermineCandBexperimen-tally.Inprinciple,twomeasurementsofvoltageandtemperaturesufficetodetermineCandB.Amoresatisfactorytechnique is torecordmeasurementsofvoltageandtemperature inthetemperaturerangeofinterestandfitthetheoreticalexpressiontothedata.Fittingisgreatly

–+

R

–+

Rthermistor–12V

10kArduino !Analog Input

2

3

6

2

36

1

2

12

7

610

black: 741 pinsred: 747 pins

Vout = CeBT

Page 4: Arduino Workshop 2017-Rev2 - Manchester University...30 SUMMER 2017 Figure 1: Circuit diagram for the thermistor. Since the Arduino’s analog input can only handle postive voltages,

SUMMER201731

simplifiedifthedataaredescribedbyastraightlinerelationship.AgraphofVoutversusTforthe thermistor function is not a straight line but we can "linearize" the exponentialrelationshipbetweenVoandTbytakingthenaturallogarithmofbothsidesoftheequation

(4)

PerformingmeasurementsofVoutandTandplottinglnVoutversus1Twillproduceastraight

linewithslopeBand intercept lnC. Youwilluse the linearregression function(LINEST)ofExceltodetermineslope,intercept,andtheiruncertainties.

Thethermistorissealedinthebottomofaglassorplastictubeabout1/4"indiameterand10" long. Electrical connections aremade to the thermistor by flexible leads entering theopenendofthetube.ConnectthethermistortothecircuitasshowninFigure1.ChooseRandVpottoproduceanoutputvoltagejustunder5Vatroomtemperature.Sincetheresistanceofthethermistordecreaseswith increasingtemperature, thiswillbe themaximumvoltage. Inthisexerciseyouwillbeusingatemperaturerangefromroomtemperature(about20˚C)toabout100˚C.BeforeyouconnecttheoutputottheArduinotestyourcircuitbytouchingthethermistor.Asitwarmsuptheoutputvoltageofyourcircuitshoulddrop.

After you convinced yourself that your circuit works the next step is to calibrate thethermistor by determining the relationship between voltage and temperature. Place athermometerandthethermistorprobeintoabeakerofwaterandplacethebeakeronahotplate. Make a series ofmeasurements of temperature and output voltage, Vout, from roomtemperature to theboilingpointofwater. It isvery important to stir thewaterduring thecalibration,andtohavethethermistorandthermometertiedtogethersoyouactuallyknowthat thermistor and thermometer are exposed to the same temperature. Record themeasurements ina spreadsheetasyouproceed. In thespreadsheet,plot lnVoutversus 1/T,whereTistheabsolutetemperature.Performalinearfit(LINEST)tothedataandrecordtheslopeandintercept;youwillneedthisforthetemperaturecontrollerinthenextpart.

TemperatureControllerSupposeyouhadajarofwateronastove,athermometertomeasurethewatertemperature,andwantedtomaintainthetemperatureat60±2˚C.Youwouldturnthestoveon,watchthethermometer,andshutitoffwhenthetemperaturereadscloseto60˚C.Whenthewatercoolsand the temperature falls below 60˚C, you would turn the stove on. In this exercise amicrocontroller(theArduino)will“watch”thetemperatureviathethermistorandwillturnaheateronoroffinordertomaintainaconstantwatertemperature.

lnVout = lnC +BT

Page 5: Arduino Workshop 2017-Rev2 - Manchester University...30 SUMMER 2017 Figure 1: Circuit diagram for the thermistor. Since the Arduino’s analog input can only handle postive voltages,

32 SUMMER2017

Figure2:The switch circuit for the temperature controller. Componentdiagram (top) and equivalent circuit diagram (bottom). Thecomponents inside thedashedboxare in theblueboxwith theoutletonyourlabstation.

Digital!Output

Immersion! Heater

Solid-State!Relay

to 120VAC!Power Outlet

If digital output = LOW switch is open!If digital output = HIGH switch is closed

to Arduino! GND! !Digital!Output

AC Power!120 VAC

Immersion !Heater

Solid-State Relay

Switched!Power!Outlet

Page 6: Arduino Workshop 2017-Rev2 - Manchester University...30 SUMMER 2017 Figure 1: Circuit diagram for the thermistor. Since the Arduino’s analog input can only handle postive voltages,

SUMMER201733

The actual switching is done by a relay. A relay is an electro-mechanical switch that isoperatedbyapplyingasmallvoltage to the input terminals. Acurrent flows throughacoilandattractsanironleverwhichinturnclosesanelectricalswitch.Wewillbeusingasimilardevicecalledasolid-staterelay;itperformsthesameaction,butentirelywithoutanymovingparts,justviasemiconductorelectronics.Thesolid-staterelayhastwoterminalstowhichthevoltageisappliedandtwoterminalsthatconstitutetheswitch.Forexample,when3to5Visapplied to the input the switch is ON, i.e. the “switch contacts” are closed. If 0 to 0.5 V isappliedtheswitchisOFF,i.e.the“switchcontacts”areopen.ThecontrolvoltageisDC,sothepolarityoftheappliedvoltagemattersgreatly.Figure2showstheswitchcircuitry.WiththecircuitinFigure1stillconnectedtotheArduino,wenowhavetoconnectthedigitaloutputofthe Arduino to the switch circuit of Figure 2. The digital output is connected to the redterminal and theArduino’s ground to theblack terminal. When theoutput goesHIGH, therelayswitchclosesandturnson the immersionheater. WhenthedigitaloutputgoesLOW,theswitchopensandtheimmersionheateristurnedoff.

NextyouneedtoprogramasketchtohavetheArduinomonitorthethermistoranddecideiftherelayswitchneedstobeonoroff.Herearethestepstoyoutoprogram:

o Readapotviaanaloginput(thesetpoint,Tset)o Readthethermistorviaanaloginput(thewatertemperature,T)o ComparesetpointTsetandwatertemperatureTo IfT<TsetsetdigitaloutputHIGHo IfT>TsetsetdigitaloutputLOWo Repeat

Aspartofthesketchyouwillneedtoconverttheoutputvoltagetoanactualtemperature.ItisforthisstepthatyouwillneedthecalibrationconstantsCandBfromtheprevioussection.

Now that youhave all yourducks in a row, it is time to see if your temperature controllerworksasadvertised.Plugtheimmersionheaterintotheswitchedoutlet(theoneintheblueboxonyourlabstation),andplacethermistorandimmersionheaterinabeakerofwater.Becareful that the thermistor does not touch the heater directly. You also need to add thethermometer so you can see if the controllermaintains the correct temperature. Once therelayturnstheheateron,thetemperaturewillrise.Whenitreachesthesetpointtemperaturethe controller will turn the heater off. Be patient, it will take some time for the watertemperature to react to the heater. After 10-20 minutes you should have some sort ofequilibrium. Carefully observe and note how high and low the temperature gets as thecontrollercyclesonandoff.

Page 7: Arduino Workshop 2017-Rev2 - Manchester University...30 SUMMER 2017 Figure 1: Circuit diagram for the thermistor. Since the Arduino’s analog input can only handle postive voltages,