go_baby_go_logo-ow4pfc
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1478
    Stacy Okai
    Participant

    What are some programming methods for keeping track of time, or determining how long multiple events have happened between start and end? This was a problem that was faced over the course of the data logging project.

    #1486
    Sylvester Dzimiri
    Participant

    I am not sure if you guys looked into the RTC library. You can use the DS1307 Real Time Clock breakout, you will need to install the library from GitHub to begin working with that.

    https://github.com/adafruit/RTClib
    https://www.adafruit.com/product/264

    This is also the RTC library (https://www.arduino.cc/en/Reference/RTC) and it has some examples to start with.

    #1638
    Stacy Okai
    Participant

    Hi Sylvester, thanks for your suggestion. Two of the data loggers that were used actually have a built-in RTC(DS1307), and the third logger uses an RTC module. The appropriate libraries were also installed for RTC usage.

    You can check out the code on our blog post titled “Data Logging with the Nano Shield – Testing – Programming and Results – Version 1.”

    Here is the link:

    Data Logging with the Nano Shield – Final Test Circuit-Programming and Results (Version 1)

    The main problem was trying to use the RTC and/or code the program in such a way that when each event/case took place, the duration of time the event occurred would be documented. For example, if a red LED was on in a forward case from 5:36:05 to 5:38:09, we would want to print the difference of 2 minutes 4 seconds (00:02:04).

    I also tried implementing the “millis” function, during the coding phase, and had no success.

    I appreciate your help!!

    #1640
    Sylvester Dzimiri
    Participant

    Hey Stacy, Thanks for the link; such a great post. You are right that you can use the “millis” function. This is what I used in my project to see how much time has passed before sending sensor data. I have attached some of the snippet code on how I instantiated the millis object and keep track of the time. I think you also want to do something along those lines.

    //initialize times
      gas_time = millis();
      flame_time = millis();
      pir_time = millis();
      sound_time = millis();
      temperature_time = millis();
      ultrasonic_time = millis();
     
      //PIR sensor
      pinMode(PirInput, INPUT);
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      unsigned long time_passed = 0;
      
      //device #2
      //read gas sensor
      // don't read analog pins too often (<1Hz), else caps never get to charge.
     
      time_passed = millis() - gas_time;
     
      //if roll over, send next value again
      if (time_passed < 0)
      {
      gas_time = millis();
      gas_time_send = -700000;
      }

    I hope that might be helpful. I am sure you also read their documentation but I am attaching the link (https://www.arduino.cc/reference/en/language/functions/time/millis/)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Thank you for your message!

We will contact you soon!