Averaging analog signal

Something like this is what you’re after, I think.

unsigned int numReadings = 30;
unsigned int readingCursor = 0;

float readings[numReadings]; // assuming the readings are float, if they're not, use:
//int readings[numReadings];

float latestAverage = 0.0;

void loop() {
    if (readingCursor != numReadings) {
        // take the reading, increment the cursor
        readings[readingCursor % numReadings] = analogRead(inputPin);
        readingCursor++;
    
        // add a delay so you don't take all measurements at once.
        delay(100);
    } else { // time to make the donuts
        float sum = 0.0; // will hold the sum of all sensor readings.

        // add up all the measurements...
        for (int i = 0; i < numReadings; i++) {
            sum += readings[i];
        }
    
        // and divide by the number of measurements to get the average
        latestAverage = sum / numReadings;

        Serial.println(latestAverage);
        // publish here, possibly.
        //Particle.publish("avg", latestAverage);

        // reset
        readingCursor = 0;
    }
}