Project 2 - Measuring the distance of an object using ultrasonic sensor and also smoothen the sensor data using moving average filter

int inches = 0;
#define SAMPLESIZE 10 // Filter Size Or Window Size
const int UL_PIN = 7;
int INDEX = 0;
int VALUE = 0;
int SUM = 0;
int avg[SAMPLESIZE];
int AVERAGE = 0;
int cm = 0;
void setup()
{
//pinMode(UL_PIN, INPUT); //ultrasonic sensor as input pin
Serial.begin(9600);
}
void loop()
{
pinMode(UL_PIN, OUTPUT);
digitalWrite(UL_PIN, LOW);
delayMicroseconds(2);
digitalWrite(UL_PIN, HIGH);
delayMicroseconds(5);
digitalWrite(UL_PIN, LOW);
//Moving average algorithm
SUM = SUM - avg[INDEX]; // subtract previous values
VALUE = analogRead(UL_PIN);// Read from ultrasonic sensor
SUM = SUM+VALUE;
INDEX = (INDEX+1)%SAMPLESIZE;//Increment the index and wrap it to zero if sample size is exceeded
AVERAGE = SUM / SAMPLESIZE; //Moving average formula
Serial.print(VALUE);
Serial.print(",");
//Serial.print("Smoothed:");
Serial.println(AVERAGE);
delay(5);
}