#include <DS3231.h>
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int CS = 4;
File dataku;
byte sensorInt = 0;
byte flowsensor = 2;
volatile byte pulseCount;
float debit, liter, volume, biaya ;
float flowmlt;
float totalmlt;
unsigned long oldTime;
float konstanta = 4.5; //konstanta flow meter
LiquidCrystal_I2C lcd(0x27, 20, 4);
DS3231 rtc;
DateTime t;
void setup() {
Serial.begin(115200);
Serial.println("DataLogger Water Meter");
Wire.begin();
lcd.begin(20, 4);
lcd.clear();
lcd.backlight();
//program yudi
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH);
// Serial.println("Membaca SDcard...");
if (!SD.begin(CS))
{
Serial.println("Gagal/Sdcard Rusak");
while (1);
}
pulseCount = 0;
debit = 0.0;
flowmlt = 0;
totalmlt = 0;
oldTime = 0;
liter = 0;
volume = 0;
//program yudi
// Serial.println("Berhasil");
}
void loop() {
t = rtc.getTime();
if ((millis() - oldTime) > 1000)
{
detachInterrupt(sensorInt);
debit = ((1000.0 / (millis() - oldTime)) * pulseCount) / konstanta;
oldTime = millis();
flowmlt = (debit/60) * 1000;
totalmlt += flowmlt;
liter = totalmlt / 1000;
volume = liter / 1000;
biaya = volume * 1000;
if (t.date == 1 && t.hour == 00 && t.min == 00 && t.sec == 00 ) {
lcd.clear();
totalmlt = 0;
biaya = 0;
lcd.clear();
}
String minta = "";
while (Serial.available() > 0)
{
minta += char(Serial.read());
}
minta.trim();
if (minta == "Meminta Data Dari Arduino...")
{
kirimdata();
}
tampilanlcd();
minta = "";
delay(1000);
}
//fungsi untuk mengirim data ke ESP32
void kirimdata() {
String datakirim = String(volume) + "#" + String(biaya);
Serial.println(datakirim);
}
//fungsi untuk menampilkan hasil pembacaan sensor ke LCD
void tampilanlcd() {
lcd.setCursor(0, 0);
lcd.print("Water Meter Digital");
lcd.setCursor(0, 1);
lcd.print(rtc.getDateStr());
lcd.setCursor(0, 2);
lcd.print("Volume = ");
lcd.print(volume);
lcd.print("M3");
lcd.setCursor(0, 3);
lcd.print("biaya = Rp");
lcd.print(biaya);
dataku = SD.open("yudi.txt", FILE_WRITE);
if (dataku){
dataku.println("");
dataku.print(rtc.getDateStr());
dataku.print(volume);
dataku.print(biaya);
dataku.close();
//Serial.println(" I Data Tersimpan");
}
else{
//Serial.println(" I Gagal Menyimpan");
void pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}
pulseCount = 0;
attachInterrupt(sensorInt, pulseCounter, FALLING);
}
Strongly suspect you have the wrong library installed.
Where did you get the code?
As with any project with a new sensor, I first run the library example code to prove out the DS3231 operation.
Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and the forum software will display it correctly.
on google
I've downloaded several libraries but it's still like that
done
Then you downloaded libraries that don't match the code.
Google is a search engine... the place it took you would be more useful.
oh oke, thank you for your solution
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.