BME/ECE 386 Lab 1 Lad Cell Measurement System GOALS Lab 1 Lad Cell Measurement System 1) Build and test a lad cell amplifier. 2) Write an Arduin prgram t: a. Acquire data frm a lad cell amplifier b. Cmpute lad in grams c. Send the data t a cmputer using the serial prt. 3) Perfrm sme fun experiments with yur lad cell measurement system! GENERAL GUIDELINES 1) Each student must build his/her wn circuit. 2) Due t the limited number f test statins, sme students need t pair up and share the test equipment. 3) Students are encuraged t help each ther. Of curse, Buma will be arund t prvide assistance as well. 4) D nt wrry if yu need lts f help during the lecture and lab activities. Just make sure yu knw yur stuff fr the exams. In additin t the written exams, there will be ne lab practical where each student is tested n putting tgether a cmplete measurement system (circuit cnstructin, Arduin + MATLAB prgramming). 5) Ask questins! The mre questins yu ask, the mre yu learn! REQUIRED MATERIALS Lad cell + weights (50g, 100g, and 200g) Lab kit + pwer supply + scillscpe + test prbes Arduin Un + USB cable + cmputer with Arduin IDE AD620 instrumentatin amplifier chip (ne) 100 hm (brwn/black/brwn) resistr (ne) 1.0 khm (brwn/black/red) resistrs (tw) Fig. 1: Lad cell (www.rbtshp.cm). LAB ACTIVITIES (3 PARTS) 1) Set up lad cell measurement hardware. 2) Develp the Arduin data acquisitin prgram. 3) Perfrm sme experiments with yur awesme lad cell measurement system. 1
BME/ECE 386 Lab 1 Lad Cell Measurement System INTRODUCTION In this lab, yu will develp a fully functining lad cell measurement system. A system blck diagram is shwn in Fig. 2. Here s hw it wrks: 1) The lad cell cnverts the mechanical lad (grams) int a very tiny vltage signal. 2) The instrumentatin amplifier increases the signal amplitude. 3) The amplifier utput is recrded by the Arduin and sent t a cmputer. 4) The cmputer displays measured lad (grams). A blck diagram f the verall system is shwn belw. The lad cell will be prvided during the lab sessin. The instrumentatin amplifier is the AD620 chip. In the lab sessin, yu will prgram an Arduin Un t recrd the amplifier utput, cmpute the lad, and send the result t a cmputer fr display. LOAD CELL AMPLIFIER ARDUINO COMPUTER Fig. 2: Blck diagram f lad cell measurement system. The hardware prtin f this lab (building and testing the lad cell amplifier) is the easy part. Mst f Lab 1 will be spent prgramming the Arduin Un. If yu have lts f Arduin experience, then this lab shuld g quickly. If yur prgramming skills are really rusty, dn t wrry this lab will guide yu thrugh the prcess in a step-by-step fashin. Buma is frcing yu t learn hw t d sme basic Arduin prgramming, because they are useful skills that can help yu: (1) with yur capstne prject (2) with any research prjects (3) get a jb. PART 1: LOAD CELL AMPLIFIER The circuit diagram fr the lad cell amplifier is shwn in Fig. 3. Task 1a: Pwer cnnectins fr the breadbard. Use RED wire fr any cnnectins invlving psitive supply vltage (e.g. +5V). Fr example, use a red wire t cnnect the breadbard s RED terminal t ne f the red-striped pwer buses. Use BLACK wire fr any cnnectins invlving grund. Yu can cnsult Buma s breadbard fr guidance. 2
BME/ECE 386 Lab 1 Lad Cell Measurement System Fig. 3: Schematic fr lad cell amplifier. The pin diagram fr the AD620 is als in the data sheet n the curse website. Taskb: Install the instrumentatin amplifier. All resistr clr cdes are n page 1 ( Required Materials ). The pin diagram f the AD620 is shwn in Fig. 3 (it is als in the datasheet n the curse website). Pin 1 and Pin 8 = 100 hm resistr this resistr sets the amplifier gain (G = 495). Pin 2 = (-) signal input frm lad cell (yellw wire). Pin 3 = (+) signal input frm lad cell (green wire). Pin 4 = GND Pin 5 = +2.5V (prduced by the tw 1.0 khm resistrs). Pin 7 = +5V Keep yur wiring neat! Yu can cnsult Buma s (r a neighbr s) breadbard fr guidance. Task 1c: Test the circuit. Use the scillscpe t measure the utput vltage at Pin 6 f the instrumentatin amplifier. Turn n the scpe Press Frce Trigger t enable lcal (e.g. Frnt Panel) cntrl Press Default Setup t reset the scpe Make sure bth the scpe and the prbe are set t 1X Adjust the scpe s vertical setting t 1V/div Yu shuld measure an utput vltage between 2 t 3.5 vlts. If nt, let Buma knw... 3
BME/ECE 386 Lab 1 Lad Cell Measurement System (End f Part 1) Place a 200g weight n the gray platfrm f the lad cell the vltage shuld increase by 0.5V. If yu are having difficulties getting yur lad cell amplifier t wrk prperly, feel free t ask Buma r the lab assistant fr help. PART 2: ARDUINO WARM-UP EXERCISES Buma will assume that yur Arduin skills have smewhat faded since ESC100. Therefre, we ll d three quick exercises t remind urselves hw t use an Arduin. The Arduin bard is prgrammed using the Arduin IDE, where IDE stands fr Integrated Develpment Envirnment. An Arduin prgram is called a sketch. Buma has kindly prvided a sketch template fr yu t get started. Dwnlad and unzip the Arduin template. G t the curse website and dwnlad Lab1_files.zip t yur desktp. Duble-click n the zipped flder. Select Extract all files (near tp f the windw) t unzip the cntents f the flder. Duble-click the Lab1_SerialStuff flder and pen the sketch. Yu shuld see smething like Fig. 4. Fig. 4: The template sketch shuld lk like this. 4
BME/ECE 386 Lab 1 Lad Cell Measurement System EXERCISE 2.1 Our first Arduin exercise is t send simple messages t the cmputer via the serial prt. Hw t d this? Any Arduin prgram requires a setup( ) rutine and lp( ) rutine. Fig. 5 is the flw chart fr the Exercise 2.1 prgram. (a) Setup rutine (runs nly ONCE) Initialize the serial prt Send a greeting (b) Lp rutine (runs ver and ver again) Send a message Wait 1000 ms Setup Rutine Lp Rutine Initialize serial prt Send a greeting Send message Wait 1000 ms Fig. 5: Flw chart f ur Arduin prgram. Repeat cntinuusly STEP 2.1a: Replace any??? in the template s that yur cde lks like Fig. 6. Fig. 6: Yur Arduin cde shuld lk like this. D NOT frget the semiclns! Sme cmments abut the cde: The Serial.begin cmmand tells the Arduin t get the serial prt ready. The 9600 sets the serial prt data rate t 9600 baud (same as bits per secnd). The Serial.print cmmand sends text data ut the serial prt. The delay cmmand tells the Arduin t wait a specified time, which in this case is 1000 ms. 5
BME/ECE 386 Lab 1 Lad Cell Measurement System STEP 2.1b: Cmpile and uplad the cde. An Arduin sketch needs t be cnverted t machine cde that is understandable t the micrcntrller. Once the cde is cmpiled, it needs t be transferred t the bard. Cmpile the cde. At the tp f the sketch windw, g t Tls >> Bard. Make sure Arduin/Genuin Un is selected. If the wrng bard is selected, yur cde wn t wrk n the Un! Click n the check-mark buttn in the tp left crner (Fig. 7). The bttm f the Arduin screen will say Cmpiling sketch... If n errr ccurs, it will eventually say Dne cmpiling. If an errr ccurs, it will tell yu the prblem. Fig. 7: Click n the check mark buttn t cmpile the cde. The arrw buttn is t uplad the cde t the Arduin bard. The serial mnitr will be used later t view the data sent frm the Arduin. Uplad the sketch t the Arduin bard. Cnnect the Arduin bard t the cmputer using a USB cable. The cmputer has many serial prts. Make sure yur sketch knws the serial prt used by the Arduin bard! At the tp f the sketch windw, g t Tls >> Prt Make sure there is a check mark next t the prt labeled Arduin Un. Click n the arrw-buttn (see Fig. 7). This actually des tw things. First, it re-cmpiles the cde. Secnd, it transfers the cmpiled cde t the bard. On the bard, the yellw Tx and Rx LEDs light up while the transfer ccurs. If all ges well, the bttm f the sketch windw shuld say Dne uplading. Yu shuld see the bard s yellw Tx LED blink nce a secnd! 6
BME/ECE 386 Lab 1 Lad Cell Measurement System STEP 2.1c: Observe the Arduin data using the Serial Mnitr n the cmputer. Click n the tp right buttn (lks like a magnifying glass) in the Arduin IDE (Fig. 7). Make sure the bttm right crner f the Serial Mnitr says 9600 baud. Otherwise, the mnitr will display sme interesting lking characters. Yu shuld ntice that all the messages are printed n the SAME line (Fig. 8). This is because the Serial.print cmmand des NOT autmatically create a new line! If yu want the Arduin t print a message AND start a new line (Fig. 9): Yu can leave the Serial Mnitr windw pen. In yur cde, change the tw Serial.print cmmands t Serial.println. The Serial.println cmmand sends the desired message and adds a new line cmmand as well. Re-cmpile and uplad yur cde each message shuld nw be n a new line! Fig. 8: The serial mnitr shuld display the multiple messages n the same line. Fig. 9: Each message is nw displayed n a new line! 7
BME/ECE 386 Lab 1 Lad Cell Measurement System EXERCISE 2.2 Nw let s d a simple cmputatin and send the result t the cmputer. We want the Arduin t act like a timer and display the number f secnds. A simple way t d this is t create a new variable T that keeps track f time. The value f T is updated at the end f each lp iteratin. STEP 2.2a: Revise the lp( ) rutine s that yur cde lks like Fig. 10. Dn t frget t add the line f cde just befre the lp! Als dn t frget the semiclns! Fig. 10: Befre the lp( ) rutine, we declare a variable that keeps track f time. Inside the lp( ) rutine, the Arduin displays an updated time value. Cmments abut the cde: When yu create a variable, yu must always specify its data type! Data types include a signed integer, unsigned integer, flating pint number, etc. int means a 16-bit signed integer, which is any integer between -32,768 and +32,767. We are setting the initial value f T t be zer. Inside the lp, ntice hw we are using multiple Serial.print cmmands t frm a message. The value f T is incremented by adding 1. STEP 2.2b: Uplad yur cde and bserve the Serial Mnitr. Yu shuld see smething like Fig. 11. Fig. 11: The Arduin nw displays an updated value fr the elapsed time. 8
BME/ECE 386 Lab 1 Lad Cell Measurement System EXERCISE 2.3 This is the last warm-up exercise! Let s recrd a vltage and send the result t the cmputer. The flw chart f ur prgram lks like Fig. 12. (a) Setup rutine (b) Lp rutine Initialize serial prt Send a greeting Recrd ADC utput Cmpute vltage Send data via serial prt Wait 1 sec Setup Rutine Lp Rutine Initialize serial prt Send a greeting Recrd ADC utput Cmpute vltage Send data Wait Fig. 12: Flw chart f Exercise 2.3 prgram. Repeat cntinuusly STEP 2.3a: Revise the lp( ) rutine s that yur cde lks like Fig. 13. Fig. 13: Befre the lp, declare sme variables t stre data. Inside the lp, recrd the ADC utput and print the value. Cmments abut the cde: Befre the lp, we need t create several variables. Pin_A0 is basically a name that we assign t analg input 0. The Arduin Un has six analg input pins. On the bard, they are labeled as A0, A1, A2,, A5. In the cde, they are simply numbers 0, 1, 2,., 5. ADCutput stres the ADC utput, which is an integer. 9
BME/ECE 386 Lab 1 Lad Cell Measurement System Vmeas is a flating pint number (e.g. has decimal pint) t stre the measured vltage. T is the number f millisecnds t wait between analg readings. Inside the lp, we must d several things: analgread reads the ADC utput frm Pin_A0. Fr nw, we will simply print the ADCutput value. Uplad yur cde and bserve the Serial Mnitr. It shuld lk like Fig. 14. Yu shuld ntice that the utput is just an integer (between 350 and 700). Since the ADC has 10 bits, it can prduce 2 10 = 1024 different values. The lwest integer is 0 and the highest integer is 1023. Fig. 14: The ADC utput is nt a vltage, but an integer between 0 and 1023. STEP 2.3b: Nw mdify the inside f the lp t lk like Fig. 15. Fig. 15: The inside f the lp nw cmpute the vltage and sends the result ver the serial prt. Cmments abut the cde: Inside the lp, we must d several things: analgread reads the integer utput (stred as ADCutput) frm Pin_A0. Fr the Arduin, Vmeas = ADCutput * V ADC = ADCutput * 5/1023.0. The decimal pint in 1023.0 ensures the final result is a flating pint number. 10
BME/ECE 386 Lab 1 Lad Cell Measurement System Uplad yur sketch t the bard and bserve the Serial Mnitr. It shuld lk like Fig. 16. By default, flating pint numbers are displayed t tw decimal places. Yu can increase this precisin (e.g. display 3.14159 sec), but we d nt need t d this fr Lab 1. (End f Part 2) Fig. 16: Yu shuld nw see vltage values. The flating pint data type is needed t display numbers with decimal pints! PART 3: LOAD CELL MEASUREMENT SYSTEM OK, nw we shuld be ready t make the lad cell measurement system! STEP 3.1: Cnnect yur lad cell amplifier t the Arduin bard (see Fig. 17). Use a YELLOW wire t cnnect the AD620 utput (Pin 6) t the A0 pin f the Arduin. Use a BLACK wire t cnnect the breadbard grund t a GND pin f the Arduin. Fig. 17: TWO wires (see arrws) cnnect yur breadbard (Pin 6 f AD620 and GND) t the Arduin Un (Pin A0 and GND). 11
BME/ECE 386 Lab 1 Lad Cell Measurement System STEP 3.2: Prgram the Arduin t display weight in grams. In Exercise 2.3, yu cmputed Vmeas. Nw yu want t end up with WEIGHT! Using the Exercise 2.3 prgram as a starting pint, figure ut hw t mdify and add extra cde t cnvert Vmeas int weight! Hw t d this? Sme things t keep in mind: Vmeas is cnverted t weight by the equatin: weight = (Vmeas- Vref) * Lrated / (K Ad RO Vs); weight is the mechanical lad in grams Vref is the reference vltage and Ad is the differential gain RO, Vs, and Lrated are the lad cell specificatins K is a calibratin factr (typically 0.8 < K < 1.2). Every variable in the equatin must be declared ahead f time. It is a gd idea t first declare each variable as a flat befre the lp. Fr example, weight shuld be declared as: flat weight; Initially, set the initial values f the fllwing variables t be: Vref = 2.50, Ad = 495, RO = 0.8e-3, Vs = 5, Lrated = 780, and K = 1.00 Later n, yu will need t tweak the values f Vref and K (see next step). Dn t frget the semiclns at the end f each line f cde! Cmpile (verify) the cde t make sure it is free f errrs. Uplad the cde and bserve the Serial Mnitr. Make sure NO WEIGHT is n the lad cell. Yu will prbably see sme very wrng values fr weight (e.g. -300g). This is OK, since we still need t zer and calibrate the weigh scale. STEP 3.3: Zer and calibrate the weigh scale. Yu are almst dne! The weigh scale displays incrrect values fr tw reasns. First, the scale needs t be zered, meaning that zer weight prduces a display f 0 grams. Secnd, the scale needs t be calibrated, meaning a knwn weight (e.g. 200 grams) prduces the crrect value. Zer the digital weighing scale by determining the prper value f Vref. Yu will need t mdify the Arduin cde t btain reasnably crrect values. Change the value f Vref (e.g. increment r decrement by 0.05 r s). Uplad the mdified cde t the bard and bserve the Serial Mnitr. Repeat as many times as necessary until yu cnsistently get a value clse t 0 g (+/- 2 g is fine). It is perfectly OK if the weight fluctuates slightly abve and belw 0 g. Yu may need t use a few decimal places (e.g. 2.395) t get the crrect value f Vref. Nw we need t calibrate the system t give accurate weight values. 12
BME/ECE 386 Lab 1 Lad Cell Measurement System Keep the prgram running and place the 200g weight n the lad cell. The value is prbably wrng (e.g. 220 g instead f 200 g). Change the value f K (e.g. increment r decrement by 0.05 r s) in the cde. Uplad the mdified cde t the bard and bserve the Serial Mnitr. Repeat as many times as necessary until yu cnsistently get 200 g (+/- 2 g is fine). Yu may need t use a few decimal places (e.g. 1.125) t get the crrect value f K. It is perfectly OK if the weight fluctuates slightly abve and belw 200 g. OK, nw fr the REAL test f hw well yur digital weighing scale wrks. Replace the 200g weight with a 100g weight. What is yur measured result? Hpefully it is between 98 and 102 grams. Replace the 100g weight with a 50g weight. What is yur measured result? Hpefully it is between 48 and 52 grams. Save a snapsht f the serial mnitr windw shwing yur system measuring 50g, 100g, and 200g weights. One snapsht can shw all three (e.g. change weights every 5 secnds). Use ALT + PrtSc t recrd a snapsht and paste the image int Wrd. Dem yur system t Buma. Shw that yur system gives reasnable values fr all three weights. Shw yur final values fr Vref and K. Fr yur lab reprt, make sure yu have the saved snapsht and values f Vref and K. Fig. 18: Yur saved snapsht shuld lk smething like this. (End f Lab 1) 13