If Statement

I'm trying to figure out how to use the "If Statement" in my program (Not finished). I have a pump (runs 1 minute), heating element (2 hours) & solenoid (runs 1 minute) that is setup to work one right after another, one at a time. I'm using the arduino uno and a 4 module relay (For 120 vac circuits).

//Process: Fill pot (Pump), cook (Heater element) for 2 hours, then drain (Solenoid).

int pump = 7; int element = 8; int solenoid = 9;

void setup() {

//pinMode(pump, OUTPUT);

digitalWrite(pump, HIGH); // turn the pump on (HIGH is on) Relay 1 closed delay(1000); // pump on for 1 minute digitalWrite(pump, LOW); // turn the pump off (LOW is off) Relay 1 open delay(120000); //pump off for 2 hours } digitalWrite(element, HIGH); // turn the element on (HIGH is on) Relay 2 closed delay(120000); // pump on for 2 hours digitalWrite(element, LOW); // turn the element off (LOW is off) Relay 2 open delay(122000); //pump off for 2 hours 2 minutes } digitalWrite(solenoid, HIGH); // turn the solenoid on (HIGH is on) Relay 3 closed delay(1000); // solenoid on for 1 minute digitalWrite(solenoid, LOW); // turn the solenoid on (Low is off) Relay 3 open void loop()( }

So where does the if come into it?

I don’t know about an if, but those { } braces need tidying up.

void setup()
{

//pinMode(pump, OUTPUT);

digitalWrite(pump, HIGH);   // turn the pump on (HIGH is on) Relay 1 closed
  delay(1000);               // pump on for 1 minute
  digitalWrite(pump, LOW);    // turn the pump off (LOW is off) Relay 1 open
  delay(120000); //pump off for 2 hours
}
digitalWrite(element, HIGH);   // This isn't in a function. Oops.

And the missing code tags.

//pinMode(pump, OUTPUT);
pinMode(pump, OUTPUT); //You need one of these for each OUTPUT

delay(1000); // pump on for 1 minute These are milliseconds <<< this is 1 second
delay(60000); //<<<<60 seconds

I recommend you to go though the example sketches in the Arduino IDE before you attempt any more programming.

Yes...I'm new to programming, will have to correct my initial code. To give you a better synopsis, after the pot is filled by the pump, then the heat element is turned on (This is only when the pot is full). After cooking, the element shuts off and the pot is drained with a solenoid. So "If" the pot is empty, then the element can not be turned on. "If" the pump is on then the solenoid cannot be on, vise versa. One component at a time. I appreciate any corrections or additions to my existing program.

As you realise there is nothing in your code to ensure that the conditions you outline are true before carrying out the next action. In order to test whether it is safe to proceed to the heating phase you need to be able to sense the level of water in the pot. You can ensure that the solenoid cannot be on when the pump is on by doing things in sequence as you do at the moment.

Incidentally, it would be better to use a while rather than an if to test the water level.

while the pot is not full
  run the pump
end of while
stop pump
start the heater

Hoosier1: I'm trying to figure out how to use the "If Statement" in my program (Not finished). I have a pump (runs 1 minute), heating element (2 hours) & solenoid (runs 1 minute) that is setup to work one right after another, one at a time. I'm using the arduino uno and a 4 module relay (For 120 vac circuits).

//Process: Fill pot (Pump), cook (Heater element) for 2 hours, then drain (Solenoid).

int pump = 7;
int element = 8;
int solenoid = 9;

void setup() { //pinMode(pump, OUTPUT);

digitalWrite(pump, HIGH);  // turn the pump on (HIGH is on) Relay 1 closed   delay(1000);              // pump on for 1 minute   digitalWrite(pump, LOW);    // turn the pump off (LOW is off) Relay 1 open   delay(120000); //pump off for 2 hours

Once the pump has been on for 1 minute you want to wait for 2 hours before the next step? That's what you've told it to do. When you switch your bedroom light off, do you need to tell it how long it will be off for? Or does it stay off until you switch it on again?

Actually yes, pump is off while the heat element is on for two hours. I have updated my incorrect time based on 1000 = 1sec. I was able to get the program to work. I need to add a level switch in the circuit as a safety for the element and may tie that in as shutoff for the pump opposed to timer. Also, want to control the heat element with a thermometer probe, either adjust the amount of current or turn it off and on. Any suggestions?

BTW, do something like this and your delays will be much more readable:

#define ONESEC 1000L
#define ONEMIN (60*ONESEC)
#define ONEHOUR (60*ONEMIN)
   :
  delay(2*ONEHOUR);

Hoosier1: . I need to add a level switch in the circuit as a safety for the element and may tie that in as shutoff for the pump opposed to timer.

You may want to do both, to limit the amount of spillage you get if your level sensor fails. As to measuring the temperature, a waterproof ds18b20 is a popular choice.