Problems with LCD and counter

Hi,

i am new to programing with arduino and i am having problems, so i was hopping you can help me.
I am using an arduino pro mini 3,3V and i want to make an automated pump. The pump is turned on with a flow switch and turned off with a water flow sensor. The problems are:

  1. I have an LCD 20x4 and it displays strange symbols through the whole display.
  2. I am having problems with the counter. I want to make A counter that you can set how much water can pass through the flow sensor then stops the pump. To reset the counter you have to hold the button for 10sec.

i hope someone can help me with this

thank you

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int button = 0;
byte ledPin = 10;                      // led on pin 10
int VolumeSetting = 0;
int Mainvolume = 0;
int PumpON = 1;
int PumpOFF = 0;
int stateofpump = 0;

// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 7
// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;

// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
  uint8_t x = digitalRead(FLOWSENSORPIN);

    if (x == lastflowpinstate) {
      lastflowratetimer++;
      return; // nothing changed!
    }
    
    if (x == HIGH) {
      //low to high transition!
      pulses++;
    }
    lastflowpinstate = x;
    flowrate = 1000.0;
    flowrate /= lastflowratetimer;  // in hertz
    lastflowratetimer = 0;
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
  }
}

void setup() {
  lcd.begin(20, 4);
  pinMode(6,INPUT_PULLUP);
  pinMode(10, OUTPUT);
//  Serial.begin(9600);
  
  pinMode(FLOWSENSORPIN, INPUT);
  digitalWrite(FLOWSENSORPIN, HIGH);
  lastflowpinstate = digitalRead(FLOWSENSORPIN);
  useInterrupt(true);
}

