Pages: 1 2 [3]   Go Down
Author Topic: reading rpm signal from cpu fan  (Read 10633 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok I finally got this working with the help of a friend. I have posted it on my site

//Code by Crenn from

//Varibles used for calculations
int NbTopsFan;
int Calc;
char counter;
char flag;
unsigned long time[2];

//The pin location of the sensor
int hallsensor = 2;

//Defines the structure for multiple fans and their dividers
typedef struct{
  char fantype;
  unsigned int fandiv;

//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 0;   //This is the variable used to select the fan and it's divider, set 1 for unipolar hall effect sensor
               //and 2 for bipolar hall effect sensor

//This is the function that the interupt calls
void rpm()
   if (counter == 0)
   if (counter == 100){
      cli();            //Disable interrupts

//This is the setup function where the serial port is initialised,
//and the interrupt is attached
void setup()
 pinMode(hallsensor, INPUT);
 attachInterrupt(0, rpm, RISING);
void loop ()
   NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
   sei();            //Enables interrupts
   Calc = (((60*100)/(time[1]-time[0]))/fanspace[fan].fandiv);
   Serial.print (Calc, DEC); //Prints the number calculated above
   Serial.print (" rpm\r\n"); //Prints " rpm" and a new line

Pages: 1 2 [3]   Go Up
Jump to: