Hello, I have been trying like mad to get this RPM Hall Sensor to LCD working. I belong to GTBA and found this schematic and code on there, but for the life of me, I cannot get it working. If anybody could shed some light, I would be very grateful. Here is the code:
Code:
//--------------------------------------------------------------
//
// Interrupt driven sketch to measure RPM,
// it expects a suitable signal on pin digital 2 / external int0
// Display is via LCD.
//
//--------------------------------------------------------------
/* LCD 1 GND - ground
- LCD 2 Vcc - +5v
- LCD 4 RS pin - digital pin 52
- LCD 6 Enable pin - digital pin 30
- LCD 7 D0 pin - digital pin 28
- LCD 8 D1 pin - digital pin 26
- LCD 9 D2 pin - digital pin 24
- LCD 10 D3 pin - digital pin 22
- LCD 11 D4 pin - digital pin 23
- LCD 12 D5 pin - digital pin 25
- LCD 13 D6 pin - digital pin 27
- LCD 14 D7 pin - digital pin 29
*pin 2 interupt
*pin 43 to flash lcd when magnet sensed
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(32, 30, 28, 26, 24, 22, 23, 25, 27, 29); //8 bit mode
volatile word rpmcount;
unsigned long rpm;
unsigned long timeold;
long rpmdetect; //time of last revo signl;
int rpmmin; //min rpm to be detected, bellow this rpm=0
void setup()
{
lcd.begin(20,4);
lcd.clear();
pinMode(43 ,OUTPUT); // revo led, high=revo detect
attachInterrupt(0, rpm_fun, RISING); //enable int pin2
rpmcount = 0;
rpm = 0;
rpmmin = 800;
timeold = 0;
rpmdetect = 0;
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("RPM: ");
if (timeold==0)
{
lcd.setCursor(5,0);
lcd.print(rpm);
}
if (analogRead(2)>500) ///turn off led when not sensed
digitalWrite(43, HIGH); //rev sensor detect
else
digitalWrite(43, LOW); //rev sensor not detected
if (rpmcount >= 100) //Update RPM every 100 counts, increase this for better RPM resolution decrease for faster update
{
rpm = 1000000*60/(micros() - timeold)*rpmcount;
timeold = micros();
rpmcount = 0;
if (rpm > rpmmin)
{
lcd.setCursor(5,0);
lcd.print(" ");
lcd.setCursor(5,0);
lcd.print(rpm);
}
}
if (((millis() - rpmdetect) >500) && (rpm>0)) //if no revolution deteced in 1/2 sec set rpm=0
{
rpm=0;
lcd.setCursor(5,0);
lcd.print(" ");
lcd.setCursor(5,0);
lcd.print(rpm);
}
}
void rpm_fun()
{
rpmcount++; //Each rotation, this interrupt function is run
rpmdetect=millis();
digitalWrite(43,HIGH);
}
Thanks a bunch,
John
P.S. If you need anything else, please let me know.