Cómo leer las revoluciones de un ventilador con Arduino

Aquí les dejo un interesante artículo que muestra cómo leer las revoluciones de un ventilador de PC mediante su pin de RPM. El método es muy sencillo ya que básicamente consiste en utilizar una interrupción para saber cuándo el ventilador da una vuelta y luego simplemente contar. El auto a añadido un pequeño display LED de 7 segmentos para visualizar las revoluciones.

Código fuente

# Include "SevenSegment.h" 

 SevenSegment seg7(19,16,15,13, // ?1,?2,?3,?4, SevenSegment seg7 (19,16,15,13, / / 1 digit, 2 digit, 3 digit, 4 digit 
 18,14,11,9,8,17,12,10); // A,B,C,D,E,F,G,DP 18,14,11,9,8,17,12,10); / / A, B, C, D, E, F, G, DP 

 unsigned long lastPulseTime; unsigned long lastPulseTime; 
 unsigned long pulseInterval; unsigned long pulseInterval; 

 // ???????????????? / / Falling edge detection pulse rotation 
 void senseRotation( void ) { void senseRotation (void) ( 
 unsigned long cur = micros (); unsigned long cur = micros (); 
 unsigned long dif = cur - lastPulseTime; // ?????????? unsigned long dif = cur - lastPulseTime; / / difference between the previous edge 
 pulseInterval = (pulseInterval - (pulseInterval >> 2)) + (dif >> 2); // ???? pulseInterval = (pulseInterval - (pulseInterval>> 2)) + (dif>> 2); / / smooth 
 lastPulseTime = cur; lastPulseTime = cur; 
 } ) 

 void setup () { void setup () ( 
 lastPulseTime = 0; lastPulseTime = 0; 
 pulseInterval = 0; pulseInterval = 0; 
 attachInterrupt (0, senseRotation, FALLING ); // 0 = D2, FALLING = ????? attachInterrupt (0, senseRotation, FALLING); / / 0 = D2, FALLING = falling 
 seg7. begin (); // 7??LED???? seg7. begin (); / / 7 LED segment begins operation 
 } ) 

 unsigned long lastUpdateTime; unsigned long lastUpdateTime; 

 void loop () { void loop () ( 
 if (seg7. update ()){ // ??????????????????????????? if (seg7. update ()) (/ / called at short intervals as possible, so do dynamic lighting control 
 unsigned long cur = millis (); unsigned long cur = millis (); 
 if (cur - lastUpdateTime > 60){ // 60ms???LED??? if (cur - lastUpdateTime> 60) (/ / 60ms update interval LED 

 uint16_t rpm = 60000000 / (pulseInterval * 2); // RPM???? uint16_t rpm = 60000000 / (pulseInterval * 2); / / RPM find 
 seg7. print (rpm); // 7??LED???? seg7. print (rpm); / / 7 LED segment display update 

 lastUpdateTime = cur; lastUpdateTime = cur; 
 } ) 
 } ) 
 } )

Deja un comentario