Icono del sitio ELECTROALL

Manejo del SENSOR DE FLUJO

CODIGO
#include <LiquidCrystal_I2C.h> // Debe descargar la Libreria que controla el I2C
#include<Wire.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);

const int pulsador_ = 3;
const int bomba    = 12;
volatile double waterFlow;
boolean state = false;
int pulsador;
void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(1, 0);
  lcd.print("ELECTROALL.");
  delay(600);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("waterFlow: ");
  lcd.print(waterFlow);
  lcd.print(" L");
  waterFlow = 0;

  pinMode(pulsador_, INPUT_PULLUP); //Resistencia de pullup interna
  attachInterrupt(0, pulse, RISING);  //DIGITAL Pin 2: Interrupt 0

  pinMode(bomba, OUTPUT);
}
void loop() {

  pulsador = digitalRead(pulsador_);

  if (pulsador == 0) {
    digitalWrite(bomba, 1);
    state = true;
    waterFlow = 0;
  }
  if (state == true) {
    lcd.setCursor(0, 0);
    lcd.print("waterFlow:");
    lcd.print(waterFlow);
    lcd.print("L");
  }
  if (waterFlow >= 1) {
    digitalWrite(bomba, 0);
    state = false;
  }
}

void pulse()   //measure the quantity of square wave
{
  waterFlow += 1.0 / 450.0;
}
VIDEO DEL MANEJO DE LA PANTALLA LCD
Salir de la versión móvil