@@ -42,56 +42,65 @@ SparkFun IR Thermometer Evaluation Board - MLX90614
42
42
43
43
IRTherm therm; // Create an IRTherm object to interact with throughout
44
44
45
- const byte LED_PIN = 8 ; // Optional LED attached to pin 8 (active low)
46
-
47
45
float newEmissivity = 0.98 ;
48
46
49
47
void setup ()
50
48
{
51
- Serial.begin (9600 ); // Initialize Serial to log output
52
- Serial.println (" Press any key to begin" );
53
- while (!Serial.available ()) ;
54
- therm.begin (); // Initialize thermal IR sensor
49
+ Serial.begin (115200 ); // Initialize Serial to log output
50
+ Wire.begin (); // Join I2C bus
51
+
52
+ if (therm.begin () == false ){ // Initialize the MLX90614
53
+ Serial.println (" Qwiic IR thermometer did not acknowledge! Freezing!" );
54
+ while (1 );
55
+ }
56
+ Serial.println (" Qwiic IR thermometer acknowledged." );
55
57
therm.setUnit (TEMP_F); // Set the library's units to Farenheit
58
+ pinMode (LED_BUILTIN, OUTPUT); // LED pin as output
56
59
57
- // Call setEmissivity() to configure the MLX90614's
58
- // emissivity compensation:
59
- therm.setEmissivity (newEmissivity);
60
+ Serial.println ();
61
+ Serial.println (" Please enter the emissivity you would like to set the thermometer to." );
62
+ Serial.println (" The emissivity of human skin is 0.98." );
63
+ Serial.println (" Valid emissivity values are between 0.1 and 1.0." );
64
+
65
+ while (!Serial.available ()) ;
60
66
61
- // readEmissivity() can be called to read the device's
62
- // configured emissivity -- it'll return a value between
63
- // 0.1 and 1.0.
64
- Serial.println (" Emissivity: " + String (therm.readEmissivity ()));
65
- pinMode (LED_PIN, OUTPUT); // LED pin as output
66
- setLED (LOW); // LED OFF
67
+ if (Serial.available ()){
68
+ float newEmissivity = 0 ;
69
+ newEmissivity = Serial.parseFloat ();
70
+
71
+ // Edge-case gaurds
72
+ if (newEmissivity < 0.1 )
73
+ newEmissivity = 0.1 ;
74
+ else if (newEmissivity > 1.0 )
75
+ newEmissivity = 1.0 ;
76
+
77
+ // Call setEmissivity() to configure the MLX90614's
78
+ // emissivity compensation:
79
+ therm.setEmissivity (newEmissivity);
80
+
81
+ // readEmissivity() can be called to read the device's
82
+ // configured emissivity -- it'll return a value between
83
+ // 0.1 and 1.0.
84
+ Serial.println (" Emissivity: " + String (therm.readEmissivity ()));
85
+ }
67
86
}
68
87
69
88
void loop ()
70
89
{
71
- setLED ( HIGH); // LED on
72
-
90
+ digitalWrite (LED_BUILTIN, HIGH);
91
+
73
92
// Call therm.read() to read object and ambient temperatures from the sensor.
74
93
if (therm.read ()) // On success, read() will return 1, on fail 0.
75
94
{
76
95
// Use the object() and ambient() functions to grab the object and ambient
77
96
// temperatures.
78
97
// They'll be floats, calculated out to the unit you set with setUnit().
79
98
Serial.print (" Object: " + String (therm.object (), 2 ));
80
- Serial.write (' °' ); // Degree Symbol
81
99
Serial.println (" F" );
82
100
Serial.print (" Ambient: " + String (therm.ambient (), 2 ));
83
- Serial.write (' °' ); // Degree Symbol
84
101
Serial.println (" F" );
85
102
Serial.println ();
86
103
}
87
- setLED (LOW);
88
- delay (500 );
89
- }
90
-
91
- void setLED (bool on)
92
- {
93
- if (on)
94
- digitalWrite (LED_PIN, LOW);
95
- else
96
- digitalWrite (LED_PIN, HIGH);
104
+ digitalWrite (LED_BUILTIN, LOW);
105
+ delay (1000 );
97
106
}
0 commit comments