I'm not very experienced with Arduino, so I'm a little stupid, please bear with me
I'm trying to create a pulse counter which takes the digital pulses from a flow meter and converts it to gallons per minute and displays the flow rate on an LCD. I have been able to get it to detect when and count pulses, but I've realized that when I try to convert my pulses per second into gal/min, any time I have an irrational number, the LCD and serial monitor just display the first integer and then zeroes after the decimal point.
I have included my code and a screenshot of the test circuit I'm using to prototype it on TinkerCAD.
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //Initialize the variables for LCD
int count = 0; //Pulse Count
float gpm;
unsigned long start; //Start and end times to determine when 1 sec has passed
unsigned long end;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup(){
Serial.begin(9600);
pinMode(7,INPUT); //Identify Digital Input
pinMode(8,OUTPUT);
lcd.begin(16,2); //Set up the LCD begin to display static text
lcd.print("Flow");
lcd.setCursor(5,1);
lcd.print("gal/min");
}
void loop(){
digitalWrite(8,HIGH);
start = millis(); //sets start time equal to the current clock time
end = start;
while ((end-start) < 1000){//Only allows the loop to run for a second
if (digitalRead(7) == HIGH){ //Checks to see if the input has changed from HIGH to LOW
delay(2);
if (digitalRead(7) == LOW){
count = count + 1; //Adds to count for every pulse detected
}
}
end = millis();
}
gpm = (count * 60) / 180;
Serial.println(count);
lcd.setCursor(0,1);
Serial.println(gpm,7);
//lcd.print(gpm);
count = 0;//Resets count to 0, use pulses/sec to convert to gal/min
}
