Skip to content

Commit 4ba078a

Browse files
committed
Finished emissivity example
1 parent 96853bc commit 4ba078a

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed

examples/Example1_Get_ID/Example1_Get_ID.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void setup()
4343
String(therm.getIDH(), HEX) +
4444
String(therm.getIDL(), HEX));
4545
}
46+
Serial.println(String(therm.readEmissivity()));
4647
}
4748

4849
void loop()

examples/Example2_Get_Temperature/Example2_Get_Temperature.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ void loop()
6464
Serial.println();
6565
}
6666
digitalWrite(LED_BUILTIN, LOW);
67-
delay(500);
67+
delay(1000);
6868
}

examples/MLX90614_Set_Emissivity/MLX90614_Set_Emissivity.ino renamed to examples/Example3_Set_Emissivity/Example3_Set_Emissivity.ino

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,56 +42,65 @@ SparkFun IR Thermometer Evaluation Board - MLX90614
4242

4343
IRTherm therm; // Create an IRTherm object to interact with throughout
4444

45-
const byte LED_PIN = 8; // Optional LED attached to pin 8 (active low)
46-
4745
float newEmissivity = 0.98;
4846

4947
void setup()
5048
{
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.");
5557
therm.setUnit(TEMP_F); // Set the library's units to Farenheit
58+
pinMode(LED_BUILTIN, OUTPUT); // LED pin as output
5659

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()) ;
6066

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+
}
6786
}
6887

6988
void loop()
7089
{
71-
setLED(HIGH); //LED on
72-
90+
digitalWrite(LED_BUILTIN, HIGH);
91+
7392
// Call therm.read() to read object and ambient temperatures from the sensor.
7493
if (therm.read()) // On success, read() will return 1, on fail 0.
7594
{
7695
// Use the object() and ambient() functions to grab the object and ambient
7796
// temperatures.
7897
// They'll be floats, calculated out to the unit you set with setUnit().
7998
Serial.print("Object: " + String(therm.object(), 2));
80-
Serial.write('°'); // Degree Symbol
8199
Serial.println("F");
82100
Serial.print("Ambient: " + String(therm.ambient(), 2));
83-
Serial.write('°'); // Degree Symbol
84101
Serial.println("F");
85102
Serial.println();
86103
}
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);
97106
}

0 commit comments

Comments
 (0)