would like to use ping sensors to control a relay

hello i would like to use 3 ping sensors to control relays on my aquarium here is the code i have so far that has the ping sensors writing distances in the serial monitor can someone point me in the right direction to make these sensor readings turn relays off and on
thanks for any help James

/*-----( Import needed libraries )-----*/
#include <NewPing.h>
#include <LiquidCrystal_I2C.h>
#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

/*-----( Declare Constants )-----*/
const int float1Pin = 22;
const int ledPin = 13;
int float1State = 0;

/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address


#define SONAR_NUM     3 // Number or sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 1000 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).

unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
unsigned int cm[SONAR_NUM];         // Where the ping distances are stored.
uint8_t currentSensor = 0;          // Keeps track of which sensor is active.

NewPing sonar[SONAR_NUM] = {     // Sensor object array.
  NewPing(22,23 , MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
  NewPing(24,25 , MAX_DISTANCE),
  NewPing(26,27 , MAX_DISTANCE),
 
};

/*-----( Declare Variables )-----*/
//none

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  pinMode(ledPin, OUTPUT);
  pinMode(float1Pin, INPUT);
  
  
  Serial.begin(9600);  // Used to type in characters
 while (!Serial) ; // wait until Arduino Serial Monitor opens
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet) 
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");  
  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines and turn on backlight

// ------- Quick 3 blinks of backlight  -------------
  for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight(); // finish with backlight on  
  

  

 
  
  pingTimer[0] = millis() + 75;           // First ping starts at 75ms, gives time for the Arduino to chill before starting.
  for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;


}/*--(end setup )---*/


void loop() { 
  float1State = digitalRead(float1Pin);
  
  if (float1State == HIGH) digitalWrite(ledPin, HIGH);
  
  else digitalWrite(ledPin, LOW);
  
  
  if (timeStatus() == timeSet) {
    digitalClockDisplay();
  } else {
    Serial.println("The time has not been set.  Please run the Time");
    Serial.println("TimeRTCSet example, or DS1307RTC SetTime example.");
    Serial.println();
    delay(4000);
  }
  delay(1000); for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
    if (millis() >= pingTimer[i]) {         // Is it this sensor's time to ping?
      pingTimer[i] += PING_INTERVAL * SONAR_NUM;  // Set next time this sensor will be pinged.
      if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results.
      sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
      currentSensor = i;                          // Sensor being accessed.
      cm[currentSensor] = 0;                      // Make distance zero in case there's no ping echo for this sensor.
      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
    }
  }
  // The rest of your code would go here.
}

void echoCheck() { // If ping received, set the sensor distance to array.
  if (sonar[currentSensor].check_timer())
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
}

void oneSensorCycle() { // Sensor ping cycle complete, do something with the results.
  for (uint8_t i = 0; i < SONAR_NUM; i++) {
    Serial.print(i);
    Serial.print("=");
    Serial.print(cm[i]);
    Serial.print("cm ");
  }
  Serial.println();
}


void digitalClockDisplay(){// displays clock on a 20x4 lcd
  lcd.setCursor(0,0); //Start at character 0 on line 0
  
  lcd.print(hour());
  lcd.print(":");
  lcd.print(minute());
  lcd.print(":");
  lcd.print(second());
  lcd.setCursor(0,1);
   
  lcd.print(month());  
  lcd.print("/");
  lcd.print(day());
  lcd.print("/");
  lcd.print(year());
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
  
  
}
/*-----( Import needed libraries )-----*/

You aren't importing anything.

can someone point me in the right direction to make these sensor readings turn relays off and on

No. Only you know what a specific reading from a specific sensor (or range of readings) is supposed to do.

PS i did a search on the forum to try and find something for what i plan on doing but it returned nothing that i could use or atleast what i felt was of use. also please excuse the poor programming code i am new to arduino and still learning a lot and just copied code that seems to work towards what i am ultimately trying to accomplish thanks again james

i would like the ping sensors to turn 3 relays on when an unknown value at this time is returned and turn them off when another unknown value is returned they will be controlling the water levels in my automatic top off , water change ,and main display tanks

i would like the ping sensors to turn 3 relays on when an unknown value at this time is returned and turn them off when another unknown value is returned they will be controlling the water levels in my automatic top off , water change ,and main display tanks

It doesn't work that way. The sensors can't turn relays on or off. The Arduino can read a sensor, and make a decision, based on the value that it read, to turn a pin on or off. It can't do that based on unknown values, though. You will have to experimentally determine the correct values, and connect the relays to the Arduino correctly (using transistors, most likely).

thanks paul for the replies! i know that i will have to connect the relays to the arduino with transitters i already have these boards ready for use but i know nothing about how to tell the arduino to take the reading from ping sensor 1 etc. and make pin say 29 high to energize the relay controlling a pump. i have the mechanical and electrical part of this project under control but just cant get a grasp on how to get the coding right to do this

i have the mechanical and electrical part of this project under control but just cant get a grasp on how to get the coding right to do this

Read your own comments:

      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
void echoCheck() { // If ping received, set the sensor distance to array.
  if (sonar[currentSensor].check_timer())
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
}
void oneSensorCycle() { // Sensor ping cycle complete, do something with the results.
  for (uint8_t i = 0; i < SONAR_NUM; i++) {
    Serial.print(i);
    Serial.print("=");
    Serial.print(cm[i]);
    Serial.print("cm ");

It really isn’t rocket science to write code that looks like:

if(cm[i] > almostEmptyTank[i])
  turnPumpOn(i);
else if cm[i] < almostFullTank[i])
  turnPumpOff(i);

I’ll leave it to you to determine the type and initial values of almostEmptyTank and almostFullTank, and where to put that code.

thank you paul for getting me guided in the right direction to me as a noob to arduino your are a rocket scientist !!! thanks james

thanks paul once i sat down and really got to concentrate on your quote the light bulb went off and i have it solved thanks again for your help James

I urge you to have a secondary system, for emergency situations, which turns off the water if tank happens to overflow.