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?'
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."