Can't change milliseconds to a higher number

Hi Guys, still green to arduino, the code below is simple, i'm trying to start a pump when it gets to the top of the bowl via a moisture sensor and it works after following youtube video but it wont allow me to choose a delay from 400 to higher to 6000 or 9000.

I'm trying to have the pump work for 1 minute after it sees the water but when i change the 400 delay to 4000 it only delays by 2 seconds :

int ACWATERPUMP = 2; //You can remove this line, it has no use in the program.
int sensor = A0; //You can remove this line, it has no use in the program.
int val; //This variable stores the value received from Soil moisture sensor.
void setup() {
  pinMode(2,OUTPUT); //Set pin 13 as OUTPUT pin, to send signal to relay
  pinMode(A0,INPUT); //Set pin 8 as input pin, to receive data from Soil moisture sensor.
}

void loop() { 
  val = digitalRead(A0);  //Read data from soil moisture sensor  
  if(val == LOW) 
  {
  digitalWrite(2,LOW); //if soil moisture sensor provides LOW value send LOW value to relay
  }
  else
  {
  digitalWrite(2,HIGH); //if soil moisture sensor provides HIGH value send HIGH value to relay
  }
  delay(400); //Wait for few second and then continue the loop.
}

Maximum for delay() function is something like 4,294,967,295. A bit more than 9000.

Looks like you are only doing a loop on...

digitalWrite(2,digitalRead(A0));
delay(400);

How do you know it is only delaying for 2 seconds with delay(4000)? I suspect it is delaying exactly the time you are asking it to delay but you don't have a way to know that.

What Arduino do you have, what have you selected in the IDE as the board?

.

larryd:
What Arduino do you have, what have you selected in the IDE as the board?

.

I have a genuine UNO, its selected as UNO.

I wanted a delay after it sees the water via the moisture sensing probes and to then run for 1 minute allowing the pump to drain the water, i naturally increasing the delay from 400 to 10000 but still no go, currently testing this with the USB and then unplugging it, connecting ti to 9V external thinking it was a power issue but same thing.

I was going to try this instead of the simple code but i kept on getting an error about the ELSE statement thats in the original code:

was going to try to add this in BOLD but received errors.

int ACWATERPUMP = 2; //You can remove this line, it has no use in the program.
int sensor = A0; //You can remove this line, it has no use in the program.
int val; //This variable stores the value received from Soil moisture sensor.
void setup() {
  pinMode(2,OUTPUT); //Set pin 13 as OUTPUT pin, to send signal to relay
  pinMode(A0,INPUT); //Set pin 8 as input pin, to receive data from Soil moisture sensor.
}

void loop() { 
  val = digitalRead(A0);  //Read data from soil moisture sensor  
  if(val == LOW) 
  {
  digitalWrite(2,LOW); //if soil moisture sensor provides LOW value send LOW value to relay
  }
[b]delay(5000);
}[/b]
  else
  {
  digitalWrite(2,HIGH); //if soil moisture sensor provides HIGH value send HIGH value to relay
  }
  delay(400); //Wait for few second and then continue the loop.
}

What soil sensor are you using that returns a digital signal? Most are connected to A0 because they return an analog signal that represents varying soil resistance. Like the one from SparkFun.

Why don't you change pin 2 to pin 13 where the UNO has a built-in LED.

Now you can watch the state change on A0. (if it does indeed change).

If you have an analog sensor you might want to follow the SparkFun tutorial.

epsilon:
was going to try to add this in BOLD but received errors.

You have an unnecessary } on line 16 which makes the compiler think that is the end of the program.

Also, you can't put BOLD text in a code window. If you want to identify something put in a comment like this

// <--------- want to add code here

...R

wzaggle:
What soil sensor are you using that returns a digital signal? Most are connected to A0 because they return an analog signal that represents varying soil resistance. Like the one from SparkFun.

Why don't you change pin 2 to pin 13 where the UNO has a built-in LED.

Now you can watch the state change on A0. (if it does indeed change).

If you have an analog sensor you might want to follow the SparkFun tutorial.

I have this moisture sensor sensor

If i change the from pin 2 to 13; i can still operate something else in programming other than the LED or it will operate something from pin 13 and the LED as well ?

"If i change the from pin 2 to 13; i can still operate something else in programming other than the LED or it will operate something from pin 13 and the LED as well ?"

Would you please try rewording this.

Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

epsilon:
If i change the from pin 2 to 13; i can still operate something else in programming other than the LED or it will operate something from pin 13 and the LED as well ?

You can attach a relay to pin 13, and the relay will operate the same way as it would on any other pin.

aarg:
You can attach a relay to pin 13, and the relay will operate the same way as it would on any other pin.

Thank you, that's what i was asking, now someone here asked if i can change pin 2 to 13 and then i could see the state change in A0, is that because while i'm in pin 2 i cant see state change ?