Devices & Components
Arduino Uno Rev3
DHT22 Temperature Sensor
2" PVC pipe
Ultrasonic Sensor - HC-SR04 (Generic)
3 mm LED: Red
Buzzer
2" PVC pipe coupling
2" PVC pipe clean-out with lid
3 mm LED: Green
Hardware & Tools
Wire cutters/stripper
Soldering iron (generic)
Project description
Code
Nagios Plug-in
python
1#!/usr/bin/env python 2 3# $Rev:: $: Version of last commit 4# $Author:: $: Author of last commit 5# $Date:: $ 6 7import serial 8import re 9import sys 10 11try: 12 ser = serial.Serial('/dev/ttyACM0', 9600, timeout=15) 13 ser.close() 14 ser.open() 15 16 rawSensorOutput = ser.readline().rstrip('\n') 17 18 x = re.split('\\|', rawSensorOutput) 19 20 temp = float(x[0]) 21 hum = float(x[1]) 22 dist = int(x[2]) 23 24 if dist >= 31: 25 print "SUMP PIT OK - %s cm from top; temp - %s, hum - %s" % (dist, temp, hum) 26 sys.exit(0) 27 elif dist <= 30: 28 print "SUMP PIT CRITICAL - %s cm from top; temp - %s, hum - %s" % (dist, temp, hum) 29 sys.exit(2) 30 else: 31 print "SUMP PIT UNKNOWN" 32 sys.exit(3) 33 34except (OSError, serial.SerialException): 35 print "SUMP PIT CRITICAL - Cannot open serial port" 36 sys.exit(2)
Pit Sensor Code
arduino
1// $Rev:: $: Version of last commit 2// $Author:: $: Author of last commit 3// $Date:: $ 4 5#include <DHT.h>; 6 7// DHT22 sensor setup 8#define DHTPIN 13 9#define DHTTYPE DHT22 10DHT dht(DHTPIN, DHTTYPE); 11 12// pin setup 13const int trigPin = 7; 14const int echoPin = 8; 15const int buzzerPin = 9; 16const int redLed = 11; 17const int greenLed = 12; 18 19//Variables 20float hum; 21float temp; 22long duration; 23int distance; 24 25void setup() { 26 // HC-SR04 27 pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output 28 pinMode(echoPin, INPUT); // Sets the echoPin as an Input 29 // LEDs 30 pinMode(greenLed, OUTPUT); 31 pinMode(redLed, OUTPUT); 32 // Buzzer 33 pinMode(buzzerPin, OUTPUT); 34 // 35 Serial.begin(9600); // Starts the serial communication 36 dht.begin(); 37} 38 39void loop() { 40 // <---------------- HC-SR04 -------------------------> 41 // Clears the trigPin 42 digitalWrite(trigPin, LOW); 43 // 10000ms is 10 seconds 44 // 2000 ms is 2 seconds 45 delay(5000); 46 // Sets the trigPin on HIGH state for 10 micro seconds 47 digitalWrite(trigPin, HIGH); 48 delayMicroseconds(10); 49 digitalWrite(trigPin, LOW); 50 // Reads the echoPin, returns the sound wave travel time in microseconds 51 duration = pulseIn(echoPin, HIGH); 52 // Calculating the distance in cm 53 distance = duration*0.034/2; 54 55 // <---------------- DHT22 -------------------------> 56 // Read data and store it to variables hum and temp 57 hum = dht.readHumidity(); 58 temp = dht.readTemperature(); 59 // Print temp and humidity values to serial monitor 60 // Convert C to F 61 temp = temp * 9/5 + 32; 62 // Output 63 Serial.print(temp); 64 Serial.print("|"); 65 Serial.print(hum); 66 Serial.print("|"); 67 Serial.println(distance); 68 69 // <-------------- LEDs + buzzer ------------------------> 70 if (distance <= 20) 71 { 72 digitalWrite(redLed, HIGH); 73 digitalWrite(buzzerPin, HIGH); 74 digitalWrite(greenLed, LOW); 75 } 76 else 77 { 78 digitalWrite(greenLed, HIGH); 79 digitalWrite(redLed, LOW); 80 digitalWrite(buzzerPin, LOW); 81 } 82}
Nagios Plug-in
python
1#!/usr/bin/env python 2 3# $Rev:: $: Version 4 of last commit 5# $Author:: $: Author of last commit 6# 7 $Date:: $ 8 9import serial 10import 11 re 12import sys 13 14try: 15 ser = serial.Serial('/dev/ttyACM0', 9600, timeout=15) 16 17 ser.close() 18 ser.open() 19 20 rawSensorOutput = ser.readline().rstrip('\ 21') 22 23 24 x = re.split('\\|', rawSensorOutput) 25 26 temp = float(x[0]) 27 hum 28 = float(x[1]) 29 dist = int(x[2]) 30 31 if dist >= 31: 32 print 33 "SUMP PIT OK - %s cm from top; temp - %s, hum - %s" % (dist, temp, hum) 34 sys.exit(0) 35 36 elif dist <= 30: 37 print "SUMP PIT CRITICAL - %s cm from top; temp 38 - %s, hum - %s" % (dist, temp, hum) 39 sys.exit(2) 40 else: 41 print 42 "SUMP PIT UNKNOWN" 43 sys.exit(3) 44 45except (OSError, serial.SerialException): 46 47 print "SUMP PIT CRITICAL - Cannot open serial port" 48 sys.exit(2)
Downloadable files
Pit Sensor Diagram
Wiring connections are missing.
Pit Sensor Diagram
Pit Sensor Diagram
Wiring connections are missing.
Pit Sensor Diagram
Comments
Only logged in users can leave comments