How to add time/date/trigger to a specific code?

Hello, I'm trying to a code where every time it detects liquid, it can tell me the time. I'm a little lost after trying out different time functions such as millis(). I'm a complete beginner to the Arduino, thank you for your time!

   /*
  Made on Jan 12, 2020
  By MehranMaleki @ Electropeak
  Home
*/

#define Liquid_Detection_Pin 2     //Output pin on sensor

void setup() {
  Serial.begin(9600);
  pinMode(Liquid_Detection_Pin, INPUT);
}

void loop() {
  
  if (digitalRead(Liquid_Detection_Pin)) {
    Serial.println("Liquid Detected!");
  }
  else {
    Serial.println("No Liquid!");
  }

  delay(1000);
}

Welcome to the forum

Do you want to know the actual time of the event, in which case you will need a source for the time such as a Real Time Clock (RTC), or the time relative to some previous event, in which case you could use millis() or an RTC

Which Arduino board do you have ?
If it is WiFi enabled then you could consider getting the time from the Internet

I'm using the Arduino Uno which I believe it cannot connect to the internet? How would I add millis()? Would I just add mytime=millis() under Serial.println("Liquid Detected!")?

 if (digitalRead(Liquid_Detection_Pin)) {
    Serial.println("Liquid Detected!");
mytime=millis();

You did not answer my question as to whether you require to know the actual time of an event or the relative time from some other event

millis() will not tell you the actual time unless you have an accurate start time in the first place

The Uno on its own cannot connect to the Internet so an RTC is the best option if you need the actual time, then you don't need to use millis() anyway

Why do you need that?

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