0% found this document useful (0 votes)
133 views7 pages

Lab 6 - Potentiometer & Servo Motor

This 3 sentence summary provides the key details about the document: The document describes a lab experiment to control a servo motor using a potentiometer connected to an Arduino board. Students will create a LabVIEW program that uses the potentiometer reading and a formula node to set the servo angle, and add additional code to allow automatic waving of the servo motor by incrementing or decrementing the angle. The program uses case structures, local variables, and other logic to change the servo direction when its minimum or maximum range is reached.

Uploaded by

Christy Cheriyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views7 pages

Lab 6 - Potentiometer & Servo Motor

This 3 sentence summary provides the key details about the document: The document describes a lab experiment to control a servo motor using a potentiometer connected to an Arduino board. Students will create a LabVIEW program that uses the potentiometer reading and a formula node to set the servo angle, and add additional code to allow automatic waving of the servo motor by incrementing or decrementing the angle. The program uses case structures, local variables, and other logic to change the servo direction when its minimum or maximum range is reached.

Uploaded by

Christy Cheriyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Laboratory 4

Potentiometer & Servo Motor

SCADA 1
Course Code: PROC TECH 3SC3

B. Tech - PAT

OBJECTIVE
Inthislabyouwilllearnhowtouseclusterarrays,andtheformulanodefunction,andusethemto
controlaservomotorwithapotentiometer.

MATERIALS
ArduinoUNO&USBCable
Breadboard
SG90ServoMotor
Potentiometer
8xJumperWires

BACKGROUNDREADING
Pleasereadthefollowingmaterialpriortothislab:

1. Tutorial:MathScriptandFormulaNode,April2015Edition.Availableonlineat
http://www.ni.com/whitepaper/7572/en/
2. SG90ServoMotor,Availableonlineathttp://www.micropik.com/PDF/SG90Servo.pdf

PROCEDURE
Step1:CreatetheArduinoCircuit

1. ConnectfromthePositive(+)rowontheBreadboardto5VontheArduino,andfromthe
Negative()rowontheBreadboardtoGround(GND)ontheArduino.
2. ConnecttheServoMotor
a. ConnecttheGNDwireoftheservototheNegative()rowontheBreadboard.
b. ConnecttheVCCwireoftheservotothePositive(+)rowontheBreadboard.
c. ConnectthePWMwireofthe
servototheDigital(7)pinon
theArduino.
3. ConnectthePotentiometer
a. Connectoneoftheoutside
wirestotheNegative()row
ontheBreadboard.
b. Connecttheotherofthe
outsidewirestothePositive
(+)rowontheBreadboard.
c. Connectthemiddlewiretothe Figure1:ArduinoCircuit
Analog(0)pinontheArduino.
4. YourcircuitshouldnowlooklikeFigure1.

Step2:CreateMainLabVIEWprogram

1. OntheBlockDiagram,addtheInitfunctionfromtheArduinosubmenuandrightclickonthe
ArduinoResource,gotoCreate,andselectConstant,andsetittoCOM3.
2. UndertheArduino,Sensors,Servosection,addtheSetNumberofServosfunctionnexttothe
Initfunction.CreateaconstantfortheNumberofServosinputandsetitto1.
3. Fromthesamesection,addtheConfigureServofunction.
a. CreateaconstantforServoNumberandsetitto0.
b. CreateaconstantforDIOPinandsetitto7.
4. Next,placeaWhileLoopontheBlockDiagram,andconnecttheArduinoResourceanderrorout
outputstotheloopwithtunnels.Also,rightclickonthestopsignandcreateacontrol.
5. InsidetheloopaddthefunctionAnalogReadPinfromtheArduino,LowLevelsectionwith
AnalogInputPininputsetto0.
6. Also,addthefunctionServoWriteAnglefunctionfromtheArduino,Sensors,Servosection
withServoNumberinputsetto0.
7. ConnectbothArduinoResourceanderrorthroughthetwofunctions,andoutofthelooptothe
Closefunction.
8. YourcodeshouldnowlooklikeFigure2.

