Hey all,
I've built myself a bldc motor out of an alternator and put together a tachometer using the arduino to monitor the rpm of the motor using one of the hall effect sensors that I built into the motor. The problem is that the arduino is not giving accurate measurement.
here is the video of the set up if you would like to see what I'm talking about:
you can see what I'm talking about at 5:40.
I've basically got it counting every edge that comes by the hall effect sensor inside of a second, multiplying that by 60, then dividing that by seven (seven poles on the rotor in a alternator.)
The information I get back is not correct, in that before it hits 1000 rpm, it shows between 0 and 3000, and before 6000 it does the same thing. so it basically counts from 0 to 3000 then switches to 1000 and counts up to 3000 again, then switches to 6000 and continues counting. this is when the motor is running. When just hooking it up to a button, it will count around 150 rps for one button press. I thought Maybe it was a bounce issue, but counting 150 from 1 button press is a lot of bounce.
Anyway here is the code, thanks!
#include <LiquidCrystal.h>
int uperdown = 0;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
unsigned long intMillTime = 0;
int alreadyUp = 0;
unsigned int RPS = 0;void setup() {
lcd.begin(16, 2);
pinMode(11, INPUT);
intMillTime = millis();
lcd.setCursor(0,0);
lcd.print("RPM:");
lcd.setCursor(8,0);
lcd.print("RPS:");
}void loop() {
//Timing
unsigned long intMillNow = millis();
unsigned long intTimeSpan = intMillNow - intMillTime;//after a second has passed, print rpm and rps, then set counter to 0, and intMillTime to now.
if (intTimeSpan > 1000) {
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(RPS*60/7);
lcd.setCursor(8,1);
lcd.print(RPS);
intMillTime = millis();
RPS = 0;
}//if rising edge, add to counter and set alreadyup so it doesn't run again.
uperdown = digitalRead(11);if (uperdown == HIGH) {
if (alreadyUp == 0) {
RPS = RPS + 1;
}
alreadyUp = 1;
}//if low keep alreadyup down
if (uperdown == LOW) {
alreadyUp = 0;}
}