makeeuropeanu
Published © GPL3+

Fan Controlled By DS18B20 Temperature Sensor With 20x4 LCD

I have started to build it for a homemade amplifier, to set the speed of the fans by the temp of the heathsink and so on.

BeginnerWork in progress26,615
Fan Controlled By DS18B20 Temperature Sensor With 20x4 LCD

Things used in this project

Story

Read more

Schematics

Fan PWM output scheme

Code

Arduino Relay and fan control - LCD

Arduino
updated 03-Jan-2017
#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 (" ");}

            }

Credits

makeeuropeanu

makeeuropeanu

1 project • 4 followers

Comments