Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
double thresholdTemp = 30;
float threshold=1;
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 8;
int delayLevel=200;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
DDRB |= (1<<1);
DDRB |= (1<<3);
mlx.begin();
}
// the loop routine runs over and over again forever:
void loop() {
delay(1000);
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF());
Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");
Serial.println();
float objectTemp = mlx.readObjectTempC();
float ambientTemp = mlx.readAmbientTempC();
float ambientMin=ambientTemp-threshold;
float ambientMax=ambientTemp+threshold;
if (objectTemp >= ambientMax) {
turnOffColors();
digitalWrite(led, HIGH); // RED
Serial.println("Above.\n");
}
if ((objectTemp < ambientMax) && (objectTemp >= ambientMin)){
turnOffColors();
PORTB |= (1<<3); // GREEN
Serial.println("Mid.\n");
}
if (objectTemp < ambientMin){
turnOffColors();
PORTB |= (1<<1); // BLUE
Serial.println("Below.\n");
}
}
void turnOffColors() {
digitalWrite(led, LOW);
PORTB &= ~(1<<3);
PORTB &= ~(1<<1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.