Welcome back to the second part of our DIY Diesel Heater Thermostat series! In this installment, we'll dive into the heart of the project—the Arduino code that transforms your heater into a smart, automated system. Feel free to explore, learn, and adapt this code to suit your needs. However, before we proceed, a stark reminder: use the code at your own risk, and I assume no responsibility for any consequences that may arise.
#include <Adafruit_LiquidCrystal.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2
#define RELAY_PIN_5 4
#define RELAY_PIN_6 6
#define DHTTYPE DHT11
DHT_Unified dht(DHTPIN, DHTTYPE);
Adafruit_LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
uint32_t delayMS;
bool relay5Active = false;
bool relay6Active = false;
void setup() {
Serial.begin(9600);
pinMode(RELAY_PIN_5, OUTPUT);
pinMode(RELAY_PIN_6, OUTPUT);
dht.begin();
sensor_t sensor;
dht.temperature().getSensor(&sensor);
delayMS = sensor.min_delay / 1000;
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("BrandoSoft");
lcd.setCursor(0, 0);
delay(5000);
lcd.print("v3.0 - 2023 ");
delay(5000);
lcd.setCursor(0, 0);
lcd.print("Temperature: ");
}
void loop() {
delay(delayMS);
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
lcd.setCursor(1, 1);
lcd.print("Error reading temp!");
} else {
lcd.setCursor(0, 1);
lcd.print(event.temperature * 1.8 + 32, 1);
lcd.print("F ");
if (event.temperature * 1.8 + 32 < 69.8 && !relay5Active) {
digitalWrite(RELAY_PIN_5, HIGH);
delay(4000);
digitalWrite(RELAY_PIN_5, LOW);
relay5Active = true;
} else if (event.temperature * 1.8 + 32 >= 73) {
relay5Active = false;
delay(3000);
}
if (event.temperature * 1.8 + 32 >= 73 && event.temperature * 1.8 + 32 <= 90 && !relay6Active) {
digitalWrite(RELAY_PIN_6, HIGH);
delay(4000);
digitalWrite(RELAY_PIN_6, LOW);
relay6Active = true;
} else if (event.temperature * 1.8 + 32 > 73) {
relay6Active = false;
delay(3000);
}
}
}
Cautionary Note: Before you delve into the code, please be aware of the following:
Use this code at your own risk: The provided Arduino code is intended for educational purposes, and any modifications or implementations are undertaken at your discretion. I am not liable for any damages, injuries, or adverse outcomes resulting from the use of this code. Ensure proper understanding and application of safety measures when dealing with electrical components and heating systems.
Feel free to copy and experiment with the code, but always prioritize safety. If you have any doubts or concerns, consult with experienced individuals or professionals before proceeding. Let's continue the journey of DIY innovation with caution and responsible exploration!
Comments
Post a Comment