1602 LCD and reading out RPM fan

Hi all,

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 code for now is:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

void setup(){
  lcd.begin(16,2);
}

void loop(){
  lcd.setCursor(0,0);
  lcd.print("Fan1");
  lcd.setCursor(4,0);
  lcd.print("Fan2");
  lcd.setCursor(8,0);
  lcd.print("Fan3");
  lcd.setCursor(12,0);
  lcd.print("Fan4");
  lcd.setCursor(0,2);
  lcd.print("%1");
  lcd.setCursor(4,2);
  lcd.print("%2");
  lcd.setCursor(8,2);
  lcd.print("%3");
  lcd.setCursor(12,2);
  lcd.print("%4");
}

The Fan1,2,3,4 text should become the rpm.

thanx in advance!

Hi ProAce,

Do you mean that the code that calculates the rpm uses pin 2 because that pin has interrupt capability? How will you connect the other five fans?

You can use (almost) any pins to drive the lcd. Just pick a different one.

Paul

PaulRB:
Do you mean that the code that calculates the rpm uses pin 2 because that pin has interrupt capability?

Hope not, using interrupts would be a very bad idea!

In the meantime, we await ProAce’s further explanation.

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 :stuck_out_tongue:

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.

Have a look at pulseIn().

Use the slowest fan speed to calculate your timout.

Would you be able to help me with the code reading out the rpm with PulseIn() on the analog in pins? I can't figure it out

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

I have no clue of that, I don't have a scope. All I know is that I have a PWM fan which runs at 2200 rpm on 12V.

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?

I used this code:

int pin = 7;
unsigned long duration;

