Page 1 of 1

LCD Blank´s - Jaycar Water Flow Gauge

Posted: Wed Sep 02, 2015 2:30 pm
by cassianomasiero
Hello friends. I am new to the forum and would appreciate a help or a tip . I'm working on Jaycar Water Flow Gauge on Atmega chip 328p NANO board, much like the UNO . It is a search for my course at school. The first time you compiled the code it all worked out . All information appeared on the LCD as expected. As I had not yet available the Hall flow sensor, expected delivery of sensor to be able to test everything together. The problem is that now , after the code compilation, the LCD display is blank. No information is shown . I checked several times all connections . Operational information appear in the Serial Print correctly, all normal. As I was in doubt about the operation of the LCD and NANO , I tested the LCD and the NANO with a "hello world" and other applications with LCD and everything works normally. What could be happening ? I appreciate any help .

Re: LCD Blank´s - Jaycar Water Flow Gauge

Posted: Thu Sep 03, 2015 4:55 am
by angusgr

Sorry to hear your project isn't working as expected. Are you using any Freetronics products in the setup? Which LCD are you using?

If you post the sketch code that you're using then someone might be able to help you debug it.


Re: LCD Blank´s - Jaycar Water Flow Gauge

Posted: Thu Sep 03, 2015 1:56 pm
by cassianomasiero
Hello Angusgr,
Thank you for contact. I'm not using Freetronics Devices that time. I'm from Brazil and there are no Freetronics products. The lcd I am using is a 16x2 model RT162-7 HD44780 controller from manufacturer Ruite SHENZHEN ELECTRONIC CO. , LTD.
My question is why the lcd worked the first time I compiled the code and now it does not. Nothing has changed.
I can not understand it in the code there is no line that blocks the operation of the LCD.
Below is the code I am using. This code is not of my own and it has not changed. Is on the site: ... flow-gauge

Code: Select all

 * Water Flow Gauge
 * Uses a hall-effect flow sensor to measure the rate of water flow and
 * output it via the serial connection once per second.
 * Copyright 2009 Jonathan Oxer <>
 * Copyright 2009 Hugh Blemings <>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// Specify the pins for the two counter reset buttons and indicator LED
byte resetButtonA = 11;
byte resetButtonB = 12;
byte statusLed    = 13;

byte sensorInterrupt = 0;  // 0 = pin 2; 1 = pin 3
byte sensorPin       = 2;

// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.5;

volatile byte pulseCount;  

float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitresA;
unsigned long totalMilliLitresB;

unsigned long oldTime;

void setup()
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("                ");
  lcd.setCursor(0, 1);
  lcd.print("                ");
  // Initialize a serial connection for reporting values to the host
  // Set up the status LED line as an output
  pinMode(statusLed, OUTPUT);
  digitalWrite(statusLed, HIGH);  // We have an active-low LED attached
  // Set up the pair of counter reset buttons and activate internal pull-up resistors
  pinMode(resetButtonA, INPUT);
  digitalWrite(resetButtonA, HIGH);
  pinMode(resetButtonB, INPUT);
  digitalWrite(resetButtonB, HIGH);
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitresA = 0;
  totalMilliLitresB = 0;
  oldTime           = 0;

  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

 * Main program loop
void loop()
  if(digitalRead(resetButtonA) == LOW)
    totalMilliLitresA = 0;
    lcd.setCursor(0, 1);
    lcd.print("0L      ");
  if(digitalRead(resetButtonB) == LOW)
    totalMilliLitresB = 0;
    lcd.setCursor(8, 1);
    lcd.print("0L      ");
  if( (digitalRead(resetButtonA) == LOW) || (digitalRead(resetButtonB) == LOW) )
    digitalWrite(statusLed, LOW);
  } else {
    digitalWrite(statusLed, HIGH);
  if((millis() - oldTime) > 1000)    // Only process counters once per second
    // Disable the interrupt while calculating flow rate and sending the value to
    // the host
    //lcd.setCursor(15, 0);
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitresA += flowMilliLitres;
    totalMilliLitresB += flowMilliLitres;
    // During testing it can be useful to output the literal pulse count value so you
    // can compare that and the calculated flow rate against the data sheets for the
    // flow sensor. Uncomment the following two lines to display the count value.
    //Serial.print(pulseCount, DEC);
    //Serial.print("  ");
    // Write the calculated value to the serial port. Because we want to output a
    // floating point value and print() can't handle floats we have to do some trickery
    // to output the whole number part, then a decimal point, then the fractional part.
    unsigned int frac;
    // Print the flow rate for this second in litres / minute
    Serial.print(int(flowRate));  // Print the integer part of the variable
    Serial.print(".");             // Print the decimal point
    // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
    frac = (flowRate - int(flowRate)) * 10;
    Serial.print(frac, DEC) ;      // Print the fractional part of the variable

    // Print the number of litres flowed in this second
    Serial.print(" ");             // Output separator

    // Print the cumulative total of litres flowed since starting
    Serial.print(" ");             // Output separator
    Serial.print(" ");             // Output separator
    lcd.setCursor(0, 0);
    lcd.print("                ");
    lcd.setCursor(0, 0);
    lcd.print("Flow: ");
    if(int(flowRate) < 10)
      lcd.print(" ");
    lcd.print((int)flowRate);   // Print the integer part of the variable
    lcd.print('.');             // Print the decimal point
    lcd.print(frac, DEC) ;      // Print the fractional part of the variable
    lcd.print(" L");
    lcd.setCursor(0, 1);
    lcd.print(int(totalMilliLitresA / 1000));
    lcd.setCursor(8, 1);
    lcd.print(int(totalMilliLitresB / 1000));

    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

 * Invoked by interrupt0 once per rotation of the hall-effect sensor. Interrupt
 * handlers should be kept as small as possible so they return quickly.
void pulseCounter()
  // Increment the pulse counter

Re: LCD Blank´s - Jaycar Water Flow Gauge

Posted: Fri Sep 04, 2015 12:36 am
by angusgr
Sorry for the confusion over products. "Jaycar" is an electronics reseller here in Australia, which is why I thought you'd bought parts from them.

I'm not sure why the code would stop working if you haven't changed it. Perhaps try adding some Serial.println() statements and look at the output in the Serial Monitor to see where the code is getting to. Also double-check all the pin numbers used for the Lcd.begin() statement and other places.

Sorry I can't be of more help.

Re: LCD Blank´s - Jaycar Water Flow Gauge

Posted: Fri Sep 04, 2015 6:21 pm
by cassianomasiero
I had not thought of it yet. I will try to change the code as you suggest and see if it works . Thank you for your help.

Re: LCD Blank´s - Jaycar Water Flow Gauge

Posted: Tue Dec 29, 2015 7:36 am
by sarwanov
That was really good post.Thanks a lot for sharing it.