Figure2:ArduinoInterface

9. OntheFrontPaneladdaComboBoxfromtheString&Pathsection(Rename:Choice).Right
clickonitandselectEditItemsandinserttwoitems,namethemManualandAutomatic.
10. AddaGaugecontrolfromtheNumericsection
(Rename:Angle).Changetherangeto0180.
11. AddtwoNumericControlsfromtheNumeric
section(Rename:Speed&WaveCount).
12. AddanOKButtoncontrolfromtheBoolean
section(Rename:GO).
13. YourpanelshouldnowlooklikeFigure3.

3
Figure3:FrontPanel

14. Placethefourinputcontrolsintheloopontheleftside.CreatealocalvariableforAngle.Setit
toreadmode.Placeitamongsttheotherinputs.PlaceAngleontherightside.
15. PlaceaCaseStructurefunctionintheloop,andconnectChoicetotheCaseSelectorinput.
ChangethecasestoManual,DefaultandAutomatic.
16. IntheManualcaseplaceaFormulaNodefromtheProgramming,Structuressection.
a. IntheFormulaNodetypeD=V*180/5;.Thisisdonetoconvertfromvoltagetodegrees,
sincetheinputwillbefrom05V,andtheoutputmustbefrom0180.
b. RightclickontheFormulaNodeandclickAddInput,renameittoV.Connectittothe
voltageoutputfromtheAnalogReadPinfunction.
c. OntheFormulaNodealsoselectAddOutput,renameittoD.ConnectittoAngle.
17. AddanotherFormulaNodeoutsidetheCaseStructure.
a. AddaninputofDandtwooutputsIandSM.
b. TypeI=180D;ononelineandSM=(I/180*X)+Y;onthenextinsidetheFormulaNode.
c. (Note:Thisstepisdonetocalibratetheprogramtothespecificsoftheindividualservo.
Findthelowestandhighestanglestheservocanturnto.ReplaceYwiththeLowest,and
XwiththeHighestminustheLowest.E.g.Ifthelowestis32andthehighestis180,Y=
32,X=148.TheI=180D;partinvertstheservosothatitturnsinsyncwiththe
potentiometer;youcanremovethisifitisunnecessaryforyourservo.Note:IftheServo
isnotlimitedtoacertainrange,theentireFormulaNodeisunnecessary).
d. ConnecttheoutputtotheAngleinputofServoWriteAngle.Yourcodeshouldnowlook
likeFigure4.

Figure4:ManualCase

Step3:CreateaSubVI

1. OpenanewBlankVI.
2. AddfourcontrolstotheFrontPanel,oneButton(Rename:Go)andoneLED(Rename:Waving)
fromtheBooleansection,andoneNumericIndicator(Rename:WavesLeft)andoneNumeric
Control(Rename:WaveCountIN)fromtheNumericsection.PlaceGoandWaveCountINintoa
Cluster,foundintheArray,Matrix&Clustersection.
3. OntheBlockDiagram,addtheUnbundlefunction,foundundertheCluster,Class&Variant
section,andconnectittothecluster.Note:Youcanreordertheoutputbyrightclickingoneach
itemandclickingSelectItemandchoosingtheitemyouwantinthatlocation.
4. AddaCaseStructureandconnectGofromtheclustertotheCaseSelector.
a. InsidetheTruecase,placetheLEDandconnectittotheCaseSelectoraswell.
b. AlsointheTruecase,connecttheWaveCountINtoWavesLeft.
c. Thisisdonetosettheinitial
conditions;wavingissettoon,and
waveslefttothewavecountinput
fromtheuser.Nocodewillbeput
intheFalsecase.Yourcodeshould
looklikeFigure5.
Figure5:InitializeWaving
5. OntheFrontPanel,add4morecontrols,
oneLED(Rename:Direction),twoNumeric
Controls(Rename:AngleINandSpeed),andoneNumericIndicator(Rename:AngleOUT).
6. PlaceAngleINandSpeedintotheclusteraswell.
7. OntheBlockDiagram,addanotherCaseStructure.
a. CreateaLocalVariableofWavingandconnectittotheCaseSelector.
b. Also,connect;bothNumericControlsintotheCaseStructure.
c. IntheFalsecase,connectAngleINallthewaythroughtheCaseStructure,andoutto
AngleOUT.ThisisallthatwillbeintheFalsecase.

