Raspberry Pi + MMA (9): Measuring the cooling of hot water using Vernier and LM73 sensor

 In Wolfram Community, Reading Temperature Sensors in the Wolfram Language On the RPi written by Emerson Willard is very interesting for me. This experiment uses the DS18B20 temperature sensors. On the other hand, Adding Vernier (analog) sensors to the Raspberry Pi written by BoB LeSuer gives me the MathLink program, "vernier". Then I am able to use the Vernier and the LM73 temperature sensor in this experiment. The data is saved to dropbox in the same way as one written by Emerson.

Hardware requirement & setup

1. Raspberry Pi   2. Go!Link interface   3. Vernier sensor  4. LM73 temperature sensor

Mathematica notebook

$MachineName
⇒ raspberrypi
(*  LM73 sensor  *)
SetDirectory["/home/pi/workLM73"];
getTemperature[] := (Run["./LM73.sh > tmp.dat"];
  First[ToExpression[Import["tmp.dat", "Lines"]]])
lm73Temp=Table[Pause[1.]; getTemperature[], {10}]
⇒ {7.6562,7.625,7.625,7.625,7.625,7.625,7.625,7.625,7.625,7.625}
meanLM73=Mean[lm73Temp]
⇒ 7.62812
(*  Vernier sensor  *)
link = Install["/home/pi/vernier/vernier"];
getDeviceInfo[]
⇒ Go! Link,1:6,10,Stainless Temp,(C)
vernierTemp =Table[Pause[2.0]; getSimpleMeasurement[], {10}]
⇒ {8.22137, 8.21277, 8.18702, 8.21707, 8.18016, 8.19159, 8.17339, \
   8.15843, 8.1653, 8.16072}
meanVernier = Mean[vernierTemp]
⇒ 8.18678
delta = meanVernier - meanLM73
⇒ 0.558664

For caliblation of sensors, the temperature at room is measured using the LM73 and Vernier, respectively. The record is 7.628 and 8.186 degrees Celsius, respectively. The difference is 0.56 degrees at 8 degrees, then this result shows an enough precision for this experiment.

Data were record every thirty seconds and uploaded every two minutes.

(* Setting for Dropbox upload  *)
upload[filesourcepath_, savedir_String] := 
  Run["/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload " <> 
    filesourcepath <> " " <> 
    FileNameJoin[{savedir, FileNameTake[filesourcepath]}]];
(*  Setting tasks  *)
file = "/home/pi/Desktop/temperaturedata.txt";
task1 = CreateScheduledTask[upload[file, "/za_RaspberryPi/temperaturexperiment"], 120];
task2 = CreateScheduledTask[
   PutAppend[{DateList[AbsoluteTime[]], getSimpleMeasurement[], getTemperature[]}, file], 30];
(*   Start tasks   *)
StartScheduledTask[{task1, task2}];
(*   Stop tasks   *)
StopScheduledTask[{task1, task2}];

Results

(*  Mac  *)
infile = "/Users/satouy/Dropbox/za_RaspberryPi/temperaturexperiment/temperaturedata.txt";
data = ToExpression[Import[infile, "Lines"]];
Short[data, 5]
⇒ {{2014,3,5,0,7,14.1673},79.4693,7.9062},
  {{2014,3,5,0,7,44.1593},78.5191,7.9687},<<1254>>,
  {{2014,3,5,10,42,57.2543},7.44058,7.1562}}
data1 = DeleteCases[data[[All, {1, 2}]], {x__, y_} /; y < 1.0 || y >= 90];
data2 = DeleteCases[data[[All, {1, 3}]], {x__, y_} /; y < 1.0];
grf = DateListPlot[{data1, data2}, Joined -> False, PlotRange -> {0, 90}]
The blue and purple line is the temperature of water and room, respectively.

Summary

  • It was possible to measure the temperature of the hot water and room for about 10 hours using two temperature sensors.
  • The ScheduleTaskObject function of Mathematica is useful for this experiment.
  • The data were able to transfer to Dropbox from Raspberry Pi.

go to Table of contents