I am writing arduino code for flow sensor and lcd display.
Below is my code and lcd showing 40 l/h constant value and never change.
Anybody can help me?I am very new with arduino programming.
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
flow_frequency++;
}
//flow_frequency = 0;
void setup()
{
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
Serial.begin(9600);
attachInterrupt(0, flow, RISING); // Setup Interrupt
sei(); // Enable interrupts
currentTime = millis();
cloopTime = currentTime;
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Flow Meter!");
}
void loop ()
{
currentTime = millis();
// Every second, calculate and print litres/hour
if(currentTime >= (cloopTime + 1000))
{
//flow_frequency = 0;
cloopTime = currentTime; // Updates cloopTime
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
flow_frequency = 0; // Reset Counter
lcd.setCursor(0, 1);
lcd.print(l_hour,DEC);
lcd.print (" L/hour");
Serial.print(l_hour, DEC); // Print litres/hour
Serial.println(" L/hour");
// print the number of seconds since reset:
volatile int flow_frequency; // Measures flow meter pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowmeter = 2; // Flow Meter Pin number
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interruot function
{
flow_frequency++;
}
volatile int flow_frequency; // Measures flow meter pulses
That was as far as I read. I can not imagine needing to use a comment to describe the contents of a variable, when naming it flow_pulse_count would eliminate the need for the comment.
minko:
volatile int flow_frequency; // Measures flow meter pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowmeter = 2; // Flow Meter Pin number
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interruot function
{
flow_frequency++;
}
I am facing problem with arduino with display and yfs201 flow sensor.
My code is below.If i put lcd.begin (16,2);,flow senor reading is not correct and never change reading.
Can help me anybody?
minko:
I am facing problem with arduino with display and yfs201 flow sensor.
My code is below.If i put lcd.begin (16,2);,flow senor reading is not correct and never change reading.
Can help me anybody?