alright I adapted this code to work with an LCD and will add a second fan in the future. the problem I have is when the RPM drops below 1000. the readout keeps the characters to the left rather than the right. so 600rpm should be displayed "600" or even "0600" but rather is displayed "6000". and idea how to fix this? here's the code:
Code:
//code by Crenn from http://thebestcasescenario.com
//project by Charles Gantt from http://themakersworkbench.com
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
/*To disable interrupts:
cli(); // disable global interrupts
and to enable them:
sei(); // enable interrupts
*/
//Varibles used for calculations
int NbTopsFan;
int Calc;
//The pin location of the sensor
int hallsensor = 2;
typedef struct{ //Defines the structure for multiple fans and their dividers
char fantype;
unsigned int fandiv;
}fanspec;
//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};
char fan = 1; //This is the varible used to select the fan and it's divider, set 1 for unipole hall effect sensor
//and 2 for bipole hall effect sensor
void rpm () //This is the function that the interupt calls
{
NbTopsFan++;
}
//This is the setup function where the LCD is initialised,
//and the interrupt is attached
void setup()
{
pinMode(hallsensor, INPUT); //Sets RPM pin to input
lcd.begin(16, 2); //Set up the LCD's number of rows and columns
lcd.print(" diluzio91's "); //First line opening message
lcd.setCursor(0, 1);
lcd.print("Fan Control Cntr"); //Second line opening message
delay(5000); //Delay for opening message
lcd.setCursor(0, 1); //Clear bottom line
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print(" Fan 1 Fan 2 "); //Update top line readout
attachInterrupt(0, rpm, RISING);
}
void loop ()
{
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv); //Times NbTopsFan (which is apprioxiamately the fequency the fan is spinning at) by 60 seconds before dividing by the fan's divider
lcd.setCursor(0, 1);
lcd.print (Calc, DEC); //Prints the number calculated above
lcd.setCursor(4, 1);
lcd.print ("RPM"); //Prints " RPM"
}
Also, how would I go about adding in a second fan to this setup? And the reading seems to fluctuate a lot. at a steady rpm, it bounces between 1500rpm and 1200
and the setup:
