#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/)

Thank you for your message!

We will contact you soon!