can you share your arduino code you've tried?
I'm about to modify a tachometer program to add surface feet per minute based on input workpiece diameters. The programming should be very similar. I may be able to work out yours too.
caveat, I have not written any code for arduino in years so I am rusty.
---------------------------------------------------------------------------------------------------------------
const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 6; // Echo Pin of Ultrasonic Sensor
// Include the library:
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
//LiquidCrystal_I2C lcd(0x3F, 16, 2);
#define MAX_DISTANCE 400
NewPing sonar(pingPin, echoPin, MAX_DISTANCE);
// Create variable to store curent value _c, pervious value _p, delta value d_, centemeter cm, millisec ms, seconds sec
float c_cm = 0;
float p_cm = 0;
float d_cm = 0;
unsigned long c_ms = 0;
unsigned long p_ms = 0;
unsigned long d_ms = 0;
unsigned long d_sec = 0;
// Create variable to store cm per sec cps, ft per min fpm
float cps = 0;
float fpm = 0;
float duration, c_dur, p_dur, a_dur, inches, cm = 0.0;
unsigned long lcdrefresh = 0; // To store time for lcd to refresh
void setup() {
Serial.begin(9600); // Starting Serial Terminal
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("FWD FPM ");
lcd.setCursor(0,1);
lcd.print("REV FPM ");
lcd.setCursor(0,1);
}
void loop() {
/*******
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
c_dur = pulseIn(echoPin, HIGH);
****/
c_dur = sonar.ping_median(5);
if (abs(c_dur - p_dur) <= /*4.35*/ 4.4) c_dur = p_dur;
a_dur = (c_dur + p_dur) / 2.0;
inches = microsecondsToInches(a_dur);
cm = microsecondsToCentimeters(a_dur);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm, ");
// Serial.print(sonar.ping_in());
// Serial.print("in, ");
Serial.print("c_dur ");
Serial.print(c_dur);
Serial.print(" p_dur ");
Serial.print(p_dur);
Serial.print(" a_dur ");
Serial.println(a_dur);
Serial.println();
c_cm = cm;
c_ms = millis();
bool fwdfpm = false;
bool revfpm = false;
bool frfpm = false;
if (c_cm > p_cm) fwdfpm = true;
if (c_cm < p_cm) revfpm = true;
if (c_cm == p_cm) frfpm = true;
d_cm = c_cm - p_cm;
d_ms = c_ms - p_ms;
d_sec = d_ms / 1000;
cps = d_cm / d_sec;
fpm = (cps / 30.48) * 60.0;
// LCD Display
// if( ( millis()-lcdrefresh ) >= 1000 )
{
if (fwdfpm)
{
lcd.setCursor(8,0);
lcd.print(" ");
lcd.setCursor(8,0);
lcd.print(fpm);
}
if (revfpm)
{
lcd.setCursor(8,1);
lcd.print(" ");
lcd.setCursor(8,1);
lcd.print(fpm);
}
if (frfpm)
{
lcd.setCursor(8,0);
lcd.print(" ");
lcd.setCursor(8,0);
lcd.print(fpm);
lcd.setCursor(8,1);
lcd.print(" ");
lcd.setCursor(8,1);
lcd.print(fpm);
}
Serial.print("fpm ");
Serial.print(fpm);
Serial.print(" dcm ");
Serial.println(d_cm);
Serial.println();
lcdrefresh = millis();
}
p_cm = c_cm;
p_ms = c_ms;
// p_dur = a_dur;
p_dur = c_dur;
// delay(100);
delay(900);
}
float microsecondsToInches(long microseconds) {
return microseconds / 74.0 / 2.0;
}
float microsecondsToCentimeters(long microseconds) {
return microseconds / 29.0 / 2.0;
}
---------------------------------------------------------------------------------------------------------------
Still need to figure out how to capture peak FPM or average FPM for the fwd and rev strokes.