CK Tan
Published © GPL3+

Copy Of Fidget Spinner RPM Counter

Arduino Project: How to make a Fidget Spinner RPM counter with Hall-effect sensor.

BeginnerWork in progress2 hours8,294
Copy Of Fidget Spinner RPM Counter

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Resistor 221 ohm
Resistor 221 ohm
×3
LED (generic)
LED (generic)
×3
hall effect sensor
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fidget Spinner RPM Counter Circuit Diagram

Code

code

Arduino
#include <LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);
const int hallSensorPin = 2;                      // connect the hall effect sensor on pin 2
const unsigned long sampleTime = 1000;
const int maxRPM = 1260;                  // maximum RPM for LCD Bar
int rpmMaximum = 0;

void setup() 
{
  pinMode(hallSensorPin,INPUT);
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.print("Initializing");
  delay(1000);
  lcd.clear();
  lcd.print("Welcome to Fidget Spinner RPM Counter");
  for (int positionCounter = 0; positionCounter < 21; positionCounter++) {
    lcd.scrollDisplayLeft();
    delay(350);
  }
  delay(1000);
  lcd.clear();
}

void loop() 
{
  delay(100);
  int rpm = getRPM();
  if (rpm > rpmMaximum) rpmMaximum = rpm;
  lcd.clear();
  displayRPM(rpm);
  displayBar(rpm);
  
}
 
int getRPM()
{
  int count = 0;
  boolean countFlag = LOW;
  unsigned long currentTime = 0;
  unsigned long startTime = millis();
  while (currentTime <= sampleTime)
  {
    if (digitalRead(hallSensorPin) == HIGH)
    {
      countFlag = HIGH;
    }
    if (digitalRead(hallSensorPin) == LOW && countFlag == HIGH)
    {
      count++;
      countFlag=LOW;
    }
    currentTime = millis() - startTime;
  }
  int countRpm = int(60000/float(sampleTime))*count;
  return countRpm;
}
    
void displayRPM(int rpm) 
{
  lcd.clear();
  lcd.setCursor(0, 0); 
  lcd.print(rpm,DEC);
  lcd.setCursor(7,0);
  lcd.print(rpmMaximum, DEC);
  lcd.setCursor(13,0);
  lcd.print("MAX");
  Serial.print("RPM = ");
  Serial.print(rpm);
  Serial.print("  MAX RPM = ");
  Serial.println(rpmMaximum);
}

void displayBar(int rpm)
{
  int numOfBars=map(rpm,0,maxRPM,0,15);
  lcd.setCursor(0,1);
  if (rpm!=0)
  {
  for (int i=0; i<=numOfBars; i++)
   {
        lcd.setCursor(i,1);
        lcd.write(1023);
      }
  }
} 

Credits

CK Tan

CK Tan

0 projects • 1 follower
Thanks to Andriy Baranov.

Comments