presssureSensor.m - MAE221/Thermodynamics-Lab GitHub Wiki
clear all
% Enter your photon name
name = 'Photon Name';
% Enter the unique access token for your Photon
atoken = 'Access Token';
% Enter the port your Photon is connected to. If you have trouble with
% this, leave it blank and the Photon will connect via the Cloud (though
% much slower than the port)
port = 'Port';
% Change it to the analog pin connected to the sensor output (A0 to A5)
read_pin = 'A5';
% change the value here to the resistance you are using.
Resistance_1 = 10000;
Resistance_2 = 10000;
vIn = 4.8;
pMax = 34473.8;
pMin = -34473.8;
g = Photon(name, atoken, port);
% Enter true if you are using a serial connection and false if you are using a cloud connection. If you having issues, just put false.
isUsingSerial = true;
if isUsingSerial
g.disconnect;
end
Pressure_atmosphere = 101325; %Pa, or 14.696 psi
Run_No = 5;
Pressure = zeros(1,Run_No);
for i = 1:Run_No
disp('Please exhale (or inhale)')
pause(2)
v_Read = g.analogRead(read_pin);
vOut = v_Read/Resistance_2 * (Resistance_1 + Resistance_2);
pressureApp = transferFunction(vIn, vOut, pMin, pMax);
Pressure(i) = pressureApp;
if i < Run_No
disp('Finish reading signals, prepare for next run in 10 sec')
pause(10)
else
disp('Finish reading signals')
end
end
% The measured data is saved in Pressure.
disp('The measurement results are (unit: Pa):')
disp(Pressure)
plot(1:Run_No, Pressure, 'ro')
xlabel('Runs', 'Fontsize',16)
ylabel('Pressure', 'Fontsize',16)
%% OUR CODE
% This function will take in the input voltage, output voltage, minimum
% pressure, and maximum pressure and output the pressure difference
% detected.
function pressureDiff = transferFunction(vIn, vOut, pMin, pMax)
pressureDiff = pMin + (pMax-pMin)/0.8 * (vOut/vIn - 0.1);
end