int motor = 6; //
int inpin = 7; // proximity sensor connected with the pin 2
int val = 0; // this variable will read the value from the sensor
unsigned long sensorAir = 0;
unsigned long running = 2777; // how long the pump will run after seeing air
void setup()
{
Serial.begin(9600);
pinMode(motor, OUTPUT);
pinMode(inpin, INPUT_PULLUP);
}
void loop()
{
delay(10); // just to cut down on printing.
val = !digitalRead(inpin); // ! so val true == pressed
unsigned long currentMillis = millis();
running = analogRead(A0) * 3;
if (val == HIGH) {
digitalWrite(motor, HIGH);
sensorAir = currentMillis;
Serial.println(running);
}
else {
if (currentMillis - sensorAir >= running)
digitalWrite(motor, LOW);
}
}