I'm new to the Arduino world but am semi-familiar with C/C++. I'm working an a project that will use multiple sensors and a LCD display to show the gathered info. With simple sensors, such as RB-Wav-39, SEN0189 or DS18S20, I've got no issue. However, when I try using interrupts with a YF-S201 (a hall-effect water flow sensor) to count pulses, I just get a blank screen on the LCD. Below is a portion of my code for these two items. Any thoughts or suggestions on why this happens?
//INCLUDES
#include <LiquidCrystal.h>
#include <Wire.h>
//PIN ASSIGNMENTS
#define Pin_FlowSens1 2 //Flow Sensor (YF-S201) to digital pin 2
#define Pin_FlowSens2 3 //Flow Sensor (YF-S201) to digital pin 3
#define Pin_LCDBkltGreen 5 //LCD (LCD-10862) Green Backlight to digital pin 5, PWM freq=980 Hz
#define Pin_LCDBkltBlue 6 //LCD (LCD-10862) Blue Backlight to digital pin 6, PWM freq=980 Hz
#define Pin_LCDrs 7 //LCD (LCD-10862) RS to digital pin 7
#define Pin_LCDen 8 //LCD (LCD-10862) Enable to digital pin 8
#define Pin_LCDBkltRed 9 //LCD (LCD-10862) Red Backlight to digital pin 9, PWM freq=490 Hz
#define Pin_LCDd4 10 //LCD (LCD-10862) D4 to digital pin 10
#define Pin_LCDd5 11 //LCD (LCD-10862) D5 to digital pin 11
#define Pin_LCDd6 12 //LCD (LCD-10862) D6 to digital pin 12
#define Pin_LCDd7 13 //LCD (LCD-10862) D7 to digital pin 13
LiquidCrystal lcd(Pin_LCDrs, Pin_LCDen, Pin_LCDd4, Pin_LCDd5, Pin_LCDd6, Pin_LCDd7); // Configure LCD Display Pins
int brightness = 255; //Change the overall brightness by range 0 -> 255
volatile int FlowCnt1; //measuring the rising edges of the signal
volatile int FlowCnt2; //measuring the rising edges of the signal
void setup(void) {
Serial.begin(9600);
lcd.begin(16, 2); //Initialize LCD and set up the number of columns and rows
pinMode(Pin_LCDBkltRed, OUTPUT);
pinMode(Pin_LCDBkltGreen, OUTPUT);
pinMode(Pin_LCDBkltBlue, OUTPUT);
setBacklight(0, 0, 0);
pinMode(Pin_FlowSens1, INPUT);
attachInterrupt(digitalPinToInterrupt(Pin_FlowSens1), rpm1, RISING);
pinMode(Pin_FlowSens2, INPUT);
attachInterrupt(digitalPinToInterrupt(Pin_FlowSens2), rpm2, RISING);
} //End Setup
void loop(void) {
float flow =0;
FlowCnt1 = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
flow = (FlowCnt1 * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L / hour
delay (5000);
lcd.setCursor(0, 0); //Set the cursor to the top left
lcd.print("Flow Rate:");
lcd.setCursor(5, 1); //Set the cursor to the top left
lcd.print(flow); //Prints the number calculated above
Serial.println(flow, DEC);
lcd.print(" L/hr"); //Prints "L/hour" and returns a new line
delay(1000); //delay in between sensor reads to be able to read
lcd.clear(); //clear LCD screen to prepare for next value
} //End Main Loop
//-------------------------------------------------------------
void setBacklight(uint8_t r, uint8_t g, uint8_t b) {
// normalize the red LED - its brighter than the rest!
// r = map(r, 0, 255, 0, 100);
// g = map(g, 0, 255, 0, 150);
r = map(r, 0, 255, 0, brightness * 1.5);
g = map(g, 0, 255, 0, brightness);
b = map(b, 0, 255, 0, brightness);
analogWrite(Pin_LCDBkltRed, r);
analogWrite(Pin_LCDBkltGreen, g);
analogWrite(Pin_LCDBkltBlue, b);
} //End setBacklight
void rpm1 () //
{
FlowCnt1++; //called by interupt, Measures the rising and falling edge of the hall effect sensors signal
}
void rpm2 () //
{
FlowCnt2++; //called by interupt, Measures the rising and falling edge of the hall effect sensors signal
}