Oneslowz28
06-07-2010, 06:11 AM
http://thebestcasescenario.com/oneslowz28/front_page/tutorials/arduinofantut1.pngBy Charles Gantt ( Oneslowz28 )
Part 1: Outputting Fan RPM to the serial console
What you will need:
1x 3 wire PC fan
1x external 12v Power supply (PC PSU)
1x 10k resistor (http://www.protostack.com/index.php?main_page=product_info&cPath=14_31&products_id=37)
1x Seeeduino or Arduino compatible dev board (http://www.seeedstudio.com/depot/seeeduino-v212-fully-assembled-arduino-compatible-p-389.html?cPath=27).
Jumper Wires (http://www.seeedstudio.com/depot/premium-jumper-wires-140-pcsbox-p-394.html?cPath=34)
1x breadboard (http://www.seeedstudio.com/depot/bread-board-clear-8262-cm-p-262.html?cPath=60_5)
http://themakersworkbench.com/sites/default/files/images/Fan_RPM_Arduino_0.jpg
This is pretty simple to hook up. First you need to run the Signal wire (almost always yellow) to the breadboard. Then from it connect a jumper wire to Arduino Digital Pin 2. Also from the sensor wire you need to connect a 10k resistor to the Arduino's 5V pin. This is a simple pull-up resistor. We also need to make sure that we connect the fans ground line to one of the Arduino's ground pins. Next just connect the fans power wire to the PSUs 12v line and the fans ground wire to the PSUs ground.
Now upload the following code to your Arduino, and then open the serial terminal. Again I would like to thank Crenn for his help with the code.
//code by Crenn from http://thebestcasescenario.com
//project by Charles Gantt from http://themakersworkbench.com
/*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 serial port is initialised,
//and the interrupt is attached
void setup()
{
pinMode(hallsensor, INPUT);
Serial.begin(9600);
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
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" rpm\r\n"); //Prints " rpm" and a new line
}
You should see an RPM output in the serial terminal. It is accurate within 10-15 RPM of the fans actual RPM which is close enough for me. If your RPM output seems to be double what it should be your fan may have a bipolar Hall efect sensor and its counting each pass of the magnets pole as a single RPM when each should be 1/2 an RPM. No worries though as this is an easy fix. Just simply change the " char fan = 0 code from 0 to 1. Upload the modified code and you should be seeing accurate RPM numbers. Check IGA Catalogue (https://www.catalogueau.com/iga/) and ALDI Catalogue (https://www.catalogueau.com/aldi/).
My fritzing page on this project. (Download all the files there)
Reading PC Fan / Water Pump RPM with an Arduino (http://fritzing.org/projects/reading-pc-fan-rpm-with-an-arduino/)
Part 1: Outputting Fan RPM to the serial console
What you will need:
1x 3 wire PC fan
1x external 12v Power supply (PC PSU)
1x 10k resistor (http://www.protostack.com/index.php?main_page=product_info&cPath=14_31&products_id=37)
1x Seeeduino or Arduino compatible dev board (http://www.seeedstudio.com/depot/seeeduino-v212-fully-assembled-arduino-compatible-p-389.html?cPath=27).
Jumper Wires (http://www.seeedstudio.com/depot/premium-jumper-wires-140-pcsbox-p-394.html?cPath=34)
1x breadboard (http://www.seeedstudio.com/depot/bread-board-clear-8262-cm-p-262.html?cPath=60_5)
http://themakersworkbench.com/sites/default/files/images/Fan_RPM_Arduino_0.jpg
This is pretty simple to hook up. First you need to run the Signal wire (almost always yellow) to the breadboard. Then from it connect a jumper wire to Arduino Digital Pin 2. Also from the sensor wire you need to connect a 10k resistor to the Arduino's 5V pin. This is a simple pull-up resistor. We also need to make sure that we connect the fans ground line to one of the Arduino's ground pins. Next just connect the fans power wire to the PSUs 12v line and the fans ground wire to the PSUs ground.
Now upload the following code to your Arduino, and then open the serial terminal. Again I would like to thank Crenn for his help with the code.
//code by Crenn from http://thebestcasescenario.com
//project by Charles Gantt from http://themakersworkbench.com
/*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 serial port is initialised,
//and the interrupt is attached
void setup()
{
pinMode(hallsensor, INPUT);
Serial.begin(9600);
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
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" rpm\r\n"); //Prints " rpm" and a new line
}
You should see an RPM output in the serial terminal. It is accurate within 10-15 RPM of the fans actual RPM which is close enough for me. If your RPM output seems to be double what it should be your fan may have a bipolar Hall efect sensor and its counting each pass of the magnets pole as a single RPM when each should be 1/2 an RPM. No worries though as this is an easy fix. Just simply change the " char fan = 0 code from 0 to 1. Upload the modified code and you should be seeing accurate RPM numbers. Check IGA Catalogue (https://www.catalogueau.com/iga/) and ALDI Catalogue (https://www.catalogueau.com/aldi/).
My fritzing page on this project. (Download all the files there)
Reading PC Fan / Water Pump RPM with an Arduino (http://fritzing.org/projects/reading-pc-fan-rpm-with-an-arduino/)