Reading RPm from 3 wire fan.


greetings guys.

i need reading rpm 3 wire 12v 1.3a fan.

the problem rpm reading @ constant 0.

here lies code.

code: [select]
int potpin = 0;                           // analog pin 0 connected potentiometer
const int transistorpin = 9;                  // connected digital pin 9 base of transistor
int potvalue = 0;                       // value returned potentiometer
int nbtopsfan; int calc;              //variables used calculations

//the pin location of sensor
int hallsensor = 2; typedef struct {

  //defines structure multiple fans and
  //their dividers
  char fantype;
  unsigned int fandiv;
} fanspec;

//definitions of fans
//this variable used select fan , it's divider
//set 1 unipole hall effect sensor
// , 2 bipole hall effect sensor
fanspec fanspace [3] = {{0, 1}, {1, 2}, {2, 8}}; char fan = 1;

void rpm()
//this function interupt calls
{
  nbtopsfan++;
}

//this setup function serial port initialised
//and interrupt attached


void setup() {                          // set  transistor pin output

  pinmode(transistorpin, output);
  pinmode(hallsensor, input);
  serial.begin(9600);
  attachinterrupt(0, rpm, rising);

}


void loop() {                           // read potentiometer, convert between 0 - 255 value accepted digital pin.
  potvalue = analogread(potpin) / 4;    // potvalue alters supply pin 9 in turn controls power running through transistor
  analogwrite(9, potvalue);
  nbtopsfan = 0;

  //enables interrupts
  sei();

  //wait 1 second
  delay(1000);

  //disable interrupts
  cli();

  //times nbtopsfan (which approximately frequency fan
  //is spinning at) 60 seconds before dividing fan's divider
  calc = ((nbtopsfan * 60) / fanspace[fan].fandiv);

  //prints number calculated above
  serial.print (calc, dec);

  //prints "rpm" , new line
  serial.print(" rpm\r\n");

}


here's how hook up


where did go wrong? :smiley-confuse:

pinmode(hallsensor, input_pullup);


Arduino Forum > Using Arduino > Project Guidance > Reading RPm from 3 wire fan.


arduino

Comments