Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

motor rpm measurement using hall effect sensor

Place one small magnet on the hub of the motor or any rotating part. Place the hall effect sensor at about 1 to 2 mm distance from the magnet. Tune the refsig value(usually =((max_raw value+min_raw value)/2)). ta da!

code is here. https://github.com/animeshshastry/motor-rpm-measurement-using-hall-effect-sensor

or use ctrl+c and ctrl+v for the following:

 //this code measures the difference between two rising edges of the digitalised signal coming from hall sensor and then prints the rpm.
 //pin A0 is the signal pin
 int refsig = 200; //for converting the analog signal coming from hall sensor to digital through arduino code
 int val;//the digital value of the incoming analog signals
 int prev_val = 0;
 int t, cur_t; //time variables
 void setup()
 {
   Serial.begin(115200);
   pinMode(A0, INPUT);
 }
 void loop()//Measure RPM
 {
   int sig = analogRead(A0); //read raw value of hall sensor
   if (sig > refsig) val = HIGH; //convert it to digital 0,1 form
   else val = LOW;
   if (prev_val == 0 && val == 1) { //check for rising edge
     cur_t = micros();
     Serial.println(1000000 * 60 / (cur_t - t)); //print the rpm
     t = micros();
   }
   prev_val = val;
 }