Components and supplies
DS18B20 temperature sensor
Arduino Mega 2560
20x4 i2c LCD Screen
Arduino 4 Relays Shield
Project description
Code
Arduino Relay and fan control - LCD
arduino
updated 03-Jan-2017
1#include <Wire.h> // 2#include <LCD.h> // 3#include <LiquidCrystal_I2C.h> // 4#include <OneWire.h> // 5#include <DallasTemperature.h> // 6//---------------------------------------------------------------------------------------------------------------------------------// 7#define ONE_WIRE_BUS 13 //sensor data pin // 8LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE); // 9OneWire oneWire(ONE_WIRE_BUS); // 10DallasTemperature sensors(&oneWire); // 11//---------------------------------------------------------------------------------------------------------------------------------// 12int sensor = 12; // sensor power pin (+) 13int tempMin = 22; // the temperature to start the fans 14int tempMax = 26; // the maximum temperature when fans are at 100% 15int tempOFF = 33; // the temperature to start the main power of amplifier 16int fanSpeed = 0; 17int fanLCD; 18int fan = 2; //fan speed PWM - connects to 1k resistor fan board 19int powerrelay = 3; //the ssr relay on the main power of amplifier 20int speakersrelay = 4; //the relay on the power of speaker protection board 21float tempC = 0; 22float tempF = 0; 23byte degree[8] = { B00010, B00101, B00010, B00000, B00000, B00000, B00000, B00000 }; 24byte percentage_1[8] = { B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000 }; 25byte percentage_2[8] = { B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000 }; 26byte percentage_3[8] = { B11100, B11100, B11100, B11100, B11100, B11100, B11100, B11100 }; 27byte percentage_4[8] = { B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110 }; 28byte percentage_5[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }; 29 30//-----------------------------------------------------------------------------------------// 31void setup(){ 32 sensors.begin(); 33 pinMode(2, OUTPUT); 34 pinMode(3, OUTPUT); 35 pinMode(4, OUTPUT); 36 pinMode(9, OUTPUT); 37 pinMode(12, OUTPUT); 38 Serial.begin(9600); 39 digitalWrite (sensor, HIGH); 40 lcd.begin (20,4); // lcd screen type 41 lcd.createChar(6, degree); 42 lcd.createChar(1, percentage_1); 43 lcd.createChar(2, percentage_2); 44 lcd.createChar(3, percentage_3); 45 lcd.createChar(4, percentage_4); 46 lcd.createChar(5, percentage_5); 47 lcd.setBacklight(HIGH); 48 lcd.setCursor(0,0); 49 lcd.print (" SYSTEM "); 50 lcd.setCursor(0,1); 51 lcd.print (" IS "); 52 lcd.setCursor(0,2); 53 lcd.print (" INITIALISING "); 54 lcd.setCursor(0,3); 55 for (int i=0; i<20; ++i ){for(int j=0; j<5;j++) 56 {lcd.setCursor(i,3); 57 lcd.write(j); 58 delay(10);}}} 59//-----------------------------------------------------------------------------------------// 60 61void loop(){ 62 sensors.requestTemperatures(); 63 tempC = sensors.getTempCByIndex(0); 64 tempF = sensors.toFahrenheit(tempC); 65 Serial.println(tempC,0); 66 if (tempC >= tempOFF){digitalWrite(speakersrelay,LOW); //this will cutoff the speakers protection boards ->no signal in speakers 67 delay(500); //delay half second 68 digitalWrite(powerrelay,LOW);} //cutt of main power of the amp. 69 else {digitalWrite(powerrelay,HIGH); 70 digitalWrite(speakersrelay,HIGH);} 71 72 delay(250); 73 lcd.setCursor(0,0); 74 lcd.print("AMPLIFIER MONITOR"); 75 lcd.print(" "); 76 lcd.setCursor(0,1); 77 lcd.print("Heatsink temp:"); 78 lcd.print(tempC,0); 79 lcd.write(6); 80 lcd.print("C"); 81 if(tempC < tempMin){ // if temp is lower than minimum temp 82 fanSpeed = 0; // fan is not spinning 83 lcd.setCursor (0,2); 84 lcd.print ("Fans not running"); 85 lcd.setCursor (0,3); 86 lcd.print ("ALL SYSTEMS GOOD!"); 87 lcd.print (" "); 88 digitalWrite(fan, LOW);} 89 90 if((tempC >= tempMin) && (tempC <= tempMax)) { //if temp is higher than the minimum range 91 fanSpeed = map(tempC, tempMin, tempMax, 32, 255); // the actual speed of fan 92 fanLCD = map(tempC, tempMin, tempMax, 0, 100); // speed of fan to display on LCD 93 lcd.setCursor(0,2); 94 lcd.print("Fans Speed:"); // display the fan speed 95 lcd.print(fanLCD); 96 lcd.print("%"); 97 lcd.print(" "); 98 lcd.setCursor (0,3); 99 lcd.print ("ALL SYSTEMS GOOD!"); 100 lcd.print (" "); 101 analogWrite(fan, fanSpeed);} // spin the fan at the fanSpeed speed 102 103 if (tempC > tempMax) { // if temp is higher than tempMax 104 lcd.setCursor (0,3); 105 lcd.print ("HIGH TEMP REACHED!"); 106 lcd.print (" "); 107 analogWrite(fan, 255); 108 fanLCD = 100; 109 lcd.setCursor(0,2); 110 lcd.print("Fans Speed:"); // display the fan speed 111 lcd.print(fanLCD); 112 lcd.print("%"); 113 lcd.print(" ");} 114 115 if (tempC >= tempOFF){ 116 lcd.setCursor (0,3); 117 lcd.print ("THERMAL THROTTLING!"); 118 lcd.print (" ");} 119 120 } 121 122
Arduino Relay and fan control - LCD
arduino
updated 03-Jan-2017
1#include <Wire.h> // 2#include <LCD.h> // 3#include <LiquidCrystal_I2C.h> // 4#include <OneWire.h> // 5#include <DallasTemperature.h> // 6//---------------------------------------------------------------------------------------------------------------------------------// 7#define ONE_WIRE_BUS 13 //sensor data pin // 8LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE); // 9OneWire oneWire(ONE_WIRE_BUS); // 10DallasTemperature sensors(&oneWire); // 11//---------------------------------------------------------------------------------------------------------------------------------// 12int sensor = 12; // sensor power pin (+) 13int tempMin = 22; // the temperature to start the fans 14int tempMax = 26; // the maximum temperature when fans are at 100% 15int tempOFF = 33; // the temperature to start the main power of amplifier 16int fanSpeed = 0; 17int fanLCD; 18int fan = 2; //fan speed PWM - connects to 1k resistor fan board 19int powerrelay = 3; //the ssr relay on the main power of amplifier 20int speakersrelay = 4; //the relay on the power of speaker protection board 21float tempC = 0; 22float tempF = 0; 23byte degree[8] = { B00010, B00101, B00010, B00000, B00000, B00000, B00000, B00000 }; 24byte percentage_1[8] = { B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000 }; 25byte percentage_2[8] = { B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000 }; 26byte percentage_3[8] = { B11100, B11100, B11100, B11100, B11100, B11100, B11100, B11100 }; 27byte percentage_4[8] = { B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110 }; 28byte percentage_5[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }; 29 30//-----------------------------------------------------------------------------------------// 31void setup(){ 32 sensors.begin(); 33 pinMode(2, OUTPUT); 34 pinMode(3, OUTPUT); 35 pinMode(4, OUTPUT); 36 pinMode(9, OUTPUT); 37 pinMode(12, OUTPUT); 38 Serial.begin(9600); 39 digitalWrite (sensor, HIGH); 40 lcd.begin (20,4); // lcd screen type 41 lcd.createChar(6, degree); 42 lcd.createChar(1, percentage_1); 43 lcd.createChar(2, percentage_2); 44 lcd.createChar(3, percentage_3); 45 lcd.createChar(4, percentage_4); 46 lcd.createChar(5, percentage_5); 47 lcd.setBacklight(HIGH); 48 lcd.setCursor(0,0); 49 lcd.print (" SYSTEM "); 50 lcd.setCursor(0,1); 51 lcd.print (" IS "); 52 lcd.setCursor(0,2); 53 lcd.print (" INITIALISING "); 54 lcd.setCursor(0,3); 55 for (int i=0; i<20; ++i ){for(int j=0; j<5;j++) 56 {lcd.setCursor(i,3); 57 lcd.write(j); 58 delay(10);}}} 59//-----------------------------------------------------------------------------------------// 60 61void loop(){ 62 sensors.requestTemperatures(); 63 tempC = sensors.getTempCByIndex(0); 64 tempF = sensors.toFahrenheit(tempC); 65 Serial.println(tempC,0); 66 if (tempC >= tempOFF){digitalWrite(speakersrelay,LOW); //this will cutoff the speakers protection boards ->no signal in speakers 67 delay(500); //delay half second 68 digitalWrite(powerrelay,LOW);} //cutt of main power of the amp. 69 else {digitalWrite(powerrelay,HIGH); 70 digitalWrite(speakersrelay,HIGH);} 71 72 delay(250); 73 lcd.setCursor(0,0); 74 lcd.print("AMPLIFIER MONITOR"); 75 lcd.print(" "); 76 lcd.setCursor(0,1); 77 lcd.print("Heatsink temp:"); 78 lcd.print(tempC,0); 79 lcd.write(6); 80 lcd.print("C"); 81 if(tempC < tempMin){ // if temp is lower than minimum temp 82 fanSpeed = 0; // fan is not spinning 83 lcd.setCursor (0,2); 84 lcd.print ("Fans not running"); 85 lcd.setCursor (0,3); 86 lcd.print ("ALL SYSTEMS GOOD!"); 87 lcd.print (" "); 88 digitalWrite(fan, LOW);} 89 90 if((tempC >= tempMin) && (tempC <= tempMax)) { //if temp is higher than the minimum range 91 fanSpeed = map(tempC, tempMin, tempMax, 32, 255); // the actual speed of fan 92 fanLCD = map(tempC, tempMin, tempMax, 0, 100); // speed of fan to display on LCD 93 lcd.setCursor(0,2); 94 lcd.print("Fans Speed:"); // display the fan speed 95 lcd.print(fanLCD); 96 lcd.print("%"); 97 lcd.print(" "); 98 lcd.setCursor (0,3); 99 lcd.print ("ALL SYSTEMS GOOD!"); 100 lcd.print (" "); 101 analogWrite(fan, fanSpeed);} // spin the fan at the fanSpeed speed 102 103 if (tempC > tempMax) { // if temp is higher than tempMax 104 lcd.setCursor (0,3); 105 lcd.print ("HIGH TEMP REACHED!"); 106 lcd.print (" "); 107 analogWrite(fan, 255); 108 fanLCD = 100; 109 lcd.setCursor(0,2); 110 lcd.print("Fans Speed:"); // display the fan speed 111 lcd.print(fanLCD); 112 lcd.print("%"); 113 lcd.print(" ");} 114 115 if (tempC >= tempOFF){ 116 lcd.setCursor (0,3); 117 lcd.print ("THERMAL THROTTLING!"); 118 lcd.print (" ");} 119 120 } 121 122
Downloadable files
Fan PWM output scheme
Fan PWM output scheme
Comments
Only logged in users can leave comments
makeeuropeanu
0 Followers
•0 Projects
Table of contents
Intro
15
0