Hi, so recently I've tried to make my own Tachometer project. I am using Arduino Uno, A3144 Hall-effect sensor and 1.8' TFT display for displaying the RPM value. The only minor problem I am seeking to resolve right now is the jump in value. So for example when the sensor isn't detecting any magnetic field the value is 0 but after just one detection the value immediately jumps to 60 rpm. How can I edit the code so the value goes up gradually and not by segments of 60(0,60,120,180...)? Any help is much appreciated.
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// char array to print to the screen
char sensorPrintout[4];
int hallsensor = 2; // Hall sensor at pin 2
volatile int counter;
unsigned int rpm;
unsigned long passedtime;
void isr()
{
//Each rotation, this interrupt function is run twice, so take that into consideration for
//calculating RPM
//Update count
counter++;
}
void setup()
{Serial.begin(9600);
//Intiates Serial communications
attachInterrupt(0, isr, RISING); //Interrupts are called on Rise of Input
pinMode(hallsensor, INPUT); //Sets hallsensor as input
counter = 0;
rpm = 0;
passedtime = 0; //Initialise the values
// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();
// clear the screen with a black background
TFTscreen.background(0, 0, 0);
// write the static text to the screen
// set the font color to white
TFTscreen.stroke(255, 255, 255);
// set the font size
TFTscreen.setTextSize(2);
// write the text to the top left corner of the screen
TFTscreen.text("Sensor Value :\n ", 0, 0);
// ste the font size very large for the loop
TFTscreen.setTextSize(5);
}
void loop()
{
delay(999);//Update RPM every second
detachInterrupt(0); //Interrupts are disabled
rpm = counter*60;
passedtime = millis();
counter = 0;
Serial.print("RPM=");
Serial.println(rpm); //Print out result to monitor
attachInterrupt(0, isr, RISING); //Restart the interrupt processing
// Read the value of the sensor on A0
String sensorVal = String((rpm));
// convert the reading to a char array
sensorVal.toCharArray(sensorPrintout, 4);
// set the font color
TFTscreen.stroke(255, 255, 255);
// print the sensor value
TFTscreen.text(sensorPrintout, 0, 20);
// wait for a moment
delay(250);
// erase the text you just wrote
TFTscreen.stroke(0, 0, 0);
TFTscreen.text(sensorPrintout, 0, 20);
}