I am reading a 12V PC fan's RPM, the signal is connected to an arduino pin and to +5v via a 10K pullup resistor. this is the code i am using:
const int rpmPin = 2;
void setup() {
Serial.begin(9600);
pinMode(rpmPin, INPUT);
}
void loop() {
unsigned long interval = pulseIn(rpmPin, HIGH) + pulseIn(rpmPin, LOW);
int RPS = 1000000UL / interval; // Pulses per second
int RPM = RPS*60;
Serial.println(RPM);
}
ok this is working ok, but now i need to read the rpm from 4 different fans, through a parallel in-serial out shift-register CD4021B and i have no idea where to start... any help will be appreciated.
You may find that an interrupt driven implementation would be best, you only have 4 inputs.
Ray
well, in fact i will be connecting some other things aside from the fans... i need to control also 4 water pumps, read 4 flow sensors (they work the same as the fans, so i need to read the pulses too), and some other things. (some buttons, sensors etc).
i have tried reading RPM of just one fan using interrupts, but the problem with this is (as far as i know) i have to use delay() or millis() and this blocks program execution... and also, i have no idea if i can use interrupts through a shift register...
KenTF:
Are you really that desperate for input pins? The implementation would be far simpler without the shift register and cheaper too.
yes I am... my project involves many other devices too... i was hoping i would be able to connect everything with daisy-chained shift registers (one chain for inputs with CD4021B registers, one chain for outputs with 74HC595 registers)