loupalladino
Published © GPL3+

Sump Pit Alarm

Homegrown sump pit monitor with Nagios integration.

IntermediateShowcase (no instructions)5,163
Sump Pit Alarm

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
Temp and humidity sensor not critical to this build, but I figured why not?
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
3 mm LED: Red
3 mm LED: Red
Red LED was salvaged from a malfunctioning strand of Christmas lights.
×1
3 mm LED: Green
3 mm LED: Green
Green LED was salvaged from a malfunctioning strand of Christmas lights.
×1
Buzzer
Buzzer
Buzzer was salved from a broken remote control car.
×1
2" PVC pipe
×1
2" PVC pipe coupling
×1
2" PVC pipe clean-out with lid
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Wire cutters/stripper

Story

Read more

Schematics

Pit Sensor Diagram

Wiring connections are missing.

Code

Pit Sensor Code

Arduino
// $Rev::                         $:  Version of last commit
// $Author::                      $:  Author of last commit
// $Date::                                                $

#include <DHT.h>;

// DHT22 sensor setup
#define DHTPIN 13
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

// pin setup
const int trigPin = 7;
const int echoPin = 8;
const int buzzerPin = 9;
const int redLed = 11;
const int greenLed = 12;

//Variables
float hum;
float temp;
long duration;
int distance;

void setup() {
  // HC-SR04
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  // LEDs
  pinMode(greenLed, OUTPUT);
  pinMode(redLed, OUTPUT);
  // Buzzer
  pinMode(buzzerPin, OUTPUT);
  //
  Serial.begin(9600); // Starts the serial communication
  dht.begin();
}

void loop() {
  // <---------------- HC-SR04 ------------------------->
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  // 10000ms is 10 seconds
  // 2000 ms is 2 seconds
  delay(5000);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance in cm
  distance = duration*0.034/2;

  // <---------------- DHT22 ------------------------->
  // Read data and store it to variables hum and temp
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  // Print temp and humidity values to serial monitor
  // Convert C to F
  temp = temp * 9/5 + 32;
  // Output
  Serial.print(temp);
  Serial.print("|");
  Serial.print(hum);
  Serial.print("|");
  Serial.println(distance);

  // <-------------- LEDs + buzzer ------------------------>
  if (distance <= 20)
    {
      digitalWrite(redLed, HIGH);
      digitalWrite(buzzerPin, HIGH);
      digitalWrite(greenLed, LOW);
    }
  else
    {
      digitalWrite(greenLed, HIGH);
      digitalWrite(redLed, LOW);
      digitalWrite(buzzerPin, LOW);
    }
}

Nagios Plug-in

Python
#!/usr/bin/env python

# $Rev::                         $:  Version of last commit
# $Author::                      $:  Author of last commit
# $Date::                                                $

import serial
import re
import sys

try:
    ser = serial.Serial('/dev/ttyACM0', 9600, timeout=15)
    ser.close()
    ser.open()

    rawSensorOutput = ser.readline().rstrip('\n')

    x = re.split('\|', rawSensorOutput)

    temp = float(x[0])
    hum = float(x[1])
    dist = int(x[2])

    if dist >= 31:
        print "SUMP PIT OK - %s cm from top; temp - %s, hum - %s" % (dist, temp, hum)
        sys.exit(0)
    elif dist <= 30:
        print "SUMP PIT CRITICAL - %s cm from top; temp - %s, hum - %s" % (dist, temp, hum)
        sys.exit(2)
    else:
        print "SUMP PIT UNKNOWN"
        sys.exit(3)

except (OSError, serial.SerialException):
    print "SUMP PIT CRITICAL - Cannot open serial port"
    sys.exit(2)

Credits

loupalladino

loupalladino

1 project • 7 followers
Endlessly tinkering.

Comments