Arduino Thermostat Code Explanation
Libraries:
- Adafruit_LiquidCrystal: A library that extends the functionality of the standard LiquidCrystal library for LCD displays.
- Wire: Enables communication with I2C devices.
- Adafruit_Sensor and DHT_U: Libraries for working with the DHT temperature and humidity sensor.
- DHT.h: Includes the main DHT library.
Pin Definitions:
- DHTPIN: Pin to which the DHT sensor is connected (Pin 2).
- RELAY_PIN_5 and RELAY_PIN_6: Pins to which the relays controlling the heater are connected (Pins 4 and 6, respectively).
- DHTTYPE: Specifies the DHT sensor type (DHT11).
Variable Declarations:
- DHT_Unified dht(DHTPIN, DHTTYPE): Creates an instance of the DHT sensor.
- Adafruit_LiquidCrystal lcd(12, 11, 10, 9, 8, 7): Creates an instance of the LCD display.
Setup Function:
- Initializes serial communication.
- Sets the relay control pins as outputs.
- Initializes the DHT sensor.
- Initializes the LCD display with a welcome message.
Loop Function:
- Reads the temperature from the DHT sensor.
- Displays the temperature on the LCD.
- Controls the relays based on temperature conditions:
- If the temperature is below 69.8°F and relay 5 is not active, it turns on relay 5 for 4 seconds and sets relay5Active to true.
- If the temperature is above 73°F, it turns off relay 5 after a delay.
- If the temperature is between 73°F and 90°F and relay 6 is not active, it turns on relay 6 for 4 seconds and sets relay6Active to true.
- If the temperature is above 73°F, it turns off relay 6 after a delay.
Wiring Instructions:
- DHT Sensor: Connect the DHT sensor to Pin 2 on the Arduino.
- Remote Connections:
- Solder one wire to the on button positive terminal of the wireless remote controller circuit, and wire it to Pin 4 on the Arduino (RELAY_PIN_5).
- Solder another wire to the off button of the wireless remote circuit, and connect it to Pin 6 on the Arduino (RELAY_PIN_6).
- Solder one black wire to the ground of the wireless remote controller and connect it to the ground of the Arduino board.
- LCD Display: Connect the LCD display to the corresponding pins on the Arduino (12, 11, 10, 9, 8, 7).
- Power Supply: Power the Arduino using an external power supply.
- Heater Connections: Connect the relays to the corresponding control points on your diesel heater, ensuring proper isolation and safety measures.
(IMPORTANT! The controller must have the little 12v battery inside it to operate; if the battery dies, the thermostat turns nothing on since the remote cannot send enough signal to the diesel heater wired controller unit.) (these batteries can be ordered)
(side note: I understand this is probably not the proper way to wire this circuit, but I assure you I am no expert on doing circuitry; I am just a lowly tinkerer who needed heat to survive a freezing Michigan winter! the most affordable way possible)
Remember to double-check the specifications of your relays and diesel heater to ensure compatibility with the Arduino. Additionally, take appropriate safety precautions when working with electrical components. This code is a foundation, and you might need to tweak it based on your specific hardware and usage requirements.
Comments
Post a Comment