I want to display on a 1602 lcd the rpm of six CM JetFlo's (feeded by the pc).
I have found a way to read out the rpm out of the tacho wire (third wire) but it uses the 2 pin.
This pin is also in use by the lcd.
So I want to read out the rpm with the A0 to A5 pin.
But I can't find any way to do this, so do you have suggestions?
The problem is that the sketch I use for now, uses the 2 - pin of the arduino.
Because of me wanting to use more fans I want to use the A0 to A5 pin to read out the rpm.
But I don't know how, so that's the biggest problem
For now I have it working so far: (rpm on pin 2)
#include <LiquidCrystal.h>
volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
LiquidCrystal lcd (12,11,7,6,5,4);
void setup()
{
Serial.begin(9600);
attachInterrupt(0, rpm_fun, RISING);
half_revolutions = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
if (half_revolutions >= 20) {
rpm = 30*1000/(millis() - timeold)*half_revolutions;
timeold = millis();
half_revolutions = 0;
if (rpm >1000){
lcd.setCursor(0,0);
lcd.print(rpm,DEC);
}
if (rpm <1000){
lcd.setCursor(1,0);
lcd.print(rpm,DEC);
lcd.setCursor(0,0);
lcd.print(" ");
}
if (rpm == 0){
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(3,1);
lcd.print("0");
}
}
}
void rpm_fun()
{
half_revolutions++;
//Each rotation, this interrupt function is run twice
}
There are only 2 pins you can use like that for interrputs on an Uno. There is a library that allows more interrupt pins, but this may not be the best way to approach the problem.
Yes, you can use most analog pins as digital inputs. pulsein() waits for a pulse and returns the length of it in microseconds. It seems from your sketch that the fans give 2 pulses per revolution, but we don't know for what part of a revolution the pulse lasts. Have you any information on this?
For example if a pulse lasts one quarter of a revolution, and pulseIn() retuns a value of 5000us, we can calculate the rpm as 60 × 1000000 / ( 4 × 5000 ) = 3000
ProAce:
All I know is that I have a PWM fan which runs at 2200 rpm on 12V.
Ok, great. So to calibrate, connect the fan to 12V and write a short sketch that gets a reading from pulseIn () and sends the result to the Serial Monitor with Serial.println (). What values do you see?
Look very consistent, which is good. However, it does show that the two pulses per revolution are slightly different lengths, so it will be important to always measure the pulses in pairs and use the total of the two answers.
Are all your fans identical? Try one or two more to see if there is much difference in the readings, using that sketch.
The total of a pair of readings comes to around 14,000us (I'll leave you to do a more accurate calculation) and this corresponds to 2200rpm. So to translate any pulse reading into rpm, multiply 2200 × 14000 and divide by the pulse reading. For example if a pair of pulse readings comes to 28000, rpm would be 2200×14000/28000 = 1100.
ProAce:
What I meant is that if I'm ever going to use other fans, I will have to calibrate the formula to them.
You could program the Arduino to self calibrate. Attach a pushbutton to the Arduino. Code your sketch so that when you set all fans to 12V/2200rpm and press the button, the Arduino measures a pair of pulses from each fan and stores these calibration values in its eeprom. These values can then be read back from eeprom in setup ().