2023-04-11 09:43:38 +02:00
|
|
|
|
2023-04-13 15:54:58 +02:00
|
|
|
#define FAN_PIN 9 // D9
|
|
|
|
#define L_LED_PIN 13 // D13
|
2023-04-11 09:43:38 +02:00
|
|
|
|
|
|
|
#define BMP280_I2C_ADDRESS 0x76 // BMP280 conneciton: D1 = SCL; D2 = SDA
|
|
|
|
|
|
|
|
// minimum value to start both fan's is 110
|
|
|
|
// without queeking noise is 255
|
2023-04-13 15:54:58 +02:00
|
|
|
#define FAN_ON_TEMP 26.0
|
|
|
|
#define FAN_OFF_MAX_TEMP 24.5
|
2023-04-11 09:43:38 +02:00
|
|
|
|
|
|
|
#define FAN_ON_STATE HIGH
|
|
|
|
#define FAN_OFF_STATE LOW
|
|
|
|
|
2023-04-13 15:54:58 +02:00
|
|
|
#define BMP280_CHECK_INTERVAL_MS 2000 // every 60000 = 60 seconds
|
2023-04-11 09:43:38 +02:00
|
|
|
|
|
|
|
float bmp280_temp = -99.9;
|
|
|
|
uint32_t bmp280_lastcheck_millis = BMP280_CHECK_INTERVAL_MS;
|
|
|
|
|
|
|
|
uint8_t fan_state = LOW;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
// put your setup code here, to run once:
|
|
|
|
|
|
|
|
// setup serial
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
// setup BMP280
|
|
|
|
Serial.println("Sensor BMP280 init status: " + String(sensor_bmp280_begin(BMP280_I2C_ADDRESS)));
|
|
|
|
bmp280_temp = sensor_bmp280_temperature();
|
|
|
|
|
|
|
|
// setup FAN Pin
|
|
|
|
pinMode(FAN_PIN, OUTPUT);
|
|
|
|
|
|
|
|
pinMode(L_LED_PIN, OUTPUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// put your main code here, to run repeatedly:
|
|
|
|
|
|
|
|
if ((bmp280_lastcheck_millis + BMP280_CHECK_INTERVAL_MS) <= millis())
|
|
|
|
{
|
|
|
|
bmp280_temp = sensor_bmp280_temperature();
|
|
|
|
Serial.println("Temperature: " + String(bmp280_temp) + "°C");
|
|
|
|
digitalWrite(L_LED_PIN, HIGH);
|
|
|
|
|
|
|
|
if (fan_state > 0 && bmp280_temp <= FAN_OFF_MAX_TEMP)
|
|
|
|
{
|
|
|
|
fan_state = FAN_OFF_STATE; // off
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bmp280_temp >= FAN_ON_TEMP)
|
|
|
|
{
|
|
|
|
fan_state = FAN_ON_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.println("FAN state: " + String(fan_state));
|
|
|
|
|
2023-04-13 15:54:58 +02:00
|
|
|
digitalWrite(FAN_PIN, fan_state);
|
2023-04-11 09:43:38 +02:00
|
|
|
|
|
|
|
digitalWrite(L_LED_PIN, LOW);
|
|
|
|
|
|
|
|
bmp280_lastcheck_millis = millis();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|