Tải bản đầy đủ - 0 (trang)
The Midterm Project – a Portable DIY Thermostat

The Midterm Project – a Portable DIY Thermostat

Tải bản đầy đủ - 0trang

Chapter7.TheMidtermProject–a

PortableDIYThermostat

AfterthefirstPython-Arduinoproject,youlearnedtheprocessofprototypingvarious

sensors,developinguserinterfaces,andplottingsensordata.Theconceptsthatyou

learnedinthepreviouschapterscanbeutilizedtocreateawidevarietyofArduino-based

hardwareprojects.Theinceptionofagoodapplicationconceptalwaysbeginswitharealworldnecessityandendsupasapracticalprojectifitisexecutedproperly.Inthischapter,

wewilldemonstratethisproject-buildingprocesswithanexampleofaportablesensor

unit.Asyoucanestimatefromthechaptertitle,wewillbebuildingasimpleandportable

DIYthermostatthatcanbedeployedwithoutadesktopcomputeroralaptop.

Tobeginwith,wewilldescribetheproposedthermostatwithspecificgoalsandprocesses

toachievethem.Oncethestrategytoachievethesegoalshasbeenlaiddown,youwillbe

introducedtothetwosuccessiveprogrammingstagestodevelopthedeployableand

portableunit.Inthefirststage,wewillutilizeatraditionalcomputertosuccessfully

developtheprogramtointerfaceArduinowithPython.Inthesecondstage,wewill

replacethiscomputerwithaRaspberryPitomakeitportableanddeployable.



Thermostat–theprojectdescription

Fromthemultipleprojectsthatwecanbuildusingthethingsthatyoulearned,aproject

thathelpsyoutomonitoryoursurroundingenvironmentreallystandsoutasanimportant

real-worldapplication.Fromthevariousenvironment-monitoringprojectssuchasweather

station,thermostat,andplantmonitoringsystem,wewillbedevelopingthethermostatas

itfocusesonindoorenvironmentandcanbepartofyourdailyroutine.

Thethermostatisoneofthemostimportantcomponentsofanyremotehomemonitoring

systemandhomeautomationsystem.Apopularcommercialexampleofaconnected

