ARDUINO AUTOFILL CODE
Inbox
/* This code is written for Mr. Daniel Donatelli.
This project will automatically maintain perfect water level in WFC.
*/
#include <NewPing.h> //Including library for ultrasonic sensors
//Ultrasonic 1 setup
#define TRIGGER_PIN 10// Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
//Ultrasonic 2 setup
#define TRIGGER_PIN2 8 // Arduino pin tied to trigger pin on the 2nd ultrasonic sensor.
#define ECHO_PIN2 9 // Arduino pin tied to echo pin on the 2nd ultrasonic sensor.
#define MAX_DISTANCE2 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar2(TRIGGER_PIN2, ECHO_PIN2, MAX_DISTANCE2); // NewPing setup of pins and maximum distance.
#include <Wire.h>
#include <Adafruit_GFX.h> //Including OLED library
#include <Adafruit_SSD1306.h> //Including OLED library
//Defination of basic display parameters
#define OLED_RESET 4
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 64
#define LOGO16_GLCD_WIDTH 128
Adafruit_SSD1306 display(OLED_RESET);
Adafruit_SSD1306 display2(OLED_RESET);
//Tuning parameters for WFC (In Centimeters)
//Difference of 2cm is recommended between two levels for precise working of system
//UL stands for UPPER LIMIT
//LL stands for LOWER LIMIT
#define WFC_HIGH_UL 3
#define WFC_HIGH_LL 0
#define WFC_PERFECT_UL 10
#define WFC_PERFECT_LL 5
#define WFC_LOW_UL 20
#define WFC_LOW_LL 12
//Tuning parameters for Water Tank (In Centimeters)
//Difference of 2cm is recommended between two levels for precise working of system
//UL stands for UPPER LIMIT
//LL stands for LOWER LIMIT
#define WATER_TANK_100_UL 3
#define WATER_TANK_100_LL 0
#define WATER_TANK_75_UL 10
#define WATER_TANK_75_LL 5
#define WATER_TANK_50_UL 15
#define WATER_TANK_50_LL 12
#define WATER_TANK_25_UL 20
#define WATER_TANK_25_LL 17
#define WATER_TANK_0_UL 200
#define WATER_TANK_0_LL 22
#define PUMP_PIN 2
int TANK_INDICATION = 1;
void setup() {
Serial.begin(9600); // Set serial monitor with 9600 baud
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the Display1 address
display2.begin(SSD1306_SWITCHCAPVCC, 0x3d); // initialize with the Display2 address
pinMode(PUMP_PIN, OUTPUT);
digitalWrite(PUMP_PIN, HIGH);
}
// setup end
void loop() {
if (sonar2.ping_cm() > WATER_TANK_100_LL && sonar2.ping_cm() < WATER_TANK_100_UL) {
display.clearDisplay(); //Display Reset
Print_Text("Water Tank Level", 15, 0, 1, false);
Print_Text("Water Level", 60, 9, 1, false);
Print_Text("100%", 83, 20, 1, false);
display.fillRect(5, 10, 50, 100, SSD1306_WHITE);
display.drawLine(5, 10, 5, 50, SSD1306_WHITE);
display.drawLine(55, 10, 55, 50, SSD1306_WHITE);
display.drawRect(5, 10, 50, 1, SSD1306_WHITE);
display.display(); //Executing display layout
TANK_INDICATION = 1;
}
else if (sonar2.ping_cm() > WATER_TANK_75_LL && sonar2.ping_cm() < WATER_TANK_75_UL) {
display.clearDisplay();
Print_Text("Water Tank Level", 15, 0, 1, false);
Print_Text("Water Level", 60, 9, 1, false);
Print_Text("75%", 83, 20, 1, false);
display.fillRect(5, 15, 50, 100, SSD1306_WHITE);
display.drawLine(5, 10, 5, 50, SSD1306_WHITE);
display.drawLine(55, 10, 55, 50, SSD1306_WHITE);
display.drawRect(5, 10, 50, 1, SSD1306_WHITE);
display.display();
TANK_INDICATION = 1;
}
else if (sonar2.ping_cm() > WATER_TANK_50_LL && sonar2.ping_cm() < WATER_TANK_50_UL) {
display.clearDisplay();
Print_Text("Water Tank Level", 15, 0, 1, false);
Print_Text("Water Level", 60, 9, 1, false);
Print_Text("50%", 83, 20, 1, false);
display.fillRect(5, 20, 50, 100, SSD1306_WHITE);
display.drawLine(5, 10, 5, 50, SSD1306_WHITE);
display.drawLine(55, 10, 55, 50, SSD1306_WHITE);
display.drawRect(5, 10, 50, 1, SSD1306_WHITE);
display.display();
TANK_INDICATION = 1;
}
else if (sonar2.ping_cm() > WATER_TANK_25_LL && sonar2.ping_cm() < WATER_TANK_25_UL ) {
display.clearDisplay();
Print_Text("Water Tank Level", 15, 0, 1, false);
Print_Text("Water Level", 60, 9, 1, false);
Print_Text("25%", 83, 20, 1, false);
display.fillRect(5, 25, 50, 100, SSD1306_WHITE);
display.drawLine(5, 10, 5, 50, SSD1306_WHITE);
display.drawLine(55, 10, 55, 50, SSD1306_WHITE);
display.drawRect(5, 10, 50, 1, SSD1306_WHITE);
display.display();
TANK_INDICATION = 1;
}
else if (sonar2.ping_cm() > WATER_TANK_0_LL && sonar2.ping_cm() < WATER_TANK_0_UL) {
display.clearDisplay();
Print_Text("Water Tank Level", 15, 0, 1, false);
Print_Text("Water Level", 60, 9, 1, false);
Print_Text("0%", 83, 20, 1, false);
display.fillRect(5, 30, 50, 100, SSD1306_WHITE);
display.drawLine(5, 10, 5, 50, SSD1306_WHITE);
display.drawLine(55, 10, 55, 50, SSD1306_WHITE);
display.drawRect(5, 10, 50, 1, SSD1306_WHITE);
display.display();
TANK_INDICATION = 0;
}
if (sonar.ping_cm() > WFC_HIGH_LL && sonar.ping_cm() < WFC_HIGH_UL) {
display2.clearDisplay();
Print_Text2("WFC Water Fuel %", 15, 0, 1, false);
Print_Text2("Water Level", 60, 9, 1, false);
Print_Text2("HIGH", 83, 20, 1, false);
display2.fillRect(5, 10, 50, 100, SSD1306_WHITE);
display2.drawLine(5, 10, 5, 50, SSD1306_WHITE);
display2.drawLine(55, 10, 55, 50, SSD1306_WHITE);
display2.drawRect(5, 10, 50, 1, SSD1306_WHITE);
display2.display();
}
else if (sonar.ping_cm() > WFC_PERFECT_LL && sonar.ping_cm() < WFC_PERFECT_UL) {
display2.clearDisplay();
Print_Text2("WFC Water Fuel %", 15, 0, 1, false);
Print_Text2("Water Level", 60, 9, 1, false);
Print_Text2("PERFECT", 83, 20, 1, false);
display2.fillRect(5, 20, 50, 100, SSD1306_WHITE);
display2.drawLine(5, 10, 5, 50, SSD1306_WHITE);
display2.drawLine(55, 10, 55, 50, SSD1306_WHITE);
display2.drawRect(5, 10, 50, 1, SSD1306_WHITE);
display2.display();
digitalWrite(PUMP_PIN, LOW);
}
else if (sonar.ping_cm() > WFC_LOW_LL && sonar.ping_cm() < WFC_LOW_UL) {
display2.clearDisplay();
Print_Text2("WFC Water Fuel %", 15, 0, 1, false);
Print_Text2("Water Level", 60, 9, 1, false);
Print_Text2("LOW", 83, 20, 1, false);
display2.fillRect(5, 30, 50, 100, SSD1306_WHITE);
display2.drawLine(5, 10, 5, 50, SSD1306_WHITE);
display2.drawLine(55, 10, 55, 50, SSD1306_WHITE);
display2.drawRect(5, 10, 50, 1, SSD1306_WHITE);
display2.display();
if(TANK_INDICATION == 1){
digitalWrite(PUMP_PIN, HIGH);
}
}
if(TANK_INDICATION == 0){
digitalWrite(PUMP_PIN, LOW);
}
}
void Print_Text(String text, int x, int y, int size, boolean d) {
display.setTextSize(size);
display.setTextColor(WHITE);
display.setCursor(x, y);
display.println(text);
if (d) {
display.display();
}
}
void Print_Text2(String text, int x, int y, int size, boolean d) {
display2.setTextSize(size);
display2.setTextColor(WHITE);
display2.setCursor(x, y);
display2.println(text);
if (d) {
display2.display();
}
}