void loop()
{
  lcd.setCursor(0, 0);
  lcd.print("Start");
 // Serial.print("Start");
  button = digitalRead(6); // SET button
  if (button == LOW) // pritisk set buttona
  {
    int e = 0;
    while(button == LOW)
    {
      e++;
      delay(50);
      button = digitalRead(6);
    }
    if(e > 25)
    {
      VolumeSetting = 0;
      digitalWrite(10, HIGH);
      lcd.clear(); // ciscenje zaslona
      for (int i = 0; i < 200; i++)  //zanka za meni
      {
        lcd.setCursor(0, 1);
        lcd.print("Volumen: "); 
       // Serial.print("Volumen:");
       // Serial.println(VolumeSetting);
        lcd.print(VolumeSetting);
        button = digitalRead(6);
        if(button == LOW)
        {
          delay(100);
          VolumeSetting = VolumeSetting + 1;
          button = 0;
        }
        if(VolumeSetting == 500)
        {
          VolumeSetting = 0;
        }
        delay(120);
        Mainvolume = VolumeSetting;
        pulses = 0;
      }
    }
    delay(120);
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Set quantity: "); 
  lcd.print(Mainvolume);
  lcd.setCursor(0, 1);
  lcd.print("Current quantity: "); 
  lcd.print(Mainvolume);
  

  float liters = 0;
  while (liters < Mainvolume and Mainvolume != 0)
  {
    liters = pulses;
    liters /= 7.5;
    liters /= 30.0;
    if(stateofpump == 0 && liters > 0.50)
    {
      stateofpump = PumpON;
     // Serial.println(" Crpalka ON");
      digitalWrite(ledPin, HIGH);
    }
      
  // Serial.print(liters); 
  // Serial.println(" Liters");
   lcd.setCursor(0, 1);
   lcd.print(liters); 
   lcd.setCursor(1, 1);
   lcd.print(" Liters.");

   if (liters > Mainvolume)
   {
     if (stateofpump == 1 || stateofpump == 1 && liters < 0.50)
     {
       stateofpump = PumpOFF;
       Mainvolume = 0;
      // Serial.println(" Crpalka OFF");
       digitalWrite(ledPin, LOW);
     }  
   }
  }
  
}

Moderator edit: code tags

Get the LCD working first. Clear the LCD then try a simple "Hello World" print to it. What do you see ?

Does the LCD work on 3.3V ?
Where is it getting its power from ?

Thank you for your quick reply. The hello world does work.

There were two more questions in that post. Why didn't you answer those as well? Nobody likes wasting time writing replies for someone who is going to ignore half of what they write.

I think the 4x20 LCD would be a lot happier on the 5v...

in my experience (not a lot in the Arduino world) all the starter kits that include LCD's are 5v kits

LandonW:
I think the 4x20 LCD would be a lot happier on the 5v...

in my experience (not a lot in the Arduino world) all the starter kits that include LCD's are 5v kits

We don't know that it isn't already. The OP refused to answer that question.

Delta_G:
We don't know that it isn't already. The OP refused to answer that question.

it was stated at the beginning that he/she was using a 3.3v proMini.

I just assumed he was using the VCC from it. that's what I do when I use the 5v version.

LandonW:
I just assumed

And we know what happens when you assume don't we? The OP was asked specifically and totally refused to answer. I think we should wait until he gives us that information.

Delta_G:
And we know what happens when you assume don't we?

haha yes, I make an ASS out of U and ME. ASSUME

I prefer "Assumption is the mother of all f%*k-ups" myself. But yeah. The OP needs to tell us how it is powered and apologize for ignoring our questions and wasting our time.

I am sorry, i am not wasting your time. I am not constantly in front of my computer so i can’t reply that fast.
The LCD does work with arduino 3,3V this is on the breadboard. On the breadboard the power is from the arduino but when i have it connected in the box (I added a picture) it has a 5v supply. And i tested it with 5V the hello world and it works.

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How are you switching the pump on and off?
How are you wiring the button and flow sensor?
How are you powering the project?

Thanks.. Tom.. :slight_smile:

The pump is turned on and off with the flow switch and the flow switch is connected to pin D10 on the arduino. The button is weird for now on the breadboard to pin D6 (https://www.arduino.cc/en/Tutorial/StateChangeDetection). Flow sensor is connected to pin D9. Im testing the project on the breadboard for now

Napajalnik-power.pdf (85.3 KB)

Motor-pump.pdf (73.5 KB)

Zaly:
I am sorry, i am not wasting your time. I am not constantly in front of my computer so i can't reply that fast.

It's not that you didn't reply fast enough. It's that when you did reply you didn't answer the questions that were asked of you. I don't care if it takes you three years to get back to us, but when you do please try to read the responses you have carefully and supply any information they ask for.

If hello world works at 5V but not at 3.3V then it sounds like you need to keep the LCD powered with 5V.

Hi,
Thanks for the schematics but where is the Arduino and LCD?
Can you post your circuits as jpg or png and please read first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html.
It will tell you how to insert your images into posts.

This makes it easier for members with platforms other than PCs.

Did you write this code in stages or all at once?

You should;

  • Write code just for the LCD, get it working.
  • Write code just for the Button and the 10Sec hold, get it working.
  • Write code just for the flow sensor and counting, get it working.
  • Write code just to detect the flow limit, get it working.
  • Write code just to turn the pump ON and OFF, get it working.

Then when all the sections work on their own, combine them, ONE at a time and get it working.

I know this sounds long and tiresome, BUT it will help to debug any problems you will have.

Does your code work if you disconnect the motor?
Put a snubber, like on your transformer, across the contacts of your motor relay.

Redesign you motor relay PCB so that low voltage goes in one end and 230Vac the other.
Your PCB needs to have thicker tracks, especially the gnd tracks.
The least copper you have to remove from the PCB the less resources you waste, the quicker it etches, less chemical you use.
If you get your PCBs etched commercially, you are not paying for the amount of copper you keep, leave as much on the PCB in the form of thicker tracks and gnd plane, keeping in mind you mains voltage isolation.

Thanks.. Tom.. :slight_smile: