The sump level monitor was built to work with an Ecobee RSM-01 input board I have in my daughter's home or my Home Monitor project. I added a relay to allow it to stand alone. I wanted something I felt would be more reliable and easier to install than an ultrasonic sensor. To this end, I started looking into pressure sensors and finally came across Freescale MPXV5010DP. It has a 0-5vdc output for 0-10kPa, which would be about 1020mm of water head.
Since I wanted local indication, I chose an OLED module to use in the design. Cheap, bright and this one had a two color screen. To provide interface, I added a relay for a dry contact output. I added a DAC (digital to analog converter) for a 0-5vdc output with more power than the MPXV5010DP sensor, this will also protect the sensor from possible wiring damage. Since I am using I2C communication, all is need is software changes to supply data to another Arduino.
I designed and had built a custom board for ease of connections. It provides enough flexibility for different configurations.
The sensor is connected by tygon tubing to a copper pipe that gets routed down into the sump. This allows for some discretion as to where to mount the monitor and keeps it away from the water itself..
Code
Sump Level Monitor
Sump Level MonitorC/C++
Parse as you need, extra garbage in this version go ahead and clean up as you desire.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_MCP4725.h>
#include <math.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
Adafruit_MCP4725 dac;
int relayPin = 5; // for relay alarm output
int analogPin = 0; //measures dac output voltage
int v1 = 0; // ADC output from MPXV5010
int v2 = 0; //scaling for dac input converts from PS input to dac input
int v3 = 0; //for mm conversion from PS input
int v4 = 0; //for percentage of depth from PS input
int v5 = 0; // output of dac as read by arduino
int v6 = 0; //for mV conversion from PS input
float v7 =0; //convert from mm to inches
int v8 =0; // to eliminate inches decimals which trash the display
int offSet = 40; //the 0 kPa output as measured by arduino
int maxSet = 1015; //the 10 kPa output as measured by arduino
int maxHeight = 1020; // the depth for the sump from normal water level to lid in mm
int ranging = (maxHeight * 0.8) + offSet;
int alarmHeight = 12; // the alarm height in inches
// For the MPXV5010DP differential pressure sensor
int analogPin2 = 1;
float divisor = 25.4; //for converting display to inches
void setup() {
Serial.begin(9600);
Serial.println("DAC test with DP sensor");
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
// Clear the buffer.
display.clearDisplay();
// For MCP4725A0 the address is 0x60 or 0x61
dac.begin(0x60);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);
}
void loop() {
v1 = analogRead(analogPin2);
delay (1000);
if (v1 < offSet){v1 = offSet;}
//v2=((v1-40)*1.4);
v2 = map(v1, offSet, maxSet, 0, 4095); //for dac input converts from PS input to dac input
dac.setVoltage(v2,false);
//v3 = map(v1, offSet, maxSet, 0, 1020); //for mm conversion from PS input
v3 = (v1 - offSet) / 0.8;
v7 = v3/divisor; //convert from mm to inches
v8 = round (v7); // to eliminate inches decimals which trash the display
v4 = map(v1, offSet, ranging, 0, 100); //for percentage of depth from PS input
v5 = analogRead(analogPin); // output of dac as read by arduino 0-1023 range
v6 = map(v5, 0, 1023, 0, 5000); //for mV conversion from PS input
printoled();
serial();
}
void printoled() {
// Clear the buffer.
display.clearDisplay();
// invert the display for alarm and pickup relay with LOW signal
if(v8 > alarmHeight) {
display.invertDisplay(true); digitalWrite(relayPin,LOW);}
else {
display.invertDisplay(false); digitalWrite(relayPin,HIGH);}
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("SUMP LEVEL");
//display.setTextColor(BLACK, WHITE); // 'inverted' text
display.setTextSize(4);
display.setTextColor(WHITE);
display.print(v8);
display.setTextSize(2);
display.println("inches");
display.display();
delay(500);
}
void serial(){
//for debugging and calibration
Serial.print(" PS analog input: ");
Serial.print(v1);
Serial.print( " Height: ");
Serial.print(v3);
Serial.print(" mm ");
Serial.print(v4);
Serial.print(" %");
Serial.print(" Converted voltage: ");
Serial.print(v6);
Serial.println(" mV");
}
//end