0% found this document useful (0 votes)
4 views3 pages

Code For Heat Transfer Project

This document contains an Arduino code for a heat exchanger system that measures inlet and outlet temperatures, calculates flow rate, and computes energy transfer. It utilizes various libraries for temperature sensing and LCD display, and includes functionalities to control a relay based on energy transfer. The code also features serial output for detailed calculations and displays relevant data on an I2C LCD.

Uploaded by

shatharajab8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Code For Heat Transfer Project

This document contains an Arduino code for a heat exchanger system that measures inlet and outlet temperatures, calculates flow rate, and computes energy transfer. It utilizes various libraries for temperature sensing and LCD display, and includes functionalities to control a relay based on energy transfer. The code also features serial output for detailed calculations and displays relevant data on an I2C LCD.

Uploaded by

shatharajab8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <OneWire.

h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// I2C LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Pins
#define ONE_WIRE_BUS 2
#define FLOW_SENSOR_PIN 3
#define RELAY_PIN 7

// Temperature sensors
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempSensor1, tempSensor2;

// Flow sensor
volatile int pulseCount = 0;
float flowRate = 0;
unsigned long oldTime = 0;

// Constants
const float calibrationFactor = 4.5;
const float Cp = 4186; // J/kg°C
const float waterDensity = 1.0; // kg/L

// Variables
float tempInlet = 0;
float tempOutlet = 0;
float deltaT = 0;
float energyTransfer = 0; // in Watts

void setup() {
Serial.begin(9600);
sensors.begin();
lcd.init();
lcd.backlight();

if (!sensors.getAddress(tempSensor1, 0)) Serial.println("Sensor 1 not found");


if (!sensors.getAddress(tempSensor2, 1)) Serial.println("Sensor 2 not found");

pinMode(FLOW_SENSOR_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_PIN), countPulse, RISING);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW); // Relay off initially
lcd.setCursor(0, 0);
lcd.print("Heat Exchanger");
delay(2000);
lcd.clear();
lcd.setCursor(0, 1);

void loop() {
static unsigned long lastFlowTime = 0;
static unsigned long lastTempReadTime = 0;

unsigned long currentTime = millis();

// Read temperatures every 2 seconds


if (currentTime - lastTempReadTime >= 2000) {
sensors.requestTemperatures();
tempInlet = sensors.getTempC(tempSensor1);
tempOutlet = sensors.getTempC(tempSensor2);
deltaT = tempOutlet - tempInlet;
lastTempReadTime = currentTime;
}

// Flow rate calculation every second


if (currentTime - lastFlowTime > 1000) {
detachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_PIN));
flowRate = ((1000.0 / (currentTime - lastFlowTime)) * pulseCount) / calibrationFactor;
float flowRateLps = flowRate / 60.0;
lastFlowTime = currentTime;
pulseCount = 0;

// Energy calculation
energyTransfer = Cp * waterDensity * flowRateLps * deltaT;

// Serial Output: Detailed Calculation


Serial.println("=== Energy Calculation ===");
Serial.print("Inlet Temp: "); Serial.print(tempInlet); Serial.println(" °C");
Serial.print("Outlet Temp: "); Serial.print(tempOutlet); Serial.println(" °C");
Serial.print("Delta T: "); Serial.print(deltaT); Serial.println(" °C");
Serial.print("Flow Rate: "); Serial.print(flowRate); Serial.println(" L/min");
Serial.print("Flow Rate (L/s): "); Serial.print(flowRateLps, 4); Serial.println(" L/s");
Serial.print("Cp (specific heat): "); Serial.print(Cp); Serial.println(" J/kg°C");
Serial.print("Water density: "); Serial.print(waterDensity); Serial.println(" kg/L");
Serial.print("Power (Cp * rho * Q * dT): ");
Serial.print(Cp); Serial.print(" * ");
Serial.print(waterDensity); Serial.print(" * ");
Serial.print(flowRateLps, 4); Serial.print(" * ");
Serial.print(deltaT); Serial.print(" = ");
Serial.print(energyTransfer); Serial.println(" W");
Serial.println("==========================\n");

// LCD Display
displayOnLCD(tempInlet, tempOutlet, flowRate, energyTransfer);

// Control relay based on energy transfer


if (energyTransfer > 0) {
digitalWrite(RELAY_PIN, HIGH);
} else {
digitalWrite(RELAY_PIN, LOW);
}

attachInterrupt(digitalPinToInterrupt(FLOW_SENSOR_PIN), countPulse, RISING);


}
}

void displayOnLCD(float inlet, float outlet, float flow, float power) {


lcd.setCursor(0, 0);
lcd.print("In: ");
lcd.print(inlet, 1);
lcd.print(" Out:");
lcd.print(outlet, 1);

lcd.setCursor(0, 1);
lcd.print("F:");
lcd.print(flow, 1);
lcd.print(" ; ET = ");
lcd.print(energyTransfer, 0);

void countPulse() {
pulseCount++;
}

You might also like