turning a temperature sensor on and off every thirty minutes

Hello! I am very new to the arduino coding world...I'm trying to code a temperature sensor to come on every thirty minutes, take the temperature 5 times and average it. I've read a lot about the millis function vs delay. I'm just not sure how to code it.

Could anyone share some example code of how to do this??

Thanks!

Start with the blink without delay example. Put your temperature code in place of the code that manipulates the LED.

annachaffee:
Hello! I am very new to the arduino coding world…I’m trying to code a temperature sensor to come on every thirty minutes, take the temperature 5 times and average it. I’ve read a lot about the millis function vs delay. I’m just not sure how to code it.

Could anyone share some example code of how to do this??

const unsigned long MillisecondsPerSecond = 1000UL;
const unsigned long SecondsPerMinute = 60UL;
const unsigned long ThirtyMinutes = 30UL * SecondsPerMinute * MillisecondsPerSecond;
unsigned long StartMillis = 0;
void setup()
{
}

void loop()
{
    if (mills() - StartMillis >= ThirtyMinutes)
    {
        StartMillis += ThirtyMinutes;
        // Average five temperature readings
        float averageTemperature = 0;
        for (byte i=0; i<5; i++)
        {
            averageTemperture += getTemperature();
        }
        averageTemperature /= 5.0;
    }
}