-
Notifications
You must be signed in to change notification settings - Fork 1
/
Temperature_ExpLoRer.ino
51 lines (42 loc) · 1.15 KB
/
Temperature_ExpLoRer.ino
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
/* DeviceInfo_ExpLoRer.ino
*
* Get the onboard temperature reading from a Sodaq ExpLoRer board.
*
* @DefProc
*/
#define debugSerial SerialUSB
#define hwSerial Serial
#define btSerial Serial1
#define loraSerial Serial2
void setup()
{
debugSerial.begin(115200);
//hwSerial.begin(57600);
//btSerial.begin(57600);
loraSerial.begin(57600);
while ((!SerialUSB) && (millis() < 10000)) {
// Wait for SerialUSB or start after 10 seconds
}
debugSerial.println(F("Temperature ExpLoRer:"));
// use the onboard MCP9700AT analog output temperature sensor (on pin A6)
pinMode(TEMP_SENSOR, INPUT);
}
void loop()
{
// Vout from MCP9700AT is 10 mV/⁰C - 0.5V
// -10 to +125⁰C, ±1⁰C accuracy
float temp = -10.0;
// run 10 times quickly and take the maximum (for stability)
for (int i=0; i<10; i++) {
float mVolts = (float)analogRead(TEMP_SENSOR) * 3300.0 / 1023.0;
float new_temp = (mVolts - 500.0) / 10.0;
// save value if it's higher than is already recorded
if (new_temp > temp) {
temp = new_temp;
}
delay(10);
}
debugSerial.print(temp);
debugSerial.println(" ⁰C");
delay(900);
}