4 - pin fan, rpm counter, lcd display

Hello.

I have a piece of code for a 12V fan running "through" a potentiometer to control its speed.

I would also like to have the RPM count displayed on my LCD. I have tried for three evening with youtube videos and googling. However, I have come up empty and have to turn to you geniuses for help.

My code works fine for the motor and I can print on the display.
I am not able to incorperate the built-in tachometer from the fan into my piece of code and display it.

Now this seems fairly straightforward - however I am stuck.

#include <LiquidCrystal.h>

// Motor Control Integers
int fan_control = 6;
int pot = A0;
int control1 = 0;
int control2 = 0;


// LCD Integers
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // Motor Control
  pinMode(fan_control, OUTPUT);
  pinMode(pot, INPUT);


  // LCD Screen
  Serial.begin(9600);
  lcd.begin(16, 2);
}


void loop() {

  // Motor Control
  control2 = analogRead(pot);
  control1 = 1024 - control2;

  digitalWrite(fan_control, HIGH);
  delayMicroseconds(control1);

  digitalWrite(fan_control, LOW);
  delayMicroseconds(control2);



  report();
}

void report(void) {
  static unsigned long lastReportMs = 0;
  if (millis() - lastReportMs < 250) {
    return;
  } else {
    lastReportMs = millis();
    // LCD Screen
    lcd.setCursor(4, 1);
    lcd.print("DC Motor");
  }
}

I am not even sure where to plug the tachometer (one wire), is it analog or is it a digital signal?'

Thank you for any help

Quick search on Google finds info stating that the tach signal is a 5V square wave.
That'd be a digital signal - ON/OFF with a frequency proportional to the fan speed.

"The tachometer signal, also known as "tach signal", and "FG signal", conveys rpm information in the form of square waves. The frequency of this square wave output is proportional to the rotation of the shaft. Usually, a high sensitivity hall-effect sensor detects the rotation of the shaft providing two pulses per rotation, where the North Pole generates a positive pulse and the South Pole a negative pulse. The output of the hall sensor is usually weak and not a square wave; hence, a differential amplifier amplifies it, and a Schmitt trigger provides the switching hysteresis to reshape it into a square wave.

The final tach signal is usually an open collector design that provides a square waveform output to the motherboard. The voltage levels are usually at TTL level (+5 V) through a pull up resistor and an open collector transistor, however, this is by no means a rule and there will be exceptions."

Hello.

I am working on a rpm counter for a 4 pin fan (built in tachometer, 2 pulses per rotation).

However, I am having trouble with my attachInterrupt command for my arduino to read the signal coming from the fan.

The fault message is that I have not declared the ISR
(attachInterrupt(digitalPinToInterrupt(pin), ISR, mode)`).

Could someone please point out the obvious for me? :smiley:

#include <LiquidCrystal.h>

// Motor Control Integers
int fan_control = 6;
int pot = A0;
int control1 = 0;
int control2 = 0;

volatile int output = LOW;




// LCD Integers
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);



void setup() {

  
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);


  pinMode(fan_control, OUTPUT);
  pinMode(pot, INPUT);

  pinMode(2, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(2), rpm, RISING);

}


void loop() {

  lcd.clear();
  lcd.print("RPM: ");
  lcd.print(rpm);
  delay(100);

  control2 = analogRead(pot);
  control1 = 1024 - control2;

  digitalWrite(fan_control, HIGH);
  delayMicroseconds(control1);

  digitalWrite(fan_control, LOW);
  delayMicroseconds(control2);

}

void count() {

  input = HIGH;
  rpm = 
}














ISR is function you have not defined. Somewhere you have to have:

void rpm()  {
// ...
}

See this:

there is also an example.

Thank you.

I have read on this but I was not able to put the two together.
Since I posted I created a void rpmVal and updated my code a bit.

However, it still does not agree with me.

#include <LiquidCrystal.h>

// Motor Control Integers
int fan_control = 6;
int pot = A0;
int control1 = 0;
int control2 = 0;

volatile int output = LOW;
//int rpmVal;



// LCD Integers
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);



void setup() {

  
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);


  pinMode(fan_control, OUTPUT);
  pinMode(pot, INPUT);

  pinMode(2, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(2), rpmVal, RISING);

}


void loop() {

  lcd.clear();
  lcd.print("RPM: ");
  lcd.print(rpm);
  delay(100);

  control2 = analogRead(pot);
  control1 = 1024 - control2;

  digitalWrite(fan_control, HIGH);
  delayMicroseconds(control1);

  digitalWrite(fan_control, LOW);
  delayMicroseconds(control2);

}

void rpmVal() {

  init = HIGH;
  rpm = (rpmVal * 60000. / 2.);
}














How do you know?

And what is rpmVal in this statement:

rpm = (rpmVal * 60000. / 2.);

You don't have init or rpm declared. You have rpmVal as the name of your ISR function and a variable.

You declare this and never use it.

Ok, thank you.

Therein lies my problem - I do not know what to declare them as, nor what the declaration means within the code.

You have also output with an error. We don't see it. There is a problem described by compiler.
Why do not try some of examples first ?

I'm not trying to be difficult but those are fundamental concepts. You need to review basic C++ concepts before moving forward.

@kezreux, please do not cross-post. Threads merged.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.