For my Senior Physics project due June 7th, I am making a tachometer using Arduino, a 3144 Hall-effect switch, and a 16x02 i2C LCD.
I have the wiring as,
5v ---> VCC
GND ---> GND
D2 ---> Vout
a resister of 10K Ohms is placed on my breadboard between VCC and Vout.
and for the LCD
5v ---> VCC
GND ---> GND
SDA ---> A4
SCL ---> A5
Here is the code I am using
`/*
RPM meter code (tested on device rotating at 10,000 rpm)
rev.001
* using a hall effect sensor
http://www.adafruit.com/index.php?main_page=product_info&cPath=35&products_id=158
* using a parallel LCD with
LiquidCrystal Library
http://www.ladyada.net/learn/lcd/charlcd.html
http://www.arduino.cc/en/Tutorial/LiquidCrystal
with pins 7,8,9,10,11,12
*/
// include the library code:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// read the hall effect sensor on pin 2
const int hallPin=2;
const unsigned long sampleTime=1000;
const int maxRPM = 10200;
void setup()
{
pinMode(hallPin,INPUT);
Serial.begin(9600);
// set up the LCD's number of rows and columns:
lcd.begin(0x27, 16, 2);
// Print a message to the LCD.
lcd.print("initializing...");
delay(1000);
lcd.clear();
}
void loop()
{
delay(1000);
int rpm=getRPM();
lcd.clear();
displayRPM(rpm);
displayBar(rpm);
}
int getRPM()
{
// sample for sampleTime in millisecs
int kount=0;
boolean kflag=LOW;
unsigned long currentTime=0;
unsigned long startTime=millis();
while (currentTime<=sampleTime)
{
if (digitalRead(hallPin)==HIGH)
{
kflag=HIGH;
}
if (digitalRead(hallPin)==LOW && kflag==HIGH)
{
kount++;
kflag=LOW;
}
currentTime=millis()-startTime;
}
int kount2rpm = int(60000./float(sampleTime))*kount;
return kount2rpm;
}
void displayRPM(int rpm)
{
lcd.clear();
// set the cursor to column 0, line 1
lcd.setCursor(0, 0);
// print the number of seconds since reset:
lcd.print(rpm,DEC);
lcd.setCursor(7,0);
lcd.print("RPM");
}
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);
}
}
} `
I want to get my measurements accurately and in smaller intervals than 60. I am an Arduino noob.
Any help is appreciated
Thanks
EDIT: If anyone knows how to adjust the code to fix my issue, or knows how to change the code in order to get RPM by using the time interval instead of the conversion.