Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 |
I decided to make this project in order to control a homemade amplifier. I have just one temperature sensor, DS18B20, but in the future I will use 4 of them to read the temperature of the heatsink in different places and make an average. I want to mention that I'm a beginner in arduino and this is my first project. I'm open to any suggestions. I have done a welcome screen and a loading bar for start-up sequence. After this I had programmed to close a relay on the main power source of the amplifier. You can see the heatsink temp on the LCD. At the DS gets hot, the speed of the fans it's shown on the lcd. When the temp is less than a minimum temp, it's shows "Fans not running". When a maximum temperature is reached, it's shuts the relay off, leaving the heatsink to get cooled back. I have used an led instead of a fan (this is what I have for the moment, but it's works, the led is fading up as the fan speed grows.
#include <Wire.h> //
#include <LCD.h> //
#include <LiquidCrystal_I2C.h> //
#include <OneWire.h> //
#include <DallasTemperature.h> //
//---------------------------------------------------------------------------------------------------------------------------------//
#define ONE_WIRE_BUS 13 //sensor data pin //
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE); //
OneWire oneWire(ONE_WIRE_BUS); //
DallasTemperature sensors(&oneWire); //
//---------------------------------------------------------------------------------------------------------------------------------//
int sensor = 12; // sensor power pin (+)
int tempMin = 22; // the temperature to start the fans
int tempMax = 26; // the maximum temperature when fans are at 100%
int tempOFF = 33; // the temperature to start the main power of amplifier
int fanSpeed = 0;
int fanLCD;
int fan = 2; //fan speed PWM - connects to 1k resistor fan board
int powerrelay = 3; //the ssr relay on the main power of amplifier
int speakersrelay = 4; //the relay on the power of speaker protection board
float tempC = 0;
float tempF = 0;
byte degree[8] = { B00010, B00101, B00010, B00000, B00000, B00000, B00000, B00000 };
byte percentage_1[8] = { B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000 };
byte percentage_2[8] = { B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000 };
byte percentage_3[8] = { B11100, B11100, B11100, B11100, B11100, B11100, B11100, B11100 };
byte percentage_4[8] = { B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110 };
byte percentage_5[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 };
//-----------------------------------------------------------------------------------------//
void setup(){
sensors.begin();
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(9, OUTPUT);
pinMode(12, OUTPUT);
Serial.begin(9600);
digitalWrite (sensor, HIGH);
lcd.begin (20,4); // lcd screen type
lcd.createChar(6, degree);
lcd.createChar(1, percentage_1);
lcd.createChar(2, percentage_2);
lcd.createChar(3, percentage_3);
lcd.createChar(4, percentage_4);
lcd.createChar(5, percentage_5);
lcd.setBacklight(HIGH);
lcd.setCursor(0,0);
lcd.print (" SYSTEM ");
lcd.setCursor(0,1);
lcd.print (" IS ");
lcd.setCursor(0,2);
lcd.print (" INITIALISING ");
lcd.setCursor(0,3);
for (int i=0; i<20; ++i ){for(int j=0; j<5;j++)
{lcd.setCursor(i,3);
lcd.write(j);
delay(10);}}}
//-----------------------------------------------------------------------------------------//
void loop(){
sensors.requestTemperatures();
tempC = sensors.getTempCByIndex(0);
tempF = sensors.toFahrenheit(tempC);
Serial.println(tempC,0);
if (tempC >= tempOFF){digitalWrite(speakersrelay,LOW); //this will cutoff the speakers protection boards ->no signal in speakers
delay(500); //delay half second
digitalWrite(powerrelay,LOW);} //cutt of main power of the amp.
else {digitalWrite(powerrelay,HIGH);
digitalWrite(speakersrelay,HIGH);}
delay(250);
lcd.setCursor(0,0);
lcd.print("AMPLIFIER MONITOR");
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Heatsink temp:");
lcd.print(tempC,0);
lcd.write(6);
lcd.print("C");
if(tempC < tempMin){ // if temp is lower than minimum temp
fanSpeed = 0; // fan is not spinning
lcd.setCursor (0,2);
lcd.print ("Fans not running");
lcd.setCursor (0,3);
lcd.print ("ALL SYSTEMS GOOD!");
lcd.print (" ");
digitalWrite(fan, LOW);}
if((tempC >= tempMin) && (tempC <= tempMax)) { //if temp is higher than the minimum range
fanSpeed = map(tempC, tempMin, tempMax, 32, 255); // the actual speed of fan
fanLCD = map(tempC, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
lcd.setCursor(0,2);
lcd.print("Fans Speed:"); // display the fan speed
lcd.print(fanLCD);
lcd.print("%");
lcd.print(" ");
lcd.setCursor (0,3);
lcd.print ("ALL SYSTEMS GOOD!");
lcd.print (" ");
analogWrite(fan, fanSpeed);} // spin the fan at the fanSpeed speed
if (tempC > tempMax) { // if temp is higher than tempMax
lcd.setCursor (0,3);
lcd.print ("HIGH TEMP REACHED!");
lcd.print (" ");
analogWrite(fan, 255);
fanLCD = 100;
lcd.setCursor(0,2);
lcd.print("Fans Speed:"); // display the fan speed
lcd.print(fanLCD);
lcd.print("%");
lcd.print(" ");}
if (tempC >= tempOFF){
lcd.setCursor (0,3);
lcd.print ("THERMAL THROTTLING!");
lcd.print (" ");}
}
Comments