Hi all,
I am not a programmer just a useless Electronics Technician (Hardware). Just wondering if anyone out there would be able to sort out a Program I put together the will display Temp of a Heatsink, the PWM output to the Cooling Fan and the RPM Reading from the Hall Effect Sensor in the Fan for a Power Supply.
The Temp & Fan PWM works fine (a little bit of tweaking left to do), but when I include the Enable & Disable Interrupt lines, the Display is Blank.
Monitoring just the HES works fine on the display. It only when I try to incorporate it with the rest of the Code is where the problem lies.
Here is the Code and Many Thanks to whoever can help
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
int tempPin = A1; // the output pin of LM35
int fans = 11; // the pin where fan is
//int led = 8; // led pin
int temp;
int tempMin = 20; // the temperature to start the fan
int tempLow = 30; // the temperature where fan increases speed
int tempMax = 70; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
int NbTopsFan; //Varibles used for calculations
int Calc;
int hallsensor = 2; typedef struct{ //The pin location of the sensor
char fantype; //Defines the structure for multiple fans and their dividers
unsigned int fandiv; }fanspec;
//int readTemp;
fanspec fanspace[3]={{0,1},{1,2},{2,8}}; char fan = 1; // 1 for unipole hall effect sensor or 2 for bipole hall effect sensor
void rpm ()
{ NbTopsFan++; } //This is the function that the interupt calls
void setup() {
pinMode(fans, OUTPUT);
//pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
pinMode(hallsensor, INPUT);
attachInterrupt(0, rpm, RISING); }
void loop() {
temp = readTemp(); // get the temperature
if(temp < tempMin) { fanSpeed = 0; digitalWrite(fan, LOW); }
if((temp >= tempMin) && (temp < tempLow)) { fanSpeed = 50; fanLCD = 20; }
if((temp >= tempLow) && (temp <= tempMax)) { fanSpeed = map(temp, tempLow, tempMax, 12, 255); fanLCD = map(temp, tempLow, tempMax, 0, 100); analogWrite(fan, fanSpeed); }
if(temp > tempMax) { digitalWrite(fan, HIGH); // turn on led
} // else { digitalWrite(led, LOW);
//}
lcd.setCursor(0,0);
lcd.print("TEMP");
lcd.setCursor(0,1);
lcd.print(temp); // display the temperature
lcd.print((char)0xdf);
lcd.print("C");
lcd.setCursor(6,0); // move cursor to next line
lcd.print("FANS");
lcd.setCursor(6,1);
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
lcd.setCursor(12,0);
lcd.print("RPM");
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
//sei(); //Enables interrupts
//delay (1000);
//cli(); //Disable interrupts
Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
lcd.setCursor(12,1);
lcd.print (Calc, DEC);
delay(200);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return temp * 0.48828125;
}
Regards Steve