arduino mega sonar and relay problem

I am having a problem solving this straight forward program I wrote for Arduino Mega.
#include <LiquidCrystal.h>
LiquidCrystal lcd(5,4,3,2,9,10,11);

int spump1 = 26;
int pumpB = 28;
int pumpC = 29;
int trig1 = 22;
int echo1 = 23;
int trig2 = 24;
int echo2 = 25;
int valve1 = 30;
int valve2 = 31;

void setup() {

// set min max on both tanks

pinMode(spump1, OUTPUT);
pinMode(pumpB, OUTPUT);
pinMode(pumpC, OUTPUT);
pinMode(trig1, OUTPUT);
pinMode(echo1, INPUT);
pinMode(trig2, OUTPUT);
pinMode(echo2, INPUT);
pinMode(valve1, OUTPUT);
pinMode(valve2, OUTPUT);
digitalWrite(spump1, LOW);
digitalWrite(pumpB, LOW);
digitalWrite(pumpC, LOW);
digitalWrite(valve1, LOW);
digitalWrite(valve2, LOW);


void loop() {
// Start of tank run
// sonar ping routine

long duration1, distance1;
digitalWrite(trig1, LOW);
digitalWrite(trig1, HIGH);
digitalWrite(trig1, LOW);
duration1=pulseIn(echo1, HIGH);
distance1 = (duration1/2)/29.1;
long duration2, distance2;
delay (2);
digitalWrite(trig2, HIGH);
delay (10);
digitalWrite (trig2, LOW);
distance2 = (duration2/2)/29.1;

lcd.print(“Sanzfield 2017”);

if (distance1 >= 90 and pumpB == LOW)
digitalWrite(spump1, HIGH);
lcd.print(“Sump1 on”);
else if (distance1 <= 10); //cycle start for tank B
digitalWrite (spump1, LOW);
delay (2000);
lcd.print(“Sump1 off”);
delay (2000);
lcd.print (“B Cycle Start”);
digitalWrite(pumpB, HIGH);
delay (432000000);
lcd.print (“cycle end”);

digitalWrite(valve1, HIGH); //start transfer to TankC
if (distance2 >= 10)
digitalWrite(pumpB, LOW);
digitalWrite(valve1, LOW);
digitalWrite(pumpC, HIGH);
delay (3600000);


I could use some input as I am new at this and have a dead line. Please.
I just need to know if this correct in layout and function?

Please read and follow the directions in the "How to use this forum" post.

Post the code properly, and describe the problem.

I keep having the routine get stuck in a loop at end of ELSE IF statement.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

What is your code doing and not doing? Did you write this code in stages?

Have you considered using newPing library, it will simplify your code.

It includes simple example code.

Before you repost your code, while in the IDE press CTRL-T, this will format your code with indents to help show your statement loops.

Can you post a diagram of the tank/sensor/pumps arrangement. Can you also post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :) PS I know its a lot, but you haven't supplied anything about your project to help us give you any advice.

Amakrok: I keep having the routine get stuck in a loop at end of ELSE IF statement.

Because delay (432000000); is 120 hours and delay (3600000); is one hour

Your routine was not stuck, it do what you have instructed.