Hackster is hosting Impact Spotlights: Smart Home. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Smart Home. Stream on Thursday!
Alex TraynhamAidan RestelliAshreema Luitel
Published © GPL3+

MEGR 3171 Automated AC Water Level Detector

This device makes detecting AC water overflow automated - saving time, money, and risk of health.

IntermediateShowcase (no instructions)5 hours221
MEGR 3171 Automated AC Water Level Detector

Things used in this project

Hardware components

Argon
Particle Argon
×3
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×3
Jumper wires (generic)
Jumper wires (generic)
×1
ELEGOO UNO R3 Project Complete Starter Kit
ELEGOO UNO R3 Project Complete Starter Kit
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Resistor 220 ohm
Resistor 220 ohm
×1
LED (generic)
LED (generic)
×2
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Schematic of Water Level and Temperature Sensor Circuit

Schematic of LCD Display Circuit

Schematic of LED Circuit

Code

finalcode_lcddisplay

C/C++
This code develops the lcd display, which showcases the live readings of temperature and water level.
//includes liquid crystal library
#include <LiquidCrystal.h>

//defines temperature and communication variables
int temperature ;
int comm;

//defines defines temperature as an integer from given data
void temperatureii (const char *event, const char *data) {
String pew = data;
temperature = pew.toInt();
}

//defines pins utilized from the lcd screen
LiquidCrystal lcd(D0, D1, D2, D3, D4, D5);

void setup() {
//clears lcd screen
lcd.clear();
//sets initial columns (16) and rows (2)
lcd.begin(16, 2);
//sets cursor to top left square on lcd screen
lcd.setCursor(0,0);
//prints "H20 Lvl:" on first line
lcd.print("H20 Lvl:");
//sets cursor to bottom left square on lcd screen
lcd.setCursor(0,1);
//prints "Temp:" on second line
lcd.print("Temp:");
//subscribes to data set which has a low, mid, high level
Particle.subscribe("Water_Level_01", Level, "LOW");
Particle.subscribe("Water_Level_01", Level, "MID");
Particle.subscribe("Water_Level_01", Level, "HIGH");
//subscribes to data set for temperature
Particle.subscribe("Temp01", temperatureii, ALL_DEVICES);
}

void loop() {
//sets cursor to second line, after "Temp:"
lcd.setCursor(5,1);
//prints temperature data live
lcd.print(temperature);
//added delay in the loop
delay(100);
//prints F after temperature data (indicates unit)
lcd.print("F");
//publishes temperature data which communicates with the argons with sensors
Particle.publish("Temp01", String(comm), ALL_DEVICES);
}

void Level(const char *event, const char *data) {
//sets cursor to first line, after "H20 Lvl:"
lcd.setCursor(8,0);
//prints water level data
lcd.print(data);
}

finalcode_led

C/C++
This code defines when the led lights up green (for low water level) or red (for medium and high water level).
//define led pins on breadboard
const int led1 = A1;
const int led2 = A5;
//define data set used to control led light
int Water_Level_Value_01;

void setup() {
//defines leds as outputs
pinMode(led1,OUTPUT);
pinMode(led2, OUTPUT);
//initially sets leds to high brightness
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
//subscribes to data set
Particle.subscribe("Water_Level_Value_01", ledcontrol, ALL_DEVICES);
}

void loop() {
//if,elseif statements to indicate when led1 and led2 should turn on or off
if (Water_Level_Value_01 >= 300){
digitalWrite(led1, HIGH);
}
else if (Water_Level_Value_01 <= 300){
digitalWrite(led1, LOW);
}
else{
}

if (Water_Level_Value_01 <= 300){
digitalWrite(led2, HIGH);
}
else if (Water_Level_Value_01 >= 300){
digitalWrite(led2, LOW);
}
else{
}
}

void ledcontrol(const char *event, const char *data){
//defines water level as an integer from given data
    String pew = data;
    Water_Level_Value_01 = pew.toInt();
}

finalcode_sensor

C/C++
This code defines and integrates the water level and temperature read outs for the sensors. It then communicates this data to the display and led and plots the data to thingspeak.
//included libraries below
#include <ThingSpeak.h>
#include <DS18B20.h>
#include <math.h>

//defines water sensor, the two water value data sets, temperature data set
int waterSens = A0; 
int waterVal; 
int Temp01; 
int Water_Level_Value_01; 

//thingspeak initialize
TCPClient client;

//channel number and api key or thingspeak
unsigned long myChannelNumber = 1951865;
const char * myWriteAPIKey = "AFHI6VZOS7RG97SV";

//defines integers for the temperature probe
const int      MAXRETRY = 4;
const uint32_t msSAMPLE_INTERVAL = 2500;
const uint32_t msMETRIC_PUBLISH  = 10000;
const int16_t dsVCC  = D2;
const int16_t dsData = D3;
const int16_t dsGND  = D4;

//temperature probe can now deliver data
DS18B20  ds18b20(dsData, true); 

//setting up parameters for the read-out of the temperature probe
char     szInfo[64];
double   celsius;
double   fahrenheit;
uint32_t number01;
uint32_t number02;

void setup() {
//serial.begin for thingspeak (serial number for specific channel)
Serial.begin(115200);
//sets up pins for ground and vcc on temperature probe & watersensor
pinMode(dsGND, OUTPUT);
digitalWrite(dsGND, LOW);
pinMode(dsVCC, OUTPUT);
digitalWrite(dsVCC, HIGH);
pinMode(waterSens, INPUT);
delay(5000);
//begins thingspeak dat collection
ThingSpeak.begin(client);
}

void loop() {
//reads the water value as an analog output
waterVal = analogRead(waterSens);
delay(5000);
//strings characters for watervalue
String level = String(waterVal);

Particle.publish("Water_Level_Value_01", level,PRIVATE); //publish water level value to console 
delay(5000);

if (waterVal>=0 && waterVal<=300){
Particle.publish("Water_Level_01", "LOW",PRIVATE); //display low water level based on values to console 
    
}
else if (waterVal>300 && waterVal<=600){
Particle.publish("Water_Level_01","MID",PRIVATE); //display mid water level based on values to console

}
else if (waterVal>600){
Particle.publish("Water_Level_01", "HIGH",PRIVATE ); //display high water level based on values to console 

}

//initializes sensorvalue for thingspeak to read water levek as an analog output
int sensorValue1 = analogRead(A0);
ThingSpeak.writeField(myChannelNumber, 1, sensorValue1, myWriteAPIKey); //publishes water level value to thing speak 
}


void publishData(){
//controls physical readout parameters
sprintf(szInfo, "%2.2f", fahrenheit);
//publishes temperature data
Particle.publish("Temp01", szInfo, PRIVATE);
number01 = millis();
}

void getTemp(){
//returns a floating point decimal number for temperature
float _temp;
int   i = 0;

number02 = millis();
//converts from celcius to fahrenheit
int sensorValue2 = ds18b20.convertToFahrenheit(_temp); 
ThingSpeak.writeField(myChannelNumber, 2, sensorValue2, myWriteAPIKey); //publish temp to thing speak
}

Credits

Alex Traynham
1 project • 3 followers
Mechanical Engineering Student with a concentration in Biomedical Engineering studying at the University of North Carolina at Charlotte.
Contact
Aidan Restelli
0 projects • 5 followers
Mechanical Engineering Student with a concentration in Biomedical Engineering studying at the University of North Carolina at Charlotte
Contact
Ashreema Luitel
0 projects • 3 followers
Mechanical Engineering student at the William States Lee College of Engineering at the University of North Carolina at Charlotte
Contact

Comments

Please log in or sign up to comment.