Calculate RPM with Hall effect Sensor

How does it work?
The Hall Effect sensor works on the principle of Hall Effect. According to which, whenever a magnetic field is applied in a direction perpendicular to the flow of electric current in a conductor, a potential difference is induced. This voltage can thus be used to detect whether the sensor is in the proximity of a magnet or not. The arduino can detect this voltage change through its interrupt pin and determine whether the magnet is near the sensor or not. The basic working of the Arduino hall effect sensor can be described as shown:


Hall effect sensors have three pins: VCC(5V), GND and Vout(Signal). The pin out of a hall effect sensor is as shown above.

Step 1: Connections for the Arduino Hall Effect Sensor


Interfacing the hall effect sensor with Arduino is really simple. The VCC of the sensor is connected to Arduino’s 5V power pin. The GND of the sensor is connected to the GND pin of Arduino. And the Vout or Signal pin of the hall effect sensor is connected to Arduino’s interrupt pin (digital pin 2). Furthermore, a 10K resistor is connected between the VCC and Vout pins of the hall effect sensor. This is done to pull the output of the hall effect sensor to 5V. The connections are done as shown below (the side having the printed number is facing towards you in the diagram):
Arduino code to detect the RPM:
 volatile byte half_revolutions;
 unsigned int rpm;
 unsigned long timeold;
 void setup()
 {
   Serial.begin(115200);
   attachInterrupt(0, magnet_detect, RISING);//Initialize the intterrupt pin (Arduino digital pin 2)
   half_revolutions = 0;
   rpm = 0;
   timeold = 0;
 }
 void loop()//Measure RPM
 {
   if (half_revolutions >= 20) { 
     rpm = 30*1000/(millis() - timeold)*half_revolutions;
     timeold = millis();
     half_revolutions = 0;
     //Serial.println(rpm,DEC);
   }
 }
 void magnet_detect()//This function is called whenever a magnet/interrupt is detected by the arduino
 {
   half_revolutions++;
   Serial.println("detect");
 }

Arduino Hall sensor pin out DIY Hacking



Comments

Popular posts from this blog

LCD/LED TV FLASH BIOS / EPROM programming with Serial Flash Memory - W25Q32FV

Sony Bravia 55" Double image / Image Flickering ( CKV - Clock Vertical Signal ) LED Panel Repairing