Sensors and Actuators with Arduino

advertisement
SensorsandActuators
withArduino
Hans-PetterHalvorsen,M.Sc.
SystemOverview
NTCThermistor
Arduino
Download Code
Computer
TMP36
Pt-100
Sensors(Input)
Actuators(Output)
Examples:
PushButton
Programming
Cloud
LED
Sound
DataLogging
LabTopics
• GetOverviewoftheArduinoPlatform
• SensorsandActuatorsOverviewingeneral
• OverviewofTemperatureSensors,suchas
- Pt-100,Thermistor,Thermocouple
•
•
•
•
•
BasicDataAcquisition(DAQ),DataLogging
Calibration,Uncertainty,Resolution,Accuracy,Range,etc.
LowpassFilterimplementationinSoftware
NetworkCommunication
ReadingData sheets
AssignmentOverview
1. ArduinoBasics:ExplorethedifferentSensorsandActuators
availablewiththeArduinoKit
2. TemperatureSensors
3. Pt-100:CreateyourownPt-100sensorwithTransmitterfrom
scratchandReadTemperaturevaluesusingArduino
4. CreateaTemperatureDataLogger/EmbeddedDAQSystem.
Selectone ofthefollowingalternatives:
a) SaveDatausingSDCardavailableonArduinoShields
b) Useanonlineweb-basedDataLoggingServicelikeTemboo/Xively
c) UseWirelessCommunicationtoyourPCusingXBeeModules
Seenextslidesfordetails...
Arduino
Arduino SketchIDE
Software
Software
Programming withArduino issimpleandintuitive!
Example:
// include the TinkerKit library
#include <TinkerKit.h>
// creating the object 'led' that belongs to the 'TKLed' class
TKLed led(O0);
void setup()
{
}
void loop()
{
led.on();
delay(1000);
led.off();
delay(1000);
}
ThesyntaxissimiliartoCprogramming
//do something here
//
//
//
//
set the LED on
wait for a second
set the LED off
wait for a second
ThisprogrammakesaLEDblink
SoftwareInstallation:http://arduino.cc/en/Main/Software
Arduino UNODevice
Hardware
Hardware
Breadboard
Pt-100
Tools
SensorsandActuators
Pt-100Transmitter
Multimeter
SensorsandActuators
Theory
• ASensor isaconverterthatmeasuresaphysicalquantityand
convertsitintoasignalwhichcanbereadbyanobserverorby
an(todaymostlyelectronic)instrument.
• AnActuator isatypeofmotorformovingorcontrollinga
mechanismorsystem.Itisoperatedbyasourceofenergy,
typicallyelectriccurrent,hydraulicfluidpressure,orpneumatic
pressure,andconvertsthatenergyintomotion.Anactuatoris
themechanismbywhichacontrolsystemactsuponan
environment.
http://en.wikipedia.org/wiki/Sensor
http://en.wikipedia.org/wiki/Actuator
Sensors
Calibration:Acomparisonbetweenmeasurements.Oneof
known magnitudeorcorrectnessmadeorsetwithonedevice
andanothermeasurementmadeinassimilarawayaspossible
withaseconddevice.Thedevicewiththeknown orassigned
correctnessiscalledthestandard.Theseconddeviceistheunit
undertest,testinstrument,oranyofseveralothernamesfor
thedevicebeingcalibrated.
Theory
Accuracy:Howclosethe
measuredvalueisthethe
actual/realvalue,eg.,±0.1%
Resolution:Thesmallestchangeitcandetectinthe
quantitythatitismeasuring.Thefollowigformulamaybe
used(whereSisthemeasurmentspan,e.g.,0-100deg.C):
Intheassignment youneedtodealwiththeseparameters.Youfindinformation abouttheseparametersintheData
sheetforyourdevice
http://en.wikipedia.org/wiki/Calibration
http://en.wikipedia.org/wiki/Measurement_uncertainty
http://en.wikipedia.org/wiki/Accuracy_and_precision
ArduinoBasics
GettingStartedwithArduino
Hans-PetterHalvorsen,M.Sc.
• Arduinoisanopen-sourcephysicalcomputingplatform
designedtomakeexperimentingwithelectronicsand
programmingmorefunandintuitive.
• Arduinohasitsownunique,simplifiedprogramminglanguage
andalotsofpremadeexamlesandtutorialsexists.
• WithArduinoyoucaneasilyexplorelotsofsmall-scalesensors
andactuatorslikemotors,temperaturesensors,etc.
• ThepossibilitieswithArduinoareendeless.
http://www.arduino.cc
10
ArduinoUNO
https://www.arduino.cc/en/Guide/HomePage
http://www.arduino.cc
PinOverview:http://pighixxx.com/unov3pdf.pdf
TheArduinoProgrammingEnvironment(IDE)
TheArduino IntegratedDevelopmentEnvironment - orArduino
Software(IDE)- containsatexteditorforwritingcode,a
messagearea,atextconsole, atoolbarwithbuttonsfor
commonfunctions andaseriesofmenus.Itconnects tothe
Arduino hardwaretoupload programsandcommunicatewith
them.
https://www.arduino.cc/en/Guide/HomePage
12
Books
Freedownload fromInternet
Thesebooks givesyouanintroduction toArduino. Thesebooksareavailableonthelab.Lotsof
Arduino booksarealsoavailableonSafariBooksOnline
SelectedeBooks fromSafariOnlineavailableforfreefor
StudentsandTeachersatTUC
http://proquest.safaribooksonline.com/
Arduino UnoBoard
ArduinoBasics
Breadboard
SensorsandActuators
15
TheArduinoKit
Arduino UnoBoard
Small-sizeSensorsandActuators
GettingStartedwithArduino:http://arduino.cc/en/Guide/HomePage
TheArduinoKit
• ArdionoHomePage:http://arduino.cc
• TheArduinoStarterKit:
http://arduino.cc/en/Main/ArduinoStarterKit
• StarterKitVideos:
https://www.youtube.com/playlist?feature=edit_ok&list=PLT6
rF_I5kknPf2qlVFlvH47qHvqvzkknd
17
GettingStarted
• ArduinowithBreadboardSensors/Actuators:
–
–
–
–
–
LED
PushButton
Potentiometer
DifferentTemperatureSensors
etc.
• InstalltheArduino SketchandExplore
someoftheseSensors&Actuators,i.e.,
make2-3Examples.
• Usethebreadboard forcreatingyour
circuits.
• UseArduino Sketchinordertocreatethe
ProgramsthatinterfacewiththeSensors
&Actuators
Congratulations!- YouarefinishedwiththeTask
19
TemperatureSensors
Hans-PetterHalvorsen,M.Sc.
TemperatureMeasurements
Theory
DifferentmethodsformeasuringtheTempertature:
• Thermocouples
• Thermistors
• RTD(ResistanceTemperatureDetector)
– e.g.Pt100
• Infrared
• Thermometers
21
TemperatureSensors
MakethefollowingTemperatureSensorsworkwithArduino:
NTCThermistor
TMP36
Small-scaleTemperatureSensors
TMP36
https://www.sparkfun.com/products/10988
https://www.elfa.se/elfa3~eu_en/elfa/init.do?item=73-889-29&toc=0&q=73-889-29
NTCThermistor
https://www.elfa.se/elfa3~eu_en/elfa/init.do?item=60-260-41&toc=0&q=60-260-41
Tutorial:http://garagelab.com/profiles/blogs/tutorial-using-ntc-thermistors-with-arduino
23
TMP36
Theory
•
•
•
Thesesensorsuseasolid-statetechniquetodeterminethe
temperature.Thatistosay,theydon'tusemercury(likeold
thermometers),bimetalicstrips(likeinsomehomethermometersor
stoves),nordotheyusethermistors(temperaturesensitiveresistors).
Instead,theyusethefactastemperatureincreases,thevoltageacross
adiodeincreasesataknown rate.(Technically,thisisactuallythe
voltagedropbetweenthebaseandemitter- theVbe- ofatransistor.)
Bypreciselyamplifyingthevoltagechange,itiseasytogeneratean
analogsignalthatisdirectlyproportionaltotemperature.Therehave
beensomeimprovementsonthetechniquebut,essentiallythatishow
temperatureismeasured.
Becausethesesensorshavenomovingparts,theyareprecise,
neverwearout,don'tneedcalibration,workundermany
environmentalconditions, andareconsistantbetweensensors
andreadings.Moreovertheyareveryinexpensiveandquite
easytouse.
https://learn.adafruit.com/tmp36-temperature-sensor
24
DatasheetCalculations
Theory
Fromtheplotwehave:
(x1,y1)=(750mV,25°C)
(x2,y2)=(1000mV,50°C)
Linearrelationship:
Youhavetofind a(slope) andb(intercept):
y-25°C=((50°C-25°C)/(1000mV-750mV)) *(x-750mV)
Thisgives:
y[°C]=(1/10)*x[mv]-50
25
Voltage-basedSensors
According totheTMP36datasheet,therelationof theoutput voltage
totheactualtemperatureusesthisequation:
y[°C]=(1/10)*x[mv]-50
TMP36
Wherethevoltagevalueisspecified inmillivolts.
However, beforeyouusethatequation, youmustconverttheintegervaluethatthe
analogReadfunction returnsintoamillivolt value.
10-bitanalogtodigitalconverter
Youknowthatfora5000mV (5V)valuespantheanalogReadfunction willreturn
1024possible values:
Where
voltage=(5000/1024)*output
mV
output =analogRead(aichannel)
0-1023
A0-A5
TMP36TemperatureSensorExample
// We'll use analog input 0 to read Temperature Data
const int temperaturePin = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
float voltage, degreesC, degreesF;
voltage = getVoltage(temperatur ePin );
// Now we'll convert the voltage to degrees Celsius.
// This formula comes from the temperature sensor datasheet:
degreesC = (voltage - 0.5) * 100.0;
SerialMonitor
// Send data from the Arduino to the serial monitor window
Serial.print("voltage: ");
Serial.print(voltage);
Serial.print("
deg C: ");
Serial.println(degreesC );
delay(1000); // repeat once per second (change as you wish!)
}
float getVoltage(int pin)
{
return (analogRead(pin) * 0.004882814);
// This equation converts the 0 to 1023 value that analogRead()
// returns, into a 0.0 to 5.0 value that is the true voltage
// being read at that pin.
}
27
TMP36TemperatureWiring
28
Resistance-basedSensors
Theory
Theproblem withresistancesensorsisthattheArduino analog
interfacescan’tdirectlydetectresistancechanges.
Thermistor
Thiswillrequiresomeextraelectroniccomponents. Theeasiestwayto
detectachangeinresistanceistoconvertthatchangetoavoltage
change.Youdothatusing a voltagedivider,asshown below.
Bykeepingthepowersourceoutput constant,asthe
resistanceofthesensorchanges,thevoltagedividercircuit
changes,andtheoutput voltagechanges.Thesizeofresistor
youneedfortheR1resistordepends ontheresistancerange
generatedbythesensorandhowsensitiveyouwantthe
output voltagetochange.
E.g.,theSteinhart-HartEquationcan
beusedtofind theTemperature:
Generally,avaluebetween1Kand10Kohmsworksjustfine
tocreateameaningfuloutput voltagethatyoucandetectin
yourArduinoanaloginputinterface.
NTCThermistorExample
// Read Temerature Values from NTC Thermistor
const int temperaturePin = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int temperature = getTemp();
Serial.print("Temperatu re Value: ");
Serial.print(temperatur e);
Serial.println("*C");
delay(1000);
}
SerialMonitor
double getTemp()
{
// Inputs ADC Value from Thermistor and outputs Temperature in Celsius
int RawADC = analogRead(temperature Pin) ;
long Resistance;
double Temp;
// Assuming a 10k Thermistor.
Calculation is actually: Resistance = (1024/ADC)
Resistance=((10240000/R awAD C) - 10000);
// Utilizes the Steinhart-Hart Thermistor Equation:
// Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]^3}
// where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08
Temp =
Temp =
Temp =
return
}
log(Resistance);
1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741
Temp - 273.15; // Convert Kelvin to Celsius
Temp; // Return the Temperature
* Temp * Temp * Temp));
Steinhart-HartEquation:
Congratulations!- YouarefinishedwiththeTask
31
Pt-100Measurements
Hans-PetterHalvorsen,M.Sc.
TemperatureMeasurements
Pt100:CreateyourowntemporaryPt-100sensorwith
Transmitter(createthecircuitonabreadboard)and
thenReadTemperaturevaluesusingArduino.
SuggestedTasks:
– ComparewithTemperatureSensorsavailablewithinthe
ArduinoKit(TMP36,Thermistor,...)
– CompareandDiscussthefollowingTemperature
Measurements;Pt-100,Thermocouple,Thermistor
(Measurementprinciples,etc.)
33
L
Thisisapre-madedevice.
Yourjobistocreatethisusing
aBreadboard
N
Cableclamp
Ground
Output
+24V
RTDred
RTDwhite
Createthiscircuiton
yourbreadboard
Internal
terminalblock
Pt100
transducer
RTDred
Pt-100Wiring
<<<<<<<
Pt100element
+24V
transducer
red
red
white
↓4-20mA
R ~250Ω
Pt100
+
1-5Voutput
terminals
–
24VPSU
Output terminals
Important!Testtheoutput ofyourcircuitBEFORE connectingittotheArduinoAnalogInputwitha
Multimetertomakesurethevoltageisnothigherthan5V,elsetheArduinowillbedamaged!
Output–
RTD
Output+
0V
CreateyouownPt-100SensorwithTransmitter
TesttheDeviceusing Arduino
TemperatureTransmitter(0-100deg.C)
Pt-100
https://www.elfa.se/elfa3~eu_en/elfa/init.do?item=76-69051&toc=0&q=76-690-51
https://www.elfa.se/elfa3~eu_en/elfa/init.do?item=76-89574&toc=0&q=76-895-74
24VDC/0.25APowerSupply
Breadboard
https://www.elfa.se/elfa3~eu_en/elfa/init.do?item=69-061-79&toc=0&q=69-061-79
35
L
Important!!!
N
0V
+24V
RTD
transducer
red
red
white
↓4-20mA
R ~250Ω
•
•
•
Pt100
+
1-5Voutput
terminals
–
TesttheoutputofyourcircuitBEFORE connectingittothe
ArduinoAnalogInput
UseaMultimetertomakesurethevoltageisnothigherthan5V
TheArduinowillbedamaged if the voltage ishigher than 5V!
36
Congratulations!- YouarefinishedwiththeTask
37
TemperatureDataLogger/
EmbeddedDAQSystem
Hans-PetterHalvorsen,M.Sc.
TemperatureData Logger/EmbeddedDAQSystem
YouusethePC whencreating
thesoftware,thenyou
download thesoftwaretothe
Arduino anddisconnect the
USBcable.Usee.g.,a9V
batteryoranexternalPower
Supply.
NTCThermistor
UsedifferentTemperature
sensorsforcomparison, i.elog
datafrom2different sensorsat
thesametime.
TemperatureDataLogger/
EmbeddedDAQSystem
CreateaTemperatureLogger/EmbeddedDAQSystem.SuggestedTasks:
•
CreateanduseaLowpassFilter/AverageFilter
•
Alarm functionality:UseLEDswithdifferentcolorswhenTemperatureis
above/belowtheLimits
•
Usee.g.,ArduinoWi- Fi/EthernetShieldforCommunicationoveranetwork - or
usethemicroSDcardonthese Shields
•
SavethedatatoamicroSDcardlocatedontheWi- Fi/EthernetShield- or
connect e.g.,toxively.com ortemboo.com- whicharefreedatalogging sites.
•
LogTemperatureDatafore.g.,24hoursandimportDataintoExcel,LabVIEWor
MATLABforAnalysisandVisualization
•
Usee.g.a9Vbatteryoranexternalpowersourcetomakeitportableandsmall
Arduino Wi-Fi/EthernetShield
http://arduino.cc/en/Reference/WiFi
WiththeArduinoWi-Fi/EthernetShield,thislibraryallowsanArduino
boardtoconnecttotheinternet.Itcanserveaseitheraserveraccepting
incomingconnectionsoraclientmakingoutgoingones.
ArduinoWi-FiLibrary:http://arduino.cc/en/Reference/WiFi
ArduinoEthernetLibrary:http://arduino.cc/en/Reference/Ethernet
SDLibrary:http://arduino.cc/en/Reference/SD
41
DiscreteLowpassFilter
LowpassFilterTransferfunction:
Wedefine:
Note!Implementthe
LowpassFilterasa
separateFunction
InverseLaplacegivesthedifferential Equation:
WeusetheEulerBackwardmethod:
Thisgives:
Thisgives:
Filteroutput
Noisyinput signal
Thisalgorithm canbeeaslyimplemented
inaProgramming language
ArduinoLibraries
•
•
•
•
TheArduinoenvironmentcanbeextendedthroughtheuseoflibraries,justlikemost
programmingplatforms.
Librariesprovideextrafunctionalityforuseinsketches,e.g.workingwithhardware
ormanipulatingdata.AnumberoflibrariescomeinstalledwiththeIDE,butyoucan
alsodownloadorcreateyourown.
YoucouldsayanArduinoLibraryislikeaClasswithMethods/Functions. Itisagood
waytostructureyourcode
Examples:
– EthernetLibraryfortheArduinoEthernetShield
– SDLibrary:TheSDlibraryallowsforreadingfromandwritingtoSDcards,e.g.onthe
ArduinoEthernetShieldorArduinoWi-FiShield
– Wi-FilibraryfortheArduinoWi-FiShield
•
Writingyourownlibraries:https://www.arduino.cc/en/Hacking/LibraryTutorial
https://www.arduino.cc/en/Reference/Libraries
43
ArduinoEthernet/Wi-FiShieldwithSDCard
Arduino Wi-FiShield
Arduino UNO
Ethernet
Arduino EthernetShield
Web-basedLoggingService
Youmaywanttoconnect e.g.,toxively.com,afreedatalogging site
https://xively.com
Arduinoxively.com:https://xively.com/dev/tutorials/arduino_wi-fi
http://www.twilio.com/
Usethe“Xively forArduino” libraryinorder to
connectandstoremeasurementdatafromyour
Arduino deviceintotheXively cloud
Anotheralternativeis:
www.temboo.com/arduino
SMS:http://www.twilio.com
www.temboo.com
45
Web-basedLoggingService Sensor Data
Arduino Ethernet/Wi-FiShield
Arduino EthernetShield
storedinthe
Cloud
DataStorageandService
Sensors
Wi-Fi/Ethernet
Cloud
PresentationofData
Logging SensorDatatotheCloud
Arduino
Computer
MSExcelorsimilar
www.digi.com/xbee/
XBee- WirelessCommunication
https://en.wikipedia.org/wiki/XBee
XBeeModule
XBeeUSBAdapterBoard
XBee5V/3.3VAdapterBoard
XBeeSIPAdapter Board
Arduino Tutorial:Let’smakeXBeetalk!:
http://www.norwegiancreations.com/2013/10/arduino-tutorial-1-lets-make-xbee-talk/
MakingThings Talk,2ndEdition(eBook availableatSafariBooksOnline):
http://proquest.safaribooksonline.com/book/hardware-and-gadgets/9781449314668
ExploringXBees andXCTU:
https://learn.sparkfun.com/tutorials/exploring-xbees-and-xctu?_ga=1.116328385.696451024.1434708629
XBeeExample
XBee802.15.4Module 1
XBee802.15.4Module 2
WirelessCommunication
XBeeSIPAdapter Board
or
XBee5V/3.3V
AdapterBoard
XBeeUSBAdapterBoard
Arduino
USBCable
PC
Breadboard
48
Congratulations!- YouarefinishedwiththeTask
49
Fritzing
Aopensourcetoolformakingsimplewiring
diagramforyourhardwarewiring
https://en.wikipedia.org/wiki/Fritzing
http://fritzing.org
Wiring madewithFritzing
Congratulations!- Youarefinishedwithall theTasksintheAssignment!
Hans-PetterHalvorsen,M.Sc.
UniversityCollegeofSoutheastNorway
www.usn.no
E-mail:hans.p.halvorsen@hit.no
Blog:http://home.hit.no/~hansha/
Download