Output to off switching off after 1 sec with Relay Switch

Hi there,

I finally got an Arduino and am playing around with it. I want it to turn on a relay switch for 20 seconds. Reading the output, the code seems to be correct, but the relay closes after ~1 second. Here's the code

int Cap1_Vcc = 50;
int Cap1_Aout = A0;
int led = LED_BUILTIN;
int Pump1 = 37;
int cap;
int out;


void setup() {
  pinMode(Cap1_Vcc,OUTPUT);
  pinMode(Cap1_Aout,INPUT);
  Serial.begin(9600);
  pinMode(Pump1,OUTPUT);
}



void loop() {
  // put your main code here, to run repeatedly:

  
  digitalWrite(Cap1_Vcc ,HIGH);
  
  delay(1000);
  cap=analogRead(Cap1_Aout);
  Serial.print(out + "\t");
  Serial.print(cap);
  Serial.print("\n");
  digitalWrite(Cap1_Vcc,LOW);
  if (cap<400)
  {
    digitalWrite(Pump1,HIGH);
    Serial.print("Pump1 on\n");
    delay(20000);
    Serial.print("Pump1 off\n");
    digitalWrite(Pump1,LOW);
  }
  delay(1000);
}

Is the board faulty or am I doing something silly? Thanks.

am I doing something silly?

You're posting in italics, in the wrong forum section.

Oh - my bad. I thought this was Troubleshooting for problems with Arduino itself... Oh wait - actually it is.

munkifisht:
Oh - my bad. I thought this was Troubleshooting for problems with Arduino itself... Oh wait - actually it is.

But you don't have problems with the Arduino. You have problems with your code or your hardware or connections i.e. your project. And this section clearly says "For problems with Arduino itself, NOT your project".

I'm guessing your relay is called Pump1? What do the Serial.print()s show? How is everything powered and connected.

Steve

Nothing's connected yet. I'm testing the outputs with a multimeter directly on the board.

munkifisht:
Nothing's connected yet. I'm testing the outputs with a multimeter directly on the board.

That's good, connecting a relay directly to an Arduino will most probably make it faulty. which pin are you planning to use as the pin to switch the relay ? maybe you could just add some comments at variable declaration.