Before we start with the lab, please have a good look at the lab report assignment. Make sure to understand all the objectives of the assignment to generate all the results you need for your report.
ASSIGNMENTS/DELIVERABLES
(LAB REPORT DUE TUESDAY, 10/10/2023 AT 1:30 PM ON LAULIMA)
You are required to write a short laboratory report to present and discuss your results. You can assume that the reader of your report is familiar with the experiment so please focus on a clear description of your results instead of recounting the laboratory procedure. The report should be logically organized and include titles, headings and subheadings to organize the report. The report should present and discuss the following topics:
1. Time-Averaging
Present the results of your time averaging MATLAB script to convert the 1 second of signal data to a single average signal.
Present at least one figure to illustrate the 1 second of data at 10 Hz and the resulting average value.
You should also calculate the standard deviation of this 1 second of data. What does the standard deviation suggest about the variability in your measurement?
A table summarizing the signal mean and standard deviation for each mass.
2. Experimental Model
Present and discuss the linear fit of your load versus strain measurements.
Report the numerical values you determined for the experimental model in a table. Report the parameters of your curve fit for ‘m’ and ‘b’ along with the R2 value (squared correlation coefficient) for the experimental results.
You should also report the standard error of the fit (see Chapter 6 of your textbook).
What do the R2 and standard error values suggest about the efficiency of your experimental model?
Produce a graph that shows the data and the linear model. Include this plot as a properly formatted figure in your report.
3. Model-Experiment Comparison
Illustrate the comparison between the mathematical model and the experimental measurements. You have both an analytical model for the relationship between tip force and strain (the mathematical model from your pre-lab, using the actual measurements for the beam from lab) and an empirical model based on the linear fit of your laboratory data.
Your comparison should include one figure that plots strain (at the strain gauge) versus tip load. The plot should include your time-averaged observations for the 10 tip load values, the empirical linear model (a least-squares best linear fit of the data) and a plot of the analytical prediction from your pre-lab.
4. Estimate of "unknown" force (AKA mystery box)
Based on your calibration curve you should be able to estimate the weight of the unknown load.
Estimate the weight of the "unknown" mystery load.
Quantify the uncertainty of your estimate of the mystery load. What is the accuracy and precision of your estimate (with units)? One way to quantify the accuracy of your estimate is to compare it to a known value. Compare your measured estimate with the “true” mystery load mass as measured by a scale or known beforehand.
Present a figure that plots strain versus tip load. The figure should include your time-averaged observations for the 10 tip load values, the empirical linear model (a least-squares best linear fit of the data), a plot of the analytical prediction from your pre-lab, and a plot of the mystery weight.
Your lab report should be a single document that discusses the topics above. Your document should also include a short introduction and conclusion. The evaluation of your lab report will be based on your clear communication of the main results of the laboratory exercise. Your MATLAB scripts should be attached in the appendix of the lab report.
Note on the Units of Strain
Although strain is a unit-less quantity, it is common practice to express the strain as the ratio of two length units, for example, as m/m or in/in. Because the strain is usually a very small number, it is often better to express strain as units of μm/m (micrometers per meter). In this sense, a strain of 0.001 would be expressed as 1000 μm/m. In general, the smallest value of strain encountered in most applications is 1 μm/m. Also note that some documents use “με” (i.e., mu epsilon) instead of μm/m.
Part 1: Setup - Single strain gauge on beam with Wheatstone 1/4 bridge and HX711 Load Cell Amplifier
Beams and 120 Ohm strain gages have been prepared for you with the specifications given last week. For Lab 2, you will construct a Wheatstone bridge, connect this to an amplifier and data acquisition board, and connect that to your Arduino board to measure the strain of the gauge in response to applied loads at the end of the beam. The specifications and user's guide for the HX711 Amplifier is available on this website.
The pins on the LEFT side of the amplifier board connect to the corners of the Wheatstone bridge and are indicated by color:
RED is the excitation voltage VCC
BLK (Black) is GND
WHT (White) is the negative output
GRN (Green) is the positive output
YLW (Yellow) is not used
Use your circuit breadboard to wire up the bridge as shown:
The right-hand side of the bridge is formed by your potentiometer: Connect the ends to RED and BLK, and the variable output to WHT.
The left-hand side of the bridge is formed by a 120 Ohm resistor and the strain gauge: Connect the 120 Ohm resistor leads to RED and GRN, and the strain gauge leads to GRN and BLK.
2. The pins on the RIGHT side of the amplifier board connect to the Arduino:
VDD and VCC connect to 5V
DAT (data) connects to Arduino pin 3
CLK (clock) connects to Arduino pin 2
GND connects to GND
3. To read the amplifier signal with the Arduino:
Download the "HX711 Arduino Library by Bodgan Necula, Andreas Motl" for the Arduino: From an Arduino window go to "Sketch/Include Library/Manage Libraries", search for "HX711 Arduino Library", and install.
Type in and upload the following Arduino code (exactly!):
#include "HX711.h"
// HX711 circuit wiring
#define DOUT 3
#define SCK 2
HX711 scale;
void setup() {
Serial.begin(115200);
scale.begin(DOUT,SCK);
}
void loop() {
Serial.print(millis()/1000.0,3);
Serial.print(" ");
Serial.println(scale.read());
}
4. Because the strain gage change in resistance is small (~0.1 Ohm) and the amplifier gain is large (128x) you will almost certainly need to balance or "zero" your bridge circuit:
Start the Arduino serial plotter with a 115200 baud rate and carefully adjust your potentiometer to get the signal as close as possible to zero while the beam is unloaded. You should now be able to see the signal respond to light fingertip pressure on the beam.
NOTE: The bridge signal is quite sensitive to adjustment of the potentiometer. A light touch will be needed to balance the bridge, and it's ok if you can't get the signal exactly to zero: Actually a balance zero signal anywhere in the range of plus or minus 2000000 would be fine.
Part 2: Data Acquisition - Measuring Strain as a Function of Load
Now we have a setup that measures the output from the Wheatstone bridge. From this signal we can infer the strain measured by the strain gage. Now we will apply a set of static loads to the end of the beam, from 0 to 5 Newtons (510 gram weights) and for each load we will measure the strain.
You will need some lightweight container to hang weights from the beam. Use a light wire or string to attach the container at the hole at the end of the beam.
1. With your empty weight container hanging from the beam, zero the output of your Wheatstone bridge by adjusting the potentiometer.
2. The following steps describe a single measurement of strain for a given load. Start by obtaining measurements with the unloaded beam, then repeat the following steps 10 times, each time applying a known load using known weights.
***TIP! One nickel is exactly 5.000 g, one penny is 2.500 g. Hang your coins or other known weights in your lightweight cup or other container, up to 5.0 Newtons or 510 grams.
Hang the weights from the tip of the beam. Be careful to stop any vibration before starting the static measurement of strain.
Collect approximately 1 second of data, or 10 samples since the amplifier updates at 10 Hz, for each load using the serial monitor and copy-paste the timestamp and amplifier signal data into a matlab array named for the size of the load, such as "data100gram" for example.
As you load the beam with different weights, check that the strain gage signal returns close to the original unloaded signal each time. Some variation is normal but try to minimize this. Take a complete set of measurements in one session to minimize thermal variation.
Experiment: Mystery Weight
In the previous experiment you measured the strain for known weights between 0 and 5.0 N. This will allow us to build an experimental characterization of the relationship between strain and load.
Next we'll repeat this experiment for a “mystery weight”. Repeat the steps above for making a strain measurement, but use a different sample weight. Again, record 1 second of data. In the analysis section you will use your pre-lab model and your experimental characterization to predict the value of the mystery weight. You'll need to know the true weight of this object so you can compare your model and predicted weight to the actual weight in your lab report.
Part 3: Data Analysis
You should have defined a MATLAB array for each experimental run where each array contains 1 second of time and amplifier signal data (10 data points since the amplifier and analog-to-digital converter updates at 10 Hz). For the lab report you will need to:
(1) plot measured and average amplifier signal vs. time for at least one loading experiment, and also give the average and standard deviation of the signal converted to voltage and strain.
(2) plot strain vs. load for (a) your set of experiments by converting average signal to strain for each load condition, (b) your curve fit line function which best fits your experimental data, and (c) the strain vs. load curve predicted by your prelab analysis of the beam parameters.
Include the MATLAB scripts you use to produce these plots in an appendix of your lab report.
The first analysis step is to use MATLAB to calculate the average signal for each run:
Time Averaging
Write a script (a MATLAB.m file) that will accomplish the following:
Calculate the time-average signal and the standard deviation of the signal for each measurement
Make a plot of the signals and the average signal as a function of time.
Report the time-averaged signal to the workspace.
Here is an outline of one way you might accomplish this:
Create a new folder called “Lab2_Analysis”.
Save all your data as a .mat file in that same folder: A “save lab2” will save all the your defined matlab variables into a file called “lab2.mat”
Create a new MATLAB script called “taverage.m” and save it to the same folder.
Within the script:
Define a vector for each 10-sample measurement, for example for measurement 4:
datavec4 = data400gram(:,2);
timevec4 = data400gram(:,1);
Create a variable containing the average (the mean) of the voltage measurements (see the mean() function.) Do not put a semicolon (;) at the end of this line. This will tell MATLAB to report the variable to the workspace.
fmean4=mean(datavec4)
Create a variable containing the standard deviation of the signal measurements (see the std() function.) Do not put a semicolon (;) at the end of this line. This will tell MATLAB to report the variable to the workspace.
fstd4=std(datavec4)
Again, run your script and see if it works.
Create a new figure window
figure()
Plot the measurements as a function of time. Us red dots to indicate the individual measurements, i.e., the line type is 'r.' For example, for measurement 4:
plot(timevec4, datavec4, 'r.')
Include a statement to turn on the hold behavior so that you can add more data to the plot.
hold on;
Plot a horizontal line (a black dashed line, 'k--' works well) to indicate the value of the average voltage.
plot([x1,x2],[fmean4,fmean4],'k--') (replace x1 and x2 with appropriate values)
Add a legend, a title and axis labels (with engineering units) title('your title')
xlabel('your x label [with unit]')
ylabel('your y label [with unit]')
legend('first curve [with unit]','2nd curve [with unit]')
Now, once you have all this working you should be able to run the script and it will generate the figure and report the mean and standard deviation to the workspace.
You will need to do this for each of your measurement arrays. You can modify the script you already have with the other array names one by one, or add to the script to do them all together. All you need to do is change the data variables for each run to correspond to each numbered measurement array to obtain the average signal for each set of measurements.
NOTE: To convert the amplified sensor signals to the output voltage of the Wheatstone bridge, you need to know that the voltage supplied from the Arduino is 5 V, the gain of the HX711 amplifier is 128, and the analog-to-digital conversion is 24 bits. So you divide the obtained signal by 128, divide again by 2^24, and multiply by 5 to obtain the voltage.
You can then obtain the strain from the voltage by using the bridge equation from the prelab exercise.
Now, from your 10 runs you can collect all the data you need to create the curve fit of load versus strain. To facilitate this you should open another script. Let’s call it “curve_fit.m”. Declare two variables: “tipload” and “meanstrain”. Each variable will be a vector of length 10. For example, if I had analyzed four runs my script might look like this:
% This is my curve_fit.m script (replace the numbers with your measurements!)
tipload = [0.98, 1.96, 2.94, 3.92]; %[N]
meanstrain = [0.0012, 0.0024, 0.0034, 0.0037]; %[V]
When you are done, you can plot the strain versus load to check the results.
plot(tipload,meanstrain,'ro')
Notice each data point is indicated with a red circle ('ro').
Part 4: Developing an Experimental Model
Because of the pre-lab work, we would expect the relationship between measured strain (ε) and the applied force (F) to be a simple linear relation. For example, you may have derived an mathematical model similar to the following equation:
This mathematical model expresses a linear relationship between beam strain and applied force. However, there is considerable uncertainty in the actual material properties, beam dimensions and location of the strain gage, so we will use the measured data to generate a linear experimental model of the form,
In order to 'fit' the linear model to the data we need to determine numerical values for the constants m and b.
An important part of empirically identifying a mathematical model from experimental data is to report on the quality of the model, i.e., the “goodness of fit” of the chosen model. For linear polynomial models this is typically quantified by the correlation coefficient R, which is often reported as the coefficient of determination (often just called the R2 value).
From the previous exercise you should have a script called “curve_fit.m” that declares two variables. Each variable should be of length 10 — “tipload” and “meanstrain”.
Before we start to fit the data, we’ll need to convert the measured voltage values to measured strain values. From the pre-lab you can determine the relationship between voltage from the Wheatstone bridge and strain; this is the sensitivity of the sensor. To use MATLAB to convert the voltage values to strain values you should use an element-wise multiplication of the meansignal, like this:
meanstrain = K*meanvoltage;
where ‘K’ is a scalar constant.
Note that you will need to first convert the 24-bit signal values obtained by the Arduino to voltages as described above, then convert these voltages to strain as shown in the example below:
% This is my curve_fit.m script
tipload = [0.1, 0.2, 0.25, 0.42]; %[N]
meanvoltage = [0.0012, 0.0024, 0.0034, 0.0037]; %[V]
GF = 2; % Gage Factor
% The excitation voltage for each run is 5.0 V
Strains = meanvoltage./5*4/GF; % Estimated strain [m/m]
We can use the polyfit() function to fit a 1st order polynomial to the data. Please read the MATLAB documentation on using the polyfit() function. The results of the polyfit() function will provide you with experimentally derived values for your linear experimental model (m,b).
Once you have determined an empirical model (using polyfit()), you should be able to create one graph showing the following:
The data from the 10 runs with a known load (individual data points). Plot as red circles ('ro').
The linear fit of the data represented as a line. Plot as a red line ('r-').
The mathematical model from the prelab, represented as a black dashed line ('k--').
The strain for the mystery load. Plot as blue squares ('bs')
The x-axis of this figure should be load and the y-axis should be strain with appropriate units. Include a legend!
Here is a full example of a MATLAB script for linear regression:
% Linear Regression Example
% The "data" below is the fictitous measurements we are going to fit with a line.
tipload = [0 0.49 0.98 1.47 1.96 2.45]; % Tip force row vector [N]
meansignal = [68150 488200 879900 1333150 1658000 1916000]; % Time-avg. [V]
GF = 2; % Gage Factor
meanvoltage = meansignal/128/2^24*5;
Strains = meanvoltage./5*4/GF; % Estimated strain [m/m]
% Plot the measurements
figure(1); clf();
plot(tipload,Strains,'ro')
xlabel('Force [N]')
ylabel('Strain [m/m]')
% Fit a line (order 1) to the data
P = polyfit(tipload,Strains,1);
% Now evaluate the model at the known x points (this is our model prediction)
ForceVec = linspace(0,10,11)
StrainLinear = polyval(P,ForceVec)
% Add the model to our plot
% Plot the measurements
figure(1); clf();
plot(tipload,Strains,'o')
hold on
plot(ForceVec,StrainLinear,'r--')
xlabel('Force [N]')
ylabel('Strain [m/m]')
% Quantify the "goodness of fit" using the R-squared value
Rmatrix = corrcoef(tipload,Strains);
Rsquared = Rmatrix(2,1)^2;
% Add these evaluations of the model to the plot
title('Linear Fit Example');
msgR2 = ['Fit: R^2=' num2str(Rsquared)]
legend('Measurements',msgR2,'location','northwest');
% Plot experimental Model (from previous calculation)
figure(2); clf();
plot(tipload,Strains,'o')
hold on
plot(ForceVec,StrainLinear,'r--')
xlabel('Force [N]')
ylabel('Strain [m/m]')
%Plot mathematical Model (from prelab)
strainModel = P(1)*1.2*ForceVec;
%IMPORTANT NOTE: This is NOT a proper mathematical model of the system.
%Replace strainModel equation with mathematical model from the prelab: epsilon=F(x-l)h/(2EI)
plot(ForceVec,strainModel,'g','linewidth',2)
legend('Measurements',msgR2,'Model','location','northwest');