Figure6:ChangeAngle
5

8. IntheTruecase,createanotherCaseStructure.CreatealocalvariableforDirectionand
connectittotheCaseSelector.Connect;bothNumericControlsintothisCaseStructure.
a. IntheFalsecase,connectbothinputstotheSubtractfunction(AngleINSpeed),and
theoutputtoAngleOUT.
b. DothesamefortheTruecase,butwithanAddfunction.Thiswillchangetheangleby
thevalueofSpeedinthecurrentdirection.YourcodeshouldnowlooklikeFigure6.
c. AddanotherCaseStructureconnecttheCaseSelectorinputtoanORfunction.Connect
theinputsoftheORfunctiontoaGreaterorEqual?Function,andaLessorEqual?
Function.OneoftheinputsofeachwillbetheoutputfromtheotherCaseStructure.
Theotherwillbe180forthegreaterfunctionand0forthelessfunction.Thiswill
determinewhentheangleisoutoftherangeoftheservo,andchangethedirection.
i. InsidetheTruecase,placetheDirectionLED.Createanotherlocalvariablefor
Direction,setittoreadandconnectittoaNOTfunction,foundunderthe
Booleansection.ConnecttheoutputtotheDirectionLED.Thisisdonetotoggle
thedirectionoftheservomotor.
ii. AlsoplacetwolocalvariablesofWavesLeftinsidethestructure.Setoneto
read,connecttheinputtoaDecrementfunction,foundundertheNumeric
section.Connecttheoutputtotheotherlocalvariable.Thisisdonetolowerthe
numberofwaveslefteverytimethedirectionchanges.
iii. PutnothingintheFalsecase.
9. CreatealocalvariableforWavesLeft;connectittoaNotEqualto0?Function.Connectthe
outputtoalocalvariableforWaving.Thiswillturnoffwavingwhentherearenowavesleft.
10. Lastly,addaWaitfunction,foundunderTiming,andcreateaconstantfortheinputsetto10.
11. YoucodeshouldnowlooklikeFigure7.

Figure7:ToggleDirection&TurnoffWaving 6

Step4:TurnintoaSubVI

1. InthetoprightcorneroftheFrontPanel,rightclick,selectEditIcon
andchangeittosomethingbetter.E.g.WaveServo.
2. Also,connecttheinputoftheSubVIterminalstothecluster,and
connecttheoutputtoAngleOUT. Figure8:SubVI
3. Savetheprogram,andgobacktotheMainVI.

Step5:ConnecttheSubVIintheMainProgram

1. IntheFunctionsPanel,clickSelectaVIandfindyourSubVI.PlaceitintheAutomaticcaseof
theCaseStructure.
2. ConnectaBundlefunction,foundintheCluster,Class&Variantsectiontotheinput.Connect
theoutputtotheoutputoftheCaseStructure.
3. ConnectintotheBundlefunction,WaveCount,Angle,Speed,andGo.Youcanfigureoutthe
orderbygoingintotheSubVIandconnectingandUnbundlefunctiontotheclusterandseeing
whichordertheyappearinbydefault.Itisvitalthatyouputtheseinthecorrectorder.
4. Youcannowtesttheprogram.YourfinalprogramshouldlooklikeFigure9.

Figure9:FinalProgram

Step6:Applywhatyouhavelearnt

1. Modifytheprogramtohaveathirdchoice;Random.TheRandomcaseshouldchoosearandom
angle;0180,andwaitforatime,about1second,andthenchooseanotherrandomangle.

You might also like