Sie sind auf Seite 1von 7

ArduinoProgrammingforAccelerometer

RohanPanda
ECE480DesignTeam2
11/12/2015

Abstract
:ThisapplicationnotesdescribestheArduinoprogrammingprocessforaccelerometer.

Theproceduredescribesthecodingandconnectionprocesstoshowhowtomakethe

accelerometersensevibrationandtiltshifting.

KeyWords:vibration,accelerometer,Arduino,monitoring,imbalance,pins

Introduction:
TheArduinoUNORev3isamicrocontrollerbasedontheATmega32Pwith14

digitalinputandoutputpins.Outofthese14pins,6arecapableofPWMoutputs,6analog

inputs,aUSBconnection,apowerjack,anICSPheader,16MHzquartzcrystal,andareset

button.TheconvenientpartofArduinoisthatitisalreadyprebuiltwitheverymicrocontroller

supporthencesimplyplugginginwithanUSBcablewillsuffice.Alsoanadvantageofusingthe

UNOisthatthechipusedinitcanbereplacedforrelativelycheapcost.UNOboardisthevery

firstoftheArduinoboardsandeventhoughtherearemoreadvancedboardsavailable,forthis

project,theUNOboardwillbeenough.Thefigure1onthenextpageshowsthetechnical

specificationsofthisArduinoboard.

TheaccelerometerusedinthisprojectwouldbeADXL335small,thin,lowpower,3axis

accelerometerthatcontainssignalconditionedvoltageoutputs.Itisdesignedtomeasurethe

accelerationwithafullscalerangeof3g.Itmeasurestwokindsofmotion.Firstkindofmotion

thatitmeasuresisthestaticaccelerationofgravitywhentheaccelerometeristilted.Soduring

thediamondpolishingphaseifthearmtiltsitwillsendasignal.Thesecondkindofacceleration

itmeasuresisthedynamicaccelerationwhichwillhelptodetectthechangeisvibrationthat

mayoccurwhenthediamondpolishingmachineisatwork.
ADXL335ispoweredbya3.3vpowersourcethatcausesittogenerate3.3vpeakoutputs.It

hasthreeanalogoutputsforX,Y,andZaxiswhichrequireanADCmicrocontrollerthatis

providedbytheanalogfunctionsofArduinoboard.

Figure1:TechnicalSpecificationsforArduinoBoard


Fig1.TechnicalSpecificationsofArduinoshowsthattheboardisrelativelylightandsmall
weighingonly25gwithlengthof68.6mmandwidthof53.4mm.ItgivestheFlashmemoryand
clockspeedarerespectively32KBand16MHzwhichindicatesitisenoughforsmall
accelerometerprogramming.
Process:
TheprocesswilldescribehowtoconnecttheArduinoandtheaccelerometerandthen

downloadthearduinosoftwaretoprogramandrunthecodes.Figure2and3willbereferenced

inordertodescribetheconnection.

Figure2:ArduinoUNORev3pinsandports


Figure2showstheArduinoUNORev3portsandpinsandwheretheaccelerometerwillbe
connected.

Figure3:ADXL335Accelerometer


Figure3showstheX,Y,ZandGNDpinsfortheaccelerometeranditwillbeusedtoreference
thepowerpinconnection.

ThepartsrequiredforthisprocessaretheArduinoboard,ADXL335accelerometer,connecting

wires,andUSBcabletoconnectArduinoboardtocomputer.

ProcessforCircuitbuilding:

Accelerometerhas5pinsandalloftheseareconnectedtoArduino.FirstconnecttheGNDto

ArduinosGND.ThenconnecttheVCCtoArduinos5V,XtoArduino'sAnalogPinA5,Yto

ArduinosAnalogPinA4,andZtoArduinosAnalogPinA3.FinallytheAREFisconnectedto

3.3vonArduinotosetthereferencevoltageofADXL355to3.3v.

Thefinalproductshouldlooksomethinglikethefollowingfigure4.

Figure4:FinalconnectionofArduinotoAccelerometer



ProcessofcodingtheAccelerometer:

Beforebeginningthecoding,theArduino1.6.6softwareneedstobedownloadedforcompatible

operatingsystem.Openingitupwouldshowsomethinglikethefollowingfigure.
Figure5:WindowforArduinoSoftware

Figure5showstheArduinowindowitprovidesaspaceforwritingcodes.Ithasabuttonthat
isusedtouploadthecodestomachine.Theblackbarunderthewindowshowstheerror
messages.

NextthefollowingcodeisputintheArduinosoftware.

constintap1=A5
constintap2=A4
constintap3=A3

intsv1=0
intov1=0
intsv2=0
intov2=0
intsv3=0
intov3=0

voidsetup(){
//initializeserialcommunicationsat9600bps:
Serial.begin(9600)

}

voidloop(){
analogReference(EXTERNAL)//connect3.3vtoAREF
//readtheanaloginvalue:
sv1=analogRead(ap1)
//mapittotherangeoftheanalogout:
ov1=map(sv1,0,1023,0,255)
//changetheanalogoutvalue:
delay(2)
//
sv2=analogRead(ap2)

ov2=map(sv2,0,1023,0,255)
//
delay(2)
//
sv3=analogRead(ap3)

ov3=map(sv3,0,1023,0,255)

//printtheresultstotheserialmonitor:
Serial.print("Xsensor1=")
Serial.print(sv1)
Serial.print("\toutput1=")
Serial.println(ov1)

Serial.print("Ysensor2=")
Serial.print(sv2)
Serial.print("\toutput2=")
Serial.println(ov2)

Serial.print("Zsensor3=")
Serial.print(sv3)
Serial.print("\toutput3=")
Serial.println(ov3)

delay(3000)

}

Nextusethe searchglassicontodoserialmonitoring.

Results
:Aftertheserialmonitoringispressuredtheresultshouldgivesomethinglikethe

followinginfigure6.

Figure6:ResultsofAccelerometerVibration


Figure6showsthattherearetwodifferentanalogvaluesthatareoutput.Thefirstoneisthe

ADCvaluein10bitresolutionrangingfrom0to1023andthesecondisthemappedPWM

valuethatisin8bitresolutionrangingfrom0to255.ThenthreevaluesofX,Y.andZare

displayedatthesametimeandrepeatedafteraspecifiedintervalinthecode.Theoutputsare

variedbecauseduringthismeasuringprocess,vibrationwasproduced.Itisnotconstantwhich

showsthattheaccelerometerisdetectingthevibration.

Conclusion:
AllinalltheArduinoboardisaquiteinexpensiveandreliablewaytoprogramthe

accelerometertoshowimbalancesinthediamondpolishingarm.Thehardwarepartsare

relativelyeasytobuild.Figure6showsthattheaccelerometerissensitiveenoughto

differentiatebetweenoutputof195,190,and189whichmeanstheusercansetupanexternal

alarmsoitcangooffwhenanundesiredvibrationisproduced.

Reference:

Instructables.com.
"InterfacingADXL335withARDUINO." Web.12Nov.2015.

ArduinoArduinoBoardUno.
"ArduinoArduinoBoardUno." Web.12Nov.2015.

Das könnte Ihnen auch gefallen