#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 9
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
DeviceAddress sensor1 = { 0x28, 0xFF, 0x77, 0x62, 0x40, 0x17, 0x4, 0x31 };
DeviceAddress sensor2 = { 0x28, 0xFF, 0xB4, 0x6, 0x33, 0x17, 0x3, 0x4B };
DeviceAddress sensor3= { 0x28, 0xFF, 0xA0, 0x11, 0x33, 0x17, 0x3, 0x96 };
int flow; //Water flow L/Min
int flowsensor = 2;
int flow_ser;
unsigned long currentTime;
unsigned long lastTime;
unsigned long pulse_freq;
const int buttonPin = 7;
int buttonState = 0;
float pressure;
void pulse () // Interrupt function
{
pulse_freq++;
}
void setup()
{
pinMode(buttonPin, INPUT);
// initialize the LCD
lcd.init();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Flow Rate:");
lcd.print(" L/M");
lcd.setCursor(0, 1);
lcd.print("Temp In : ");
lcd.print((char)223); //simbol derajat
lcd.print("C");
lcd.setCursor(0, 2);
lcd.print("Temp Out : ");
lcd.print((char)223); //simbol derajat
lcd.print("C");
lcd.setCursor(0, 3);
lcd.print("Temp Prod: ");
lcd.print((char)223); //simbol derajat
lcd.print("C");
//====== setup program Flow sensor YF-S201 ========
pinMode(flowsensor, INPUT);
Serial.begin(9600);
attachInterrupt(0, pulse, RISING); // Setup Interrupt
currentTime = millis();
lastTime = currentTime;
//====== inisialisasi ds8b20 =========
sensors.begin();
}
void loop()
{
// ====== Main Program Flow Sensor ============
currentTime = millis();
// Every second, calculate and print L/Min
if(currentTime >= (lastTime + 1000))
{
lastTime = currentTime;
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
flow = (pulse_freq / 7.5);
pulse_freq = 0; // Reset Counter
//Serial.print(flow, DEC);
//Serial.println(" L/Min");
lcd.setCursor(0, 0);
lcd.print("Flow Rate:");
lcd.setCursor(10, 0);
lcd.print(flow, DEC);
flow_ser=flow;
if (flow < 10){
lcd.setCursor(10, 0);
lcd.print(flow,DEC);
lcd.setCursor(11, 0);
lcd.print(" ");
}
//lcd.print("L/M");
//Main Program DS18b20 =========
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
lcd.setCursor(0, 1);
lcd.print("Temp In :");
lcd.print(sensors.getTempC(sensor1));
lcd.print((char)223); //simbol derajat
lcd.print("C");
lcd.setCursor(0,2);
lcd.print("Temp In :");
lcd.print(sensors.getTempC(sensor2));
lcd.print((char)223); //simbol derajat
lcd.print("C");
lcd.setCursor(0, 3);
lcd.print("Temp In :");
lcd.print(sensors.getTempC(sensor3));
lcd.print((char)223); //simbol derajat
lcd.print("C");
//Serial.print((char)223);
//lcd.print("C")
Serial.print(flow, DEC);
Serial.print('-');
Serial.print(sensors.getTempC(sensor1));
Serial.print('-');
Serial.print(sensors.getTempC(sensor2));
Serial.print('-');
Serial.print(sensors.getTempC(sensor3));
Serial.print('-');
Serial.println();
}
}