Arduino + Hall effect sensor (measuring speed of rotation)

Using Hall effect sensor we can measure the speed of rotation.
RPM (Revolutions per minute) – the number of revolutions per minute. Revolutions per minute – a unit of measurement of rotational speed: the number of complete rotations made ??by the body (shaft, wheel, pulley, etc.) around a fixed axis. Used to describe the speed of rotation of the mechanical components in the mechanisms and machines.

Connect the Hall sensor to the Arduino is shown in figure 1 (S (data) -> pin 2, GND -> Arduino GND, VCC -> Arduino + 5V, the resistor 1 k ).

hall-sensor
Figure 1 – Connecting a digital Hall sensor to Arduino

To measure the speed of rotation on the drive must be mounted magnet that affect the Hall sensor after each complete turn of the disc. Thus, after each turn of the drive get momentum, which can be interpreted as one turn.
The program for the Arduino, which reads the Hall sensor displays and counts the number of revolutions per minute and the frequency of rotation. In the presence of a magnetic field is switched on the LED.



// read RPM

volatile int rpmcount = 0;//see http://arduino.cc/en/Reference/Volatile
int rpm = 0;
unsigned long lastmillis = 0;

void setup(){
Serial.begin(9600);
attachInterrupt(0, rpm_fan, FALLING);//interrupt cero (0) is on pin two(2).
}

void loop(){

if (millis() - lastmillis == 1000){ /*Uptade every one second, this will be equal to reading frecuency (Hz).*/

detachInterrupt(0); //Disable interrupt when calculating

rpm = rpmcount * 60; /* Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use rpmcount * 30.*/

Serial.print("RPM =\t"); //print the word "RPM" and tab.
Serial.print(rpm); // print the rpm value.
Serial.print("\t Hz=\t"); //print the word "Hz".
Serial.println(rpmcount); /*print revolutions per second or Hz. And print new line or enter.*/

rpmcount = 0; // Restart the RPM counter
lastmillis = millis(); // Uptade lasmillis
attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
}
}

void rpm_fan(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
rpmcount++;
}

hall




Оставить ответ

Обязательные поля помечены*

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.