Filling machine with yf-s201 reading error

Hi guys, first time poster so please be gentle :slight_smile:

I am trying to make an automated filling machine using a relay and a YF-S201 flow sensor. I am all set except the part that reads flow sensor data and shuts off the relay. Algorithm seems to record flowing volume but fails to show it on an LCD screen and turning off the relay. I am fairly new to arduino. Any help will be greatly appreciated. Here is my code:

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int ROW_NUM = 4;
const int COLUMN_NUM = 4;

char keys[ROW_NUM][COLUMN_NUM] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

byte pin_rows[ROW_NUM] = { 4, 5, 6, 7 };
byte pin_column[COLUMN_NUM] = { 8, 9, 10, 11 };
Keypad tus_takimi = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);

#define sensorPin 2
#define relay 1
#define buzzer 13
#define buton 12

//volatile long pulse;
volatile float pulse;
float volume;
float hacim;

String code = "";
String lastCode;

float count;

int previousMillis = 0;
int currentTime;

void setup() {

  pinMode(relay, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(sensorPin, INPUT_PULLUP);
  pinMode(buton, INPUT_PULLUP);

  Serial.begin(9600);
  attachInterrupt(0, increase, RISING);

  lcd.begin(16, 2);
  lcd.backlight();
  lcd.clear();

  digitalWrite(relay, HIGH);


  main_screen();
}

void loop() {

  char tus = tus_takimi.getKey();


  if ((tus >= '0' && tus <= '9')) {
    code += tus;
    lcd.setCursor(0, 1);
    lcd.print(code);
    delay(10);
  } else if (tus == 'D') {
    hacim = code.toFloat();
    if ((hacim <= 30000.00) && (hacim >= 100.00)) {
      code = lastCode;
      lcd.clear();
      filling();
    } else {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Gecersiz Miktar");

      delay(1000);
      lcd.clear();
      main_screen();
      code = "";
    }
  } else if (tus == 'B') {
    code = "";
    lastCode = code;
    lcd.clear();
    filling();
  }

  int dis_buton = digitalRead(buton);
  if (dis_buton = LOW) {
    code = "";
    lastCode = code;
    lcd.clear();
    filling();
  }
}

void increase() {
  pulse++;
}

void filling() {
  currentTime = millis();
  if (currentTime - previousMillis >= 100) {
    noInterrupts();
    count = pulse;
    pulse = 0;
    interrupts();
    previousMillis += 500;
  }
  //volume = 2.663 * pulse;
  volume = (2.25 * count);
  digitalWrite(relay, LOW);
  Serial.print(volume);
  Serial.println(" mL");
  Serial.print(hacim);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Tamamlanan:");
  lcd.setCursor(0, 1);
  lcd.print(volume);
  lcd.print(" ml");
  delay(100);

  if (volume >= (hacim - 100)) {
    digitalWrite(relay, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Bitti");
    lcd.setCursor(0, 1);
    lcd.print(volume);
    lcd.print(" mL");

    volume = 0.00;
    int currentMillis = millis();

    if (currentMillis - previousMillis >= 1500) {
      lcd.clear();
      main_screen();
      code = lastCode;
    }
  }
}

void main_screen() {
  lcd.setCursor(0, 0);
  lcd.print("Miktar Giriniz:");
  lcd.setCursor(14, 1);
  lcd.print("mL");
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.