Can you make an input go low even when it is high?

IThis is what I am trying to do:
I what to start a pump when a input goes high from a water level switch (5v). When it does I will output a 5v to a relay which will turn on the pump. When the input pin goes low(water is filled) the output will go low and turn offf the pump. NOW i want a back up. When the Input goes High I want a timer (seconds) to start, I will know the how long it takes for the water to fill. If the input has not gone low in that certain amount of time(failure of the switch) I want the pump to stop so I dont get an overflow. Can this be done? I am a noobie so all help would be great.
Thabks in advance.
Daka

Yes, it can be done.

You need to move away from the concept of "states" (is the switch HIGH), and move on to the concept of events (has the switch changed from LOW to HIGH).

Then you turn the pump on when the switch GOES high, and switch it of when EITHER the switch GOES low, or the timer exceeds the limit.

Thanks majenko,
Could you give me an example of the code, I have other simular type uses too. It would be a big help. I could just mod as needed.Just learning code.
Thanks

Untested, just written "as is":

const int sensor = 4; // Sensor input pin
const int pump = 5; // Pump control pin
const unsigned long timeout = 10000; // 10 second timeout

void setup()
{
  pinMode(sensor,INPUT);
  pinMode(pump,OUTPUT);
  digitalWrite(pump,LOW);
}

void loop()
{
  static unsigned long pumpStarted = 0; // When was the pump started?
  static unsigned char lastState = LOW;  // Previous state of the sensor
  unsigned char currentState; // Current state of the sensor

  currentState = digitalRead(sensor);  // Get the sensor state
  if(currentState != lastState)  // Has it changed?
  {
    lastState = currentState;  // Store the current state.
    if(currentState == HIGH)  // Is it high?
    {
      digitalWrite(pump,HIGH);  // Start the pump.
      pumpStarted = millis();  // Remember when we started the pump.
    } else {
      digitalWrite(pump,LOW);  // Stop the pump.
      pumpStarted = 0;  // Forget that we started it
    }
  }

  if((pumpStarted>0) && ((millis()-pumpStarted)>timeout))  // Has the pump been running too long?
  {
    digitalWrite(pump,LOW);  // Stop the pump
    pumpStarted = 0; // forget we started it.
  }
}

Again, I must say this is 100% untested - I don't even know if it compiles, let alone works.

THANKS
It gives me a place to start.
And if anybody else has any ideas please jump in.
I will also have to add a statment that says check for the problem that caused it to turn off by time instead of the switch.

I will also have to add a statment that says check for the problem that caused it to turn off by time instead of the switch.

One solution to this is to add an LED which you turn on if you execute the timer pump stop logic.

Thanks WB

I tried to compile it, it errored because it had no setup so I changed the begin to setup and it compiled. Will check it out at more on bread brd to see if it all works.
Daka

Daka101:
Thanks WB

I tried to compile it, it errored because it had no setup so I changed the begin to setup and it compiled. Will check it out at more on bread brd to see if it all works.
Daka

D'oh... I keep doing that - I seem to have a begin/setup mental block thing going on...