Help! Reset value back to 0?

Here is the problem; every time I run my program and the x-band sensor is triggered, it stays triggered and wont reset. For example: In serial monitor the x band sensor detects a range of 100-400 microvolts in normal non-triggering conditions, but when 500 microvolts are reached say by someone walking in front of the sensor, then an event is supposed to be triggered (turn on a set of LED lights). The problem is that once the 500 microvolt threshhold is crossed, it does not seem to reset back to its normal state. The event in serial monitor will look something like this, “300, 305, 300, 200, 300, 400, 528 TRIGGERED, 528 TRIGGERED, 528 TRIGGERED, 528 TRIGGERED, 528 TRIGGERED…” and will keep on displaying “528 TRIGGERED” well after the subject has moved away and there is no motion being detected.

Here is my code:

int calibrationTime = 15;   
int resetPin = 12;
int sensorpin = 0;                 // analog pin used to connect the radar
int val = 0;                 // variable to store the values from sensor(initially zero)
int ledPin = 6; // choose the pin for the LED 
const int threshold = 500;   // an arbitrary threshold level that's in the range of the analog input
const int analogPin = 0;    // pin that the sensor is attached to

const int numReadings = 15;

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int inputPin = A0;

void setup()
  // initialize serial communication with computer:
  // initialize all the readings to 0: 
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;          
pinMode(ledPin, OUTPUT);      // sets the digital pin as output

void loop() {
  // subtract the last reading:
  total= total - readings[index];         
  // read from the sensor:  
  readings[index] = analogRead(inputPin); 
  // add the reading to the total:
  total= total + readings[index];       
  // advance to the next position in the array:  
  index = index + 1;                    

  // if we're at the end of the array...
  if (index >= numReadings)              
    // ...wrap around to the beginning: 
    index = 0;                           

  // calculate the average:
  average = total / numReadings;         
  // added output module  
  // triggering protocol
  // if the analog value is high enough, turn on the LED:
  if (average >= threshold) {
    digitalWrite(ledPin, HIGH);
    index = 0;
  else {
  // send it to the computer as ASCII digits
  delay(20);        // delay in between reads for stability            

Any help would be greatly appreciated!!!

You have a 2 second delay after each “triggered” print, so you basically only take 1 sample every 2 seconds while the text is printed. It takes a long time before the average decreases with that sampling rate. Also I think you should remove setting index to zero when you print the “triggered” text.

Hope this helps!

Lowering the delay and removing index 0 did the trick. Thank you, ph77!!!

You're welcome! Glad it worked!