thermostatistheNestThermostat(https://www.nest.com),whichprovidesintelligent

remotemonitoringandschedulingfeaturesforyourexistinghome’sheatingandcooling

system.Beforewethinkaboutafull-stackproductsuchasNest,weneedfirstneedto

buildaDIYthermostatwiththebasicsetoffeatures.Later,wecanbuilduponthisproject

byaddingfeaturestoimprovetheDIYthermostatexperience.Let’sfirstoutlinethe

featuresthatweareplanningtoimplementinthisversionofthethermostatproject.



Projectbackground

Temperature,humidity,andambientlightarethethreemainphysicalcharacteristicsthat

wewanttomonitorusingthethermostat.Intermsofuserexperience,wewanttohavean

elegantuserinterfacetodisplaythemeasuredsensordata.Theuserexperiencecanbe

moreresourcefulifanyofthissensordataisplottedasalinegraph.Inthecaseofa

thermostat,thevisualrepresentationofthesensordataprovidesamoremeaningful

comprehensionoftheenvironmentthanjustdisplayingplainnumericalvalues.

Oneofthemajorobjectivesoftheprojectistomakethethermostatportableand

deployablesothatitcanbeusedinyourday-to-daylife.Tosatisfythisrequirement,the

thermostatdisplayneedstobechangedfromaregularmonitortosomethingsmalland

moreportable.Toensureitsreal-worldandmeaningfulapplication,thethermostatshould

demonstratereal-timeoperation.

Itisimportanttonotethatthethermostatwillnotbeinterfacingwithanyactuatorssuchas

homecoolingandheatingsystems.Astheinterfacingofthesesystemswiththethermostat

projectrequireshigh-levelunderstandingandexperienceofworkingwithheatingand

coolingsystems,itwilldeviatetheflowofthechapterfromitsoriginalgoalofteaching

youArduinoandPythonprogramming.



Projectgoalsandstages

Inordertodescribethefeaturesthatwewanttohaveinthethermostat,let’sfirstidentify

thegoalsandmilestonestoachievetheseobjectives.Themajorgoalsfortheprojectcan

bedeterminedasfollows:

Identifythenecessarysensorsandhardwarecomponentsfortheproject

Designandassemblethecircuitforthethermostatusingthesesensorsandthe

Arduinoboard

Designaneffectiveuserexperienceanddevelopsoftwaretoaccommodatetheuser

experience

Developandimplementcodetointerfacethedesignedhardwarewiththesoftware

components

Thecodedevelopmentprocessofthethermostatprojectisdividedintotwomajorstages.

Theobjectivesofthefirststageincludesensorinterfacing,thedevelopmentofthe

Arduinosketch,andthedevelopmentofthePythoncodeonyourregularcomputerthat

youhavebeenusingallalong.Thecodingmilestoneforthefirststagecanbefurther

distributedasfollows:

DeveloptheArduinosketchtointerfacesensorsandbuttonswhileprovidingoutput

ofthesensordatatothePythonprogramviatheserialport

DevelopthePythoncodetoobtainsensordatafromtheserialportusingthe

pySeriallibraryanddisplaythedatausingGUIthatisdesignedinTkinter

Createaplottodemonstratethereal-timehumidityreadingsusingthematplotlib

library

Inthesecondstage,wewillattachtheArduinohardwaretoasingle-boardcomputeranda

miniaturedisplaytomakeitmobileanddeployable.Themilestonetoachieveobjectiveof

thesecondstageareasfollows:

Installandconfigureasingle-boardcomputer,RaspberryPi,torunthePythoncode

fromthefirststage

InterfaceandconfiguretheminiaturescreenwiththeRaspberryPi

OptimizetheGUIandplotwindowtoadjusttothissmallscreen’sresolution

Inthefollowingsubsectionofthissection,youwillbenotifiedaboutthelistofrequired

componentsforboththestages,followedbythehardwarecircuitdesignandthesoftware

flowdesign.Theprogrammingexercisesforthesestagesareexplainedinthenexttwo

sectionsofthechapter.



Thelistofrequiredcomponents

Insteadofgoingthroughtheprocessofidentifyingtherequiredcomponents,wehave

alreadyselectedthecomponentsforthisprojectbasedontheirutilizationintheprevious

exercises,easeofuse,andavailability.Youcanreplacethesecomponentsaccordingto

theiravailabilityatthetimeyouarebuildingthisprojectoryourfamiliaritywithother

sensors.Justmakesurethatyoutakecareofmodificationsinthecircuitconnectionsand

code,ifthesenewcomponentsarenotcompatiblewiththeonesthatweareusing.

Inthefirststageofprototyping,wewillneedcomponentstodeveloptheelectroniccircuit

forthethermostatunit.Aswementionedearlier,wearegoingtomeasuretemperature,

humidity,andambientlightthroughourunit.Wealreadylearnedaboutthetemperature

sensorTMP102andtheambientlightsensorBH1750inChapter4,DivingintoPythonArduinoPrototyping.Wewillbeusingthesesensorsforthisprojectwiththehumidity

sensorHIH-4030.TheprojectwillutilizethesameArduinoUnoboardthatyouhavebeen

usingthroughoutthepreviouschapterswiththenecessarycables.Wewillalsoneedtwo

pushbuttonstoprovidemanualinputstotheunit.Thesummaryoftherequired

componentsforthefirststageisprovidedinthefollowingtable:

Component(firststage)



Quantity



Website



ArduinoUno



1



https://www.sparkfun.com/products/11021



USBcableforArduino



1



https://www.sparkfun.com/products/512



Breadboard



1



https://www.sparkfun.com/products/9567



TMP102temperaturesensor 1



https://www.sparkfun.com/products/11931



HIH-4030humiditysensor



https://www.sparkfun.com/products/9569



1



BH1750ambientlightsensor 1



http://www.robotshop.com/en/dfrobot-light-sensor-bh1750.html



Pushbuttonswitch



2



https://www.sparkfun.com/products/97



1kilo-ohmresistor



2







10kilo-ohmresistor



2







Connectionwires



Asrequired



Althoughthetableprovideslinksforfewspecificwebsite,youcanobtainthese

componentsfromyourpreferredproviders.ThetwomajorcomponentsHIH-4030

humiditysensorandpushbuttonswitchthatwehaven’tusedpreviouslyaredescribedas

follows:

HIH-4030humiditysensor:Thismeasuresandprovidesrelativehumidityresultsas

ananalogoutput.Theoutputofthesensorcanbedirectlyconnectedtoanyanalog

pinofArduino.ThefollowingimageshowsthebreakoutboardwiththeHIH-4030



sensorthatissoldbySparkFunElectronics.YoucanlearnmoreabouttheHIH-4030

sensorfromitsdatasheet,whichcanbeobtainedfrom

https://www.sparkfun.com/datasheets/Sensors/Weather/SEN-09569-HIH-4030datasheet.pdf:



Pushbuttonswitch:Pushbuttonswitchesaresmallswitchesthatcanbeusedona

breadboard.Whenpressed,theswitchoutputchangesitsstatustoHIGH,whichis

LOWotherwise.



Inthesecondstage,wearegoingtomakethesensorunitmobilebyreplacingyour

computerwithaRaspberryPi.Forthat,youwillneedthefollowingcomponentstoget

started:

Component(secondstage)



Quantity Image



RaspberryPi



1



https://www.sparkfun.com/products/11546



MicroUSBcablewithapower

adapter



1



http://www.amazon.com/CanaKit-Raspberry-Supply-AdapterCharger/dp/B00GF9T3I0/



8GBSDcard



1



https://www.sparkfun.com/products/12998



TFTLCDscreen



1



http://www.amazon.com/gp/product/B00GASHVDU/



AUSBhub



Optional



Furtherexplanationsofthesecomponentsareprovidedlaterinthechapter.



Hardwaredesign

Theentirehardwarearchitectureofthethermostatcanbedividedintotwounits,a

physicalworldinterfacingunitandacomputationunit.Thephysicalworldinterfacing

unit,asitsnameindicates,monitorsphenomenonofthephysicalworldsuchas

temperature,humidity,andambientlightusingsensorsconnectedtotheArduinoboard.

Thephysicalworldinterfacingunitisinterchangeablymentionedasthethermostatsensor

unitthroughoutthechapter.Thecomputationalunitisresponsiblefordisplayingthe

sensorinformationviatheGUIandplots.

Thefollowingdiagramshowsthehardwarecomponentsforthefirststagewherethe

thermostatsensorunitisconnectedtoacomputerusingtheUSBport.Inthethermostat

sensorunit,varioussensorcomponentsareconnectedtotheArduinoboardusingI2C,

analog,anddigitalpins:



Inthesecondprogrammingstagewherewearegoingmakeourthermostatintoamobile

anddeployableunit,youwillbeusingasingle-boardcomputer,RaspberryPi,asthe

computationaldevice.Inthisstage,wewilluseaminiaturethin-filmtransistorliquidcrystaldisplay(TFTLCD)screenthatisconnectedtoaRaspberryPiviageneralpurposeinput/output(GPIO)pinsandisusedasadisplayunittoreplacethetraditional

monitororlaptopscreen.Thefollowingdiagramshowsthisnewthermostatcomputational

unit,whichtrulyreducestheoverallsizeofthethermostatandmakesitportableand

mobile.CircuitconnectionsfortheArduinoboardareunchangedforthisstageandwe

willusethesamehardwarewithoutanymajormodifications.



Asthecommonunitforbothstagesoftheproject,theArduino-centricthermostatsensor

unitrequiresslightlymorecomplexcircuitconnectionscomparedtootherexercisesthat

youhavebeenthrough.Inthissection,wearegoingtointerfacethenecessarysensorsand

pushbuttonstotheirrespectivepinsontheArduinoboardandyouwillneedabreadboard

tomaketheseconnections.IfyouarefamiliarwithPCBprototyping,youcancreateyour

ownPCBboardbysolderingthesecomponentsandavoidthebreadboard.PCBboardsare

morerobustcomparedtobreadboardsandlesspronetolooseconnections.Usethe

followinginstructionsandtheFritzingdiagramtocompletethecircuitconnections:

1. Asyoucanseeinthefollowingdiagram,connecttheSDAandSCLpinsofTMP102

andBH1750toanalogpins4and5oftheArduinoboardandcreateanI2Cbus.To

maketheseconnections,youcanusemultiplecolor-codedwirestosimplifythe

debuggingprocess.

2. Usetwo10kilo-ohmpull-upresistorswiththeSDAandSCLlines.

3. ContrarytotheseI2Csensors,theHIH-4030humiditysensorisasimpleanalog

sensorandcanbedirectlyconnectedtotheanalogpin.ConnecttheHIH-4030tothe

analogpinA0.

4. ConnectVCCandthegroundofTMP102,BH1750,andHIH-4030to+5Vandthe

groundoftheArduinoboardusingpowerstripsofthebreadboard,asdisplayedinthe

diagram.Werecommendthatyouuseredandblackwirestorepresentthe+5Vand

groundlinesrespectively.

5. ThepushbuttonprovidestheoutputasHIGHorLOWstateandinterfacedusing

digitalpins.Asdisplayedinthecircuit,connectthesepushbuttonstodigitalpins2

and3usingtwo1kilo-ohmresistors.

6. Completetheremainingconnectionsasdisplayedinthefollowingdiagram.Make



surethatyouhavefirmlyconnectedallthewiresbeforepoweringuptheArduino

board:



Note

MakesurethatyoualwaysdisconnectyourArduinoboardfromthepowersourceora

USBportbeforemakinganyconnections.Thiswillpreventanydamagetotheboarddue

toshortcircuiting.

Completealltheconnectionsforthethermostatsensorunitbeforeheadingtothenext

section.Asthisunitisbeingusedinboththeprogrammingstages,youwon’tbe

performinganyfurtherchangestothethermostatsensorunit.



Softwareflowforuserexperiencedesign

Oneofthecriticalcomponentsofanyprojectisitsusabilityoraccessibility.Whenyouare

workingonmakingyourprojectprototypeintoaproduct,itisnecessarytohavean

intuitiveandresourcefuluserinterfacesothattheusercaneasilyinteractwithyour

product.Hence,itisnecessarytodefinetheuserexperienceandsoftwareflowofaproject

beforeyoustartcoding.Thesoftwareflowincludestheflowchartandthelogical

componentsoftheprogramthatarederivedfromtheprojectrequirements.Accordingto

thegoalsthatwehavedefinedforthethermostatproject,thesoftwareflowcanbe

demonstratedinthefollowingdiagram:



Intheimplementation,thesoftwareflowoftheprojectbeginsbymeasuringthe

temperature,humidity,andambientlightfromArduinoandprintingthemonaserialport



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

The Midterm Project – a Portable DIY Thermostat

Tải bản đầy đủ ngay(0 tr)

×