coding help

so I have a piece of code that senses a voltage using a resistor bridge and uses it if it passes a set trigger point to turn on or off an output, the problem is it only does it once and doesn't look like its looping. i am making a small solar setup to power a fountain in my garden, and going to use the output of the solar panels once high enough to trigger a relay to turn on the pump so its not running of the battery all night

int sensorPin = A1; // Voltage Sensor connected to A1
int sensorValue; // variable to store the value coming from the voltage sensor
int previousSensorValue;
int testLED = 9;
boolean timing = false;
unsigned long startTime;
unsigned long onTime = 2000;

void setup()
{
Serial.begin(9600); // initialize the serial port
pinMode(sensorPin, INPUT); // sets analog pin A1 to be an input
pinMode(testLED, OUTPUT); // sets digital pin 9 to be an output
}

void loop()
{
previousSensorValue = sensorValue;
sensorValue = analogRead(sensorPin); // read the value from the voltage sensor
Serial.println(sensorValue);
if (sensorValue >= 200 && previousSensorValue < 200)
{
timing = true;
startTime = millis();
digitalWrite(testLED, HIGH); //turns on led connected to digital pin 9
}

if (timing && millis() - startTime >= onTime)
{
digitalWrite(testLED, LOW);
timing = false;
}
}

See how to post the code on Arduino Forum

You realize as long as if() evaluates, you are restarting the TIMER.
startTime = millis();

if (sensorValue >= 200 && previousSensorValue < 200)
{
timing = true;
startTime = millis();
. . .


Did you want:

if (timing == false && sensorValue >= 200 && previousSensorValue < 200)

What you have will turn the LED on for 2 seconds each time the input CHANGES from <200 to >=200. Once the two seconds is up the input has to go below 200 and then above 200 to start a new 2-second ON period.

Did you want the LED to stay ON when the input is >= 200 and turn off two seconds after the input goes below 200? Then you don't need to detect the state change:

 if (sensorValue >= 200)
  {
    timing = true;
    startTime = millis();
    digitalWrite(testLED, HIGH);  //turns on led connected to digital pin 9
  }