Sump Pump Controller

I usually am good about finding the answers online but I feel like I have met my match with the arduino. I am posting here looking for assistance with programming my arduino to control a sump pump. Currently, my sump pump is in a sealed well do to radon remediation. The float switch has a very short travel so the water level is determined by how deep the pump sits in the well.

I would like to make a new trigger system for turning the pump on and off. I want to have a high float switch so that when the water level lifts it up it will turn the pump on. Once the water level drops below the low float switch, the pump will turn off. I would like to also have another float switch to trigger my pump alarm system (pitboss) should the pump fail to turn on and the water level gets too high.

Hardware: I have plastic float switches to go in the sump well. A relay that can control 110V. Pitboss alarm system (needs the circuit to be closed to activate alarm).

Issue: I am still very new to using the arduino in projects. I just haven't had/spent the time to read a book on programming. I am looking for help with the code that I wrote already. I tried to copy one that I saw from another sump pump project. I could not use that code exactly because it only had one float switch. Please help in any way.

// Sump Pump Controller

define FLOAT_1_LOW 2 //Low level float switch

define Pump_1_LED 3 //Pump LED

define FLOAT_1_HIGH 4 //High level float switch

define FLOAT_1_ALARM 5 //Alarm float switch

define ALARM 6 //pitboss alarm

define PUMP_1 7 //pump motor

void setup() { // put your setup code here, to run once: pinMode(FLOAT_1_LOW, INPUT); pinMode(Pump_1_LED, OUTPUT); pinMode(FLOAT_1_HIGH, INPUT); pinMode(FLOAT_1_ALARM, INPUT); pinMode(ALARM, OUTPUT); }

void loop() { // Once the high float is lifted (full well) the pump will turn on // Once the water level reaches the low level float then the pump will be shut off. // If the water level reaches the Alarm float, then the pump alarm is activated

if(digitalRead(FLOAT_1_HIGH) == HIGH) { digitalWrite(PUMP_1, HIGH); //turn on the pump digitalWrite(PUMP_1_LED, HIGH); //turn on led }

if(digitalRead(FLOAT_1_LOW) == LOW) { digitalWrite(PUMP_1, LOW); //turn off the pump digitalWrite(PUMP_1_LED, LOW); //turn off led }

if(digitalRead(FLOAT_1_ALARM) == HIGH) { digitalWrite(ALARM, HIGH) //trigger alarm } }

What exactly isn't working with your code? Also do you have any pictures of your circuit and could you provide a link to the float switches you're using?

When I went to verify the code before programming it into the UNO, it gives me a error message below:


/Users/Ryan/Documents/Arduino/Sump_Pump_Controller/Sump_Pump_Controller.ino: In function ‘void loop()’:
Sump_Pump_Controller:27: error: ‘PUMP_1_LED’ was not declared in this scope
digitalWrite(PUMP_1_LED, HIGH); //turn on led
^
Sump_Pump_Controller:33: error: ‘PUMP_1_LED’ was not declared in this scope
digitalWrite(PUMP_1_LED, LOW); //turn off led
^
Sump_Pump_Controller:39: error: expected ‘;’ before ‘}’ token
}
^
exit status 1
‘PUMP_1_LED’ was not declared in this scope

Here is link you requested for the float switches and the link for the relay I am using. Thanks for taking the time!

C++ is case sensitive.

Like aarg mentioned, C++ is case sensitive and your "PUMP_1_LED" variable was not the same case in certain places. Additionally you were missing the semi-colon here:

  if(digitalRead(FLOAT_1_ALARM) == HIGH)
  {
    digitalWrite(ALARM, HIGH);          //trigger alarm
  }

This is the fixed code, which should work:

// Sump Pump Controller

#define FLOAT_1_LOW 2      //Low level float switch
#define PUMP_1_LED 3       //Pump LED
#define FLOAT_1_HIGH 4     //High level float switch
#define FLOAT_1_ALARM 5    //Alarm float switch
#define ALARM 6            //pitboss alarm
#define PUMP_1 7           //pump motor

void setup() {
  // put your setup code here, to run once:
  pinMode(FLOAT_1_LOW, INPUT);
  pinMode(PUMP_1_LED, OUTPUT);
  pinMode(FLOAT_1_HIGH, INPUT);
  pinMode(FLOAT_1_ALARM, INPUT);
  pinMode(ALARM, OUTPUT);
}

void loop() {
  // Once the high float is lifted (full well) the pump will turn on
  // Once the water level reaches the low level float then the pump will be shut off.  
  // If the water level reaches the Alarm float, then the pump alarm is activated

  if(digitalRead(FLOAT_1_HIGH) == HIGH) 
  {
    digitalWrite(PUMP_1, HIGH);       //turn on the pump
    digitalWrite(PUMP_1_LED, HIGH);   //turn on led  
  }
  
  if(digitalRead(FLOAT_1_LOW) == LOW)
  {
    digitalWrite(PUMP_1, LOW);        //turn off the pump
    digitalWrite(PUMP_1_LED, LOW);    //turn off led 
  }

  if(digitalRead(FLOAT_1_ALARM) == HIGH)
  {
    digitalWrite(ALARM, HIGH);          //trigger alarm
  }
}

Thank you everyone for the help!

Does this code missing a: pinMode(PUMP_1 , OUTPUT);??