Not much action here but I've been making baby steps:
//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;
int ledPin = 4; //$STUFF I ADDED$
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);
pinMode(ledPin, OUTPUT); ////$STUFF I ADDED$$
}
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
//$STUFF I ADDED$/////////////////////////////////////////////////////////////////////////////
if (Calc > 40)
{
digitalWrite (4, HIGH);
delay (500);
}
if (Calc < 40)
{
digitalWrite (4, LOW);
}
}
I didn't do much but I am getting serial output of RPM to the serial monitor and I'm getting a single LED to turn ON/OFF with RPM changes. My RPM measurement doesn't seem to be accurate but it is proportional so I figure I can tinker with the code to get it working. I guess the numbers really don't matter as long as I can get the output to register correctly. I'm not going to be using the serial data anyway.
I did get the hall effect sensor working after learning that I needed a resistor between the pos and signal
Just one sad little LED for output but it's a start:
No little magnets to mount on my test rig so I'm stuck waving a big one over the HE sensor for now... I considered using a PC fan 3rd wire for input but I want to stick with what I'm going to use in the final build so I don't complicate things.
Would someone mind explaining what's going on in the code? Especially this line:
fanspec fanspace[3]={{0,1},{1,2},{2,8}};
Thanks.
More stuff:
//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;
int ledPin = 4; //$STUFF I ADDED$
int ledPin1 = 5;
int ledPin2 = 6;
int ledPin3 = 7;
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);
pinMode(ledPin, OUTPUT);////$STUFF I ADDED$$
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
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
//$STUFF I ADDED$/////////////////////////////////////////////////////////////////////////////
if (Calc > 40)
{
digitalWrite (4, HIGH);
delay (100);
}
if (Calc < 40)
{
digitalWrite (4, LOW);
}
if (Calc > 100)
{
digitalWrite (5, HIGH);
delay(100);
}
if (Calc < 100)
{
digitalWrite (5, LOW);
}
//////
if (Calc > 240)
{
digitalWrite (6, HIGH);
delay(100);
}
if (Calc < 240)
{
digitalWrite (6, LOW);
}
/////
if (Calc > 300)
{
digitalWrite (7, HIGH);
delay(100);
}
if (Calc < 300)
{
digitalWrite (7, LOW);
}
}
It's clunky but it seems to work!
Also, If all goes well, (And it looks like it very well may :)) I would like to do a permanent install. I don't want to use my UNO for it but rather build a bare bones chip setup. Any input on this? I suppose I would at least need a crystal as well as a power supply. Would be neat to (Try to) build!