I have hooked everything up per the last schematic and the fan works. It starts and stops within the Temp settings I have given it with one minor hiccup. When I power everything up the Temp code seems to run backwards with the high temp turning fans off and low temp turning them on, I can switch the alerts to make it run properly but I'm wondering if I have wired anything incorrectly to make it act that way.
#include <Wire.h> // Used to establish serial communication on the I2C bus
#include <SparkFun_TMP117.h> // Used to send and recieve specific information from our sensor
// The default address of the device is 0x48 (GND)
TMP117 sensor; // Initalize sensor
byte AlertFlag = 0; //variable to hold high and low alert flags from configuration register
boolean H_AlertFlag = 0; //variable to hold state of high alert flag
boolean L_AlertFlag = 0; //variable to hold state of low alert flag
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1500;
unsigned long startMillis2;
unsigned long currentMillis2;
const unsigned long period2 = 500;
void setup()
{
pinMode(13, OUTPUT);
Wire.begin();
Serial.begin(115200); // Start serial communication at 115200 baud
Wire.setClock(400000); // Set clock speed to be the fastest for better communication (fast mode)
if (sensor.begin() == true) // Function to check if the sensor will correctly self-identify with the proper Device ID/Address
{
Serial.println("Begin");
}
else
{
Serial.println("Device failed to setup- Freezing code.");
while (1);
}
sensor.setHighLimit(60); //set high limit to 25.50°C
sensor.setLowLimit(35 ); //set low limit to 25.00°C
sensor.setAlertFunctionMode(0);//set to alert mode
}
void loop()
{
if (sensor.dataReady() == true) // Function to make sure that there is data ready to be printed, only prints temperature values when data is ready
unsigned long currentMillis = millis();
{
currentMillis = millis();
if (currentMillis - startMillis >= period)
startMillis = currentMillis;
AlertFlag = sensor.getHighLowAlert(); //read the alert flags from the configuration register
H_AlertFlag = bitRead(AlertFlag, 1); //grab the high alert field using bitwise operator and save current to H_AlertFlag
L_AlertFlag = bitRead(AlertFlag, 0); //grab the low alert field using bitwise operator and save current L_AlertFlag
if (H_AlertFlag == true)
{
digitalWrite(13, HIGH);
}
else if (L_AlertFlag == true)
{
digitalWrite(13, LOW);
}
unsigned long currentMillis2 = millis();
{
currentMillis2 = millis();
if (currentMillis2 - startMillis2 >= period2)
startMillis2 = currentMillis2;
}
}
}