Program not working- too much activates at once!

Hi All,

New to arduino. Have been watching and reading but still not sure how to code. Have written code to control 3 solenoids and a vacuum pump. goes haywire when run. Any pointers? Want to able to do this and more so would like to learn what is wrong and how to fix.

The idea is to have pin 2 open for a time, time in code is just to see if it works, all other solenoids closed. once pressurized it will hold for 1 hour. Open drain valve then drain close and vacuum solenoid and pump on, then shutdown and hold vacuum for an hour and repeat.

Any help greatly appreciated.

Cheers Mates.

Pressure_pot_1.ino (659 Bytes)

Are your solenoids and pump connected directly to the Arduino pins ?

The correct answer is no

there is nothing wrong with this code. must be a problem with your hot tub time machine or whatever you are connected to !

Sorry, I can’t open your code on a mobile device to look at it.
Please check the forum guide on how to post your code, then someone will likely try to help.

lastchancename:
Sorry, I can’t open your code on a mobile device to look at it.
Please check the forum guide on how to post your code, then someone will likely try to help.

Why is this considered to be a problem with how the code was posted, rather than a problem with your mobile device?

I don’t have any text editor on my mobiles that can open an INO file.
All strength to you.
It is generally accepted that shorter programs will get more/faster replies if they are posted inline with tags - but with 1500+ posts, you already knew that.

OP’s code:

int pressure =2; //
int drain =3; //
int vacuum =4; //
int pump =5; // put your setup code here, to run once:


void setup() {
pinMode (2, OUTPUT); //   
pinMode (3, OUTPUT); //
pinMode (4, OUTPUT); //
pinMode (5, OUTPUT); //
   
 }
void loop() {
  digitalWrite (pressure, HIGH) ;//
  delay (5000); //
  digitalWrite (pressure, LOW) ;//
  delay (20000) ;//
  digitalWrite (drain, HIGH) ;//
  delay (20000) ;//
  digitalWrite (drain, LOW) ;//
  digitalWrite (vacuum, HIGH) ;
  digitalWrite (pump, HIGH) ;//
  delay (10000) ;//
  digitalWrite (vacuum, LOW) ;
  digitalWrite (pump, LOW) ;//
  delay (20000) ;// put your main code here, to run repeatedly: 
  
}

Posted from my 5-year-old Android phone.

As @taterking noted in reply #2 above - your code should work as is, but if you want to expand it later or add a 'cancel' button that is expected to respond in less than 75 seconds - you'll need to change the timing method (to use millis()).

I added the pin aliases into setup()

int pressure = 2;
int drain = 3;
int vacuum = 4;
int pump = 5;

void setup() {
  pinMode (pressure, OUTPUT); //   
  pinMode (drain, OUTPUT); //
  pinMode (vacuum, OUTPUT); //
  pinMode (pump, OUTPUT); //
}

void loop() {
  digitalWrite (pressure, HIGH) ;//
  delay (5000); //
  digitalWrite (pressure, LOW) ;//
  delay (20000) ;//
  digitalWrite (drain, HIGH) ;//
  delay (20000) ;//
  digitalWrite (drain, LOW) ;//
  digitalWrite (vacuum, HIGH) ;
  digitalWrite (pump, HIGH) ;//
  delay (10000) ;//
  digitalWrite (vacuum, LOW) ;
  digitalWrite (pump, LOW) ;//
  delay (20000) ;
}

Your problem could be in the wiring or power supply.
Can you sketch out how its wired together with all capacitors, diodes as added in your build.
(Check up on the way to attach & post images in-line)

Cheers

Are you using relay modules to control your solenoids and the vacuum pump? Remember that most relay modules activate the relay when the output is LOW and deactivate the relay when the output is HIGH.

Better variable names make it easier to tell what the sketch is trying to do, as do non-empty comments:

const byte PressureizedAirInputValvePin = 2;
const byte PressureDrainValvePin = 3;
const byte VacuumPortValvePin = 4;
const byte VacuumPumpMotorPin = 5;


// Solenoid valves driven by relay modules
const bool OPEN = LOW;
const bool CLOSE = HIGH;


// Vacuum pump motor controlled by a relay module.
const bool RUN = LOW;
const bool STOP = HIGH;


void setup()
{
  digitalWrite(PressureizedAirInputValvePin, CLOSE);
  pinMode (PressureizedAirInputValvePin, OUTPUT);


  digitalWrite(PressureDrainValvePin, CLOSE);
  pinMode (PressureDrainValvePin, OUTPUT);


  digitalWrite(VacuumPortValvePin, CLOSE);
  pinMode (VacuumPortValvePin, OUTPUT);


  digitalWrite(VacuumPumpMotorPin, STOP);
  pinMode (VacuumPumpMotorPin, OUTPUT);
}


void loop()
{
  digitalWrite (PressureizedAirInputValvePin, OPEN);  // Perzssure in
  delay (5000);
  digitalWrite (PressureizedAirInputValvePin, CLOSE); // Stop adding pressure
  delay (20000) ;
  digitalWrite (PressureDrainValvePin, OPEN); // Release pressure
  delay (20000) ;
  digitalWrite (PressureDrainValvePin, CLOSE);  // Stop pressure release


  digitalWrite (VacuumPortValvePin, OPEN);  // Allow vacuum
  digitalWrite (VacuumPumpMotorPin, RUN) ; // Run vacuum pump
  delay (10000) ;
  digitalWrite (VacuumPortValvePin, CLOSE);  // Close the vacuum port
  digitalWrite (VacuumPumpMotorPin, STOP);  // Trn off the vacuum pump
  delay (20000) ;
}

Hi,

Thanks for the replies.

Yes the solenoids and vacuum pump are connected through relays. 5v activation. I have run the led flash code and the pin activates and solenoid works, changed each signal wire to run the whole system one pin at a time.

I will use the slightly different code with the pin numbers in beginning and see how it goes. Will take pics and do circuit drawing.

Cheers guys,

Not trying to be passive-aggressive... but

Your problem could be in the wiring or power supply.
Can you sketch out how its wired together with all capacitors, diodes as added in your build.
(Check up on the way to attach & post images in-line)

Hi All,

No issues with wiring or relays. Code from Aug 28, 2019, 06:28 pm Last Edit: Aug 28, 2019, 06:29 pm by lastchancename works a treat. think it was how i finished the last line with double forward slashes or something.

Thanks for all the help.

Regards,

Gavin

As far as I know, there is no problem with the code. I think there must be a problem with the hot tub machine or the device you are connected with.

Or the wiring / noise filtering.