-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTemp_datalogging.txt
72 lines (55 loc) · 1.71 KB
/
Temp_datalogging.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*Temperature Sensing/Datalogging with the TMP36 */
#include <FileIO.h>
int tempPin = A0; //Reading from analog pin 0
void setup()
{
pinMode(tempPin,INPUT); //Setting analog pin to Input
Bridge.begin();
FileSystem.begin();
Serial.begin(9600);//Starting communication with serial monitor at baud rate 9600
while(!Serial);
}
void loop()
{
String dataString;
dataString += getTimeStamp();
dataString += " = ";
float TempF = tempRead();
dataString += String(TempF);
File dataFile = FileSystem.open("/mnt/sd/datalog.txt", FILE_APPEND);
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
else {
Serial.println("error opening datalog.txt");
}
delay(10000);
}
float tempRead()
{
float reading = analogRead(tempPin); //1-Taking in values through the A/D converter from 0 to 1023
float voltage = reading*(5.0/1024.0); //2-Multiplying reading by voltage step size to get voltage
float TempC = (voltage*100.0)-50.0; //3-Plugging voltage into sensor-specific formula to get temperature in degrees Celsius
float TempF = (1.8*TempC)+32.0; //4-Converting degrees Celsius to Fahrenheit
return TempF;
}
String getTimeStamp() {
String result;
Process time;
// date is a command line utility to get the date and the time
// in different formats depending on the additional parameter
time.begin("date");
time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy
// T for the time hh:mm:ss
time.run(); // run the command
// read the output of the command
while (time.available() > 0) {
char c = time.read();
if (c != '\n')
result += c;
}
return result;
}