void setup()
{
  pinMode(pin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  duration = pulseIn(pin, HIGH);
  Serial.print(duration,DEC);
}

And this is what comes in the serial monitor:

08971718390700000093559378936993809380937893909368938293739376937793789363938193789384937893789389938193819377938693689374937793859382937393769381938293659382938993919380938193769380935793779372936893819380937793779391939193829374937893809382937793809385938493849374938293819386938193829380938093959394940293979385938693909391938894079397939193889384939393869393939593909399938893779406939393939390939493829381939493949406938193919395939793819384938693979399939593869385938493939398939193949405939893989390938893909385939593769388939394019391940593959378939193959394939093849406939993919395938994039395939393989271939994079402941494099409940393989395939394119406939793939378937293709378939193889364937393859369938093849384937493599381937493819378938293709384937793829384938493819385940393819381941094019374939193809394937693909370938193729382938493909374938193899382938693739385938993789360938193869381936893779373938093789391937793729381938193769363938093789401938493789394939493899384938993829382939193849382937693779385937693789377938893849420941894379440944794459439945194609452945394499449944593779373937294119399935594059431940694099409931394649411942493809385937793918366940993829389938293939385938193789365938993809377937793889380937893709391937693829380939193859378939393809378938193909377937693749380936893849367938093709374938193829381937893809391938493789370937493949372937293699381938093559378937793579377937893779462934893699372931593579368937093689363936793649363935293659373935993659369936793599355936493819368936593729370936593679373937393739361937793689373937393749374937793779384939193819378937393949382937793819389937493779374937393649384937293789380937093939391937493809376938600288190949063911264249893686834412757823143337456835270206740647473986791606043041891115965330867118170744970876840754166545902405916744235586136223136244461868456734071270313835743308483021099314946665220512744113296165499358000019109904142149251136340366014687167006505571843592644411589257393267206244459270956994302291566124655975422769549761148534123505415337849084139201946053514933942521113965401179355732245151333823509900610064111598967196858635657774487266089737736055365529540049721409593444913475447287638464580421531216335706275357953698471542451081456116799206532468244280847025723586655504602329814486150537923765705390516659073372190549641320541631613802445311650421141544519335655108211158298007105390781775337139603981328722865956133528323135710409439759553723513518045449370411364737742533716915648258157393437548239244030427721164508984689495488894450691356516417585210215052282576530729975285339749393819371541392047432444972284718600494791951321267530616255478203655722463562328675653329156993634513538954191415127444355111445462254694594490710515051147451401902519123255216273452403199505236623651405216574344458838248457875073120752741644547621275600264756253124564634965214383441344114269143454560306475769448911078505015665146196452052419523528795214335046603809307741451064433018591165000000000000000000000000000000000000000

Well, that's a little tricky to interpret! I suggest you read my last suggestion again, carefully!

A sorry, so I changed it:

int pin = A0;
unsigned long duration;

void setup()
{
  pinMode(pin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  duration = pulseIn(pin, HIGH);
  Serial.println(duration);
}

And this came out at 12V 2200 rpm:

6742
7172
6727
7159
6727
7158
6734
7158
6748
7158
6727
7158
6727
7171
6727
7165
6732
7159
6734
7158
6742
7158
6728
7173
6742
7172
6742
7158
6748
7172
6748
7173
6728
7172
6742
7171
6728
7172
6734
7158
6735
7158
6727
7158
6727
7158
6728
7158
6734
7173
6748
7171
6743
7172
6727
7159
6742
7150
6732
7171
6745
7171
6742
7172
6740
7172
6742
7173
6756
7172
6728
7159
6763
7173
6748
7173
6743
7156
6742
7173
6742
7158
6728
7156
6734
7173
6734
7158
6727
7172
6742
7173
6742
7152
6748
7159
6734
7172
6742
7158
6727
7158
6740
7155
6748
7159
6735
7159
6743
7156
6727
7171
6727
7158
6732
7156
6747
7169
6727
7158
6727
7158
6727
7142
6734
7143
6734
7158
6728
7158
6740
7172
6727
7156
6734
7156
6745
7158
6727
7156
6740
7156
6742
7155
6731
7156
6744
7154
6740
7159
6727
7171
6742
7172
6749
7172
6748
7172
6742
7186
6740
7185
6742
7172
6740
7173
6742
7172
6748
7172
6747
7158
6728
7158
6728
7159
6728
7146
6721
7159
6734
7144
6727
7143
6711
7144
6734
7144
6719
7143
6728
7159
6728
7143
6734
7144
6719
7143
6726
7143
6726
7144
6734
7158
6732
7156
6740
7159
6728
0
7159
6714
7159
6728
7159
6728
7159
6735
7144
6734
7156
6727
7156
6727
7158
6726
7156
6747
7158
6734
7159
6742
7158
6728
7159
6740
7173
6749
7159
6748
7159
6727
7172
6728
7173
6743
7151
6745
7158
6748
7158
6727
7171
6740
7158
6727
7172
6728
7173
6748
7160
6749
7159
6742
7173
6728
7158
6743
7167
6734
7172
6734
7159
6727
7156
6742
7159
6742
7158
6734
7159
6748
7144
6728
7158
6727
7144
6727
7159
6735
7143
6732
7156
6727
7143
6727
7158
6735
7159
6748
7158
6727
7173
6743
7159
6727
7151
6735
7159
6734
7158
6742
7158
6726
7158
6742
7158
6734
7158
6734
7158
6727
7158
6727
7158
6727
7156
6745
7156
6732
7158
6727
7144
6727
7139
6721
7144
6734
7143
6726
7144
6727
7144
6734
7159
6732
7143
6726
7143
6728
7141
6734
7143
6718
7142
6709
7141
6713
7143
6719
7142
6713
7143
6727
7142
6732
7144
6719
7129
6710
7126
6713
7129
6718
7143
6714
7130
6700
7129
6719
7130
6713
7143
6700
7130
6721
7116
6706
7130
6700
7130
6717
7141
6719
7130
6714
7130
6706
7130
6719
7130
6713
7129
6700
7130
6721
7131
6713
7130
6700
7130
6721
7130
6713
7129
6713
7144
6719
7143
6700
7131
6714
7131
6706
7131
6698
7129
6713
7130
6721
7130
6705
7130
6711
7130
6705
7130
6721
7130
6714
7131
6714
7130
6706
7130
6714
7130
6714
7116
6705
7130
6715
7130
6714
7130
6719
7144
6711
7131
6711
7129
6719
7144
6721
7146
6714
7146
6728
7130
6721
7143
6714
7130
6713
7130
6721
7131
6722
7146
6715
7131
6714
7146
6721
7131
6714
7144
6714
7139
6706
7133
6715
7130
6728
7144
6734
7144
6721
7144
6701
7144
6714

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.

Al the fans are Identical. How am i gonna get the two durations and add them together?

ProAce:
How am i gonna get the two durations and add them together?

Can you please rephrase the question?

Yeah sorry, I'm a 15 year old dutch student, so my english is not that well.

How can I get the two outputs (pulse 1 and pulse 2) and add those numbers together. So that the formula will be: (Max rpm*(pulse1+pulse2))/duration.

Nevermind that. You will have to manually calibrate the code for a specticular fan.

Are you saying the pulse lengths are significantly different between fans at the same rpm?

Your English is quite good. Better than some native English-speakers on this forum! 100% better than my Dutch!

What I meant is that if I'm ever going to use other fans, I will have to calibrate the formula to them.

College is really paying of than :P

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 ().

ProAce: College is really paying of than :P

Sorry, don't understand.

Not all the fans that I use are 2200 rpm :wink:
But thanx, I have worked it out now and it works :slight_smile: