Skip to content

Commit

Permalink
float switches now invertible
Browse files Browse the repository at this point in the history
  • Loading branch information
H3wastooshort committed Jun 14, 2022
1 parent 41434f2 commit 475273c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 33 deletions.
Binary file modified images/tank_pixelart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/tank_pixelart.xcf
Binary file not shown.
Binary file modified images/tank_pixelart_hires.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 36 additions & 18 deletions waterthing/waterthing.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ Zyklus:
#include <DS1307RTC.h>

#define LOW_WATER_PIN 7
#define TANK_EMPTY_PIN 8
#define TANK_FULL_PIN 9
#define TANK_BOTTOM_PIN 8
#define TANK_TOP_PIN 9
#define PUMP_PIN 10
#define VALVE_PIN 11
#define LOW_WATER_ON_LEVEL LOW //level of low water pin when the low water sensor detects low water. sensor will probably be mounted upside-down so no water means low
#define TANK_BOTTOM_ON_LEVEL HIGH //level of TANK_BOTTOM_PIN when water has reached the bottom sensor. sensor will probably be mounted upside-down so on means high
#define TANK_TOP_ON_LEVEL LOW //level of TANK_TOP_PIN when water has reached the top sensor

#define RED_LED_PIN A1
#define GREEN_LED_PIN A2
Expand All @@ -45,6 +48,7 @@ LiquidCrystal_I2C lcd(0x27,16,2);

//const byte gfx_drop[8] = {B00100, B00100, B01110, B01110, B10111, B11111, B01110, B00000};
const byte gfx_no_water[8] = {B00001, B00001, B01000, B01101, B01100, B10110, B11110, B01100};
//const byte gfx_idle[8] = {B00000, B00000, B00000, B00000, B00000, B00000, B10101, B00000}; //... version
const byte gfx_idle[8] = {B00100, B00100, B01110, B10111, B11111, B01110, B00000, B10101}; //drop with ... version
//const byte gfx_idle[8] = {B00110, B00011, B01100, B00110, B11000, B01000, B10000, B11000}; //zZZ version
const byte gfx_fill[8] = {B00100, B10101, B01110, B00100, B00000, B10001, B10001, B11111};
Expand Down Expand Up @@ -76,7 +80,7 @@ struct settings_s {
struct i_timer_s {
int8_t start_hour = 0;
int8_t start_minute = 0;
uint16_t fillings_to_irrigate = 0;
uint16_t fillings_to_irrigate = 0; //when 0, system is turned off
uint8_t last_watering_day = 0;
} irrigation_timer;

Expand Down Expand Up @@ -337,8 +341,8 @@ void set_status_led(bool r, bool g, bool b) {
void setup() {
//pump stuff
pinMode(LOW_WATER_PIN, INPUT_PULLUP);
pinMode(TANK_EMPTY_PIN, INPUT_PULLUP);
pinMode(TANK_FULL_PIN, INPUT_PULLUP);
pinMode(TANK_BOTTOM_PIN, INPUT_PULLUP);
pinMode(TANK_TOP_PIN, INPUT_PULLUP);
pinMode(PUMP_PIN, OUTPUT);
pinMode(VALVE_PIN, OUTPUT);
digitalWrite(PUMP_PIN, LOW);
Expand All @@ -352,6 +356,11 @@ void setup() {
digitalWrite(GREEN_LED_PIN, LOW);
digitalWrite(BLUE_LED_PIN, LOW);

//buttons
pinMode(ENCODER_CLK_PIN, INPUT_PULLUP);
pinMode(ENCODER_DT_PIN, INPUT_PULLUP);
pinMode(BTN_PIN, INPUT_PULLUP);

set_status_led(1,1,0);

Serial.begin(9600);
Expand Down Expand Up @@ -488,11 +497,19 @@ void update_display() {
case PAGE_STATUS:
switch (system_state) {
case STATUS_IDLE:
lcd.print(F("Stby. bis"));
lcd.setCursor(11,1);
char til_buf[5];
sprintf(til_buf, "%02u:%02u", irrigation_timer.start_hour, irrigation_timer.start_minute);
lcd.print(til_buf);
if (irrigation_timer.fillings_to_irrigate == 0) {
lcd.print(F("Ausgeschaltet"));
}
else if (irrigation_timer.last_watering_day == current_time.Day) {
lcd.print(F("Fertig f\x07r Heute"));
}
else {
lcd.print(F("Stby. bis"));
lcd.setCursor(11,1);
char til_buf[5];
snprintf(til_buf, 5, "%02u:%02u", irrigation_timer.start_hour, irrigation_timer.start_minute);
lcd.print(til_buf);
}
break;
case STATUS_EMPTYING:
lcd.print(F("Leere Tank "));
Expand Down Expand Up @@ -593,7 +610,8 @@ void update_display() {
//status led
switch (system_state) {
case STATUS_IDLE:
set_status_led(0,1,0);
if (irrigation_timer.fillings_to_irrigate == 0) set_status_led(1,0,1);
else set_status_led(0,1,0);
break;
case STATUS_EMPTYING:
set_status_led(0,0,1);
Expand Down Expand Up @@ -630,18 +648,18 @@ void handle_pump_stuff() {
EEPROM.put(0+sizeof(settings),irrigation_timer);
}

if (tank_fillings_remaining > 0 and digitalRead(LOW_WATER_PIN)) system_state = STATUS_PUMPING;
if (!digitalRead(LOW_WATER_PIN)) system_state = STATUS_NO_WATER;
if (!digitalRead(TANK_EMPTY_PIN)) system_state = STATUS_EMPTYING; //if at boot there is still water in the tank, empty it.
if (tank_fillings_remaining > 0 and digitalRead(LOW_WATER_PIN) != LOW_WATER_ON_LEVEL) system_state = STATUS_PUMPING;
if (digitalRead(LOW_WATER_PIN) == LOW_WATER_ON_LEVEL) system_state = STATUS_NO_WATER;
if (digitalRead(TANK_BOTTOM_PIN) == TANK_BOTTOM_ON_LEVEL) system_state = STATUS_EMPTYING; //if at boot there is still water in the tank, empty it.
break;

case STATUS_EMPTYING:
digitalWrite(PUMP_PIN, LOW);
digitalWrite(VALVE_PIN, HIGH);
if (digitalRead(TANK_EMPTY_PIN) and digitalRead(TANK_FULL_PIN)) {
if (digitalRead(TANK_BOTTOM_PIN) != TANK_BOTTOM_ON_LEVEL and digitalRead(TANK_TOP_PIN) != TANK_TOP_ON_LEVEL) {
tank_fillings_remaining--;
if (tank_fillings_remaining > 60000) tank_fillings_remaining = 0; //against integer rollover
if (!digitalRead(LOW_WATER_PIN)) {
if (digitalRead(LOW_WATER_PIN) == LOW_WATER_ON_LEVEL) {
system_state = STATUS_NO_WATER;
return;
}
Expand All @@ -657,15 +675,15 @@ void handle_pump_stuff() {
case STATUS_PUMPING:
digitalWrite(PUMP_PIN, HIGH);
digitalWrite(VALVE_PIN, LOW);
if (!digitalRead(TANK_FULL_PIN) or !digitalRead(LOW_WATER_PIN)) {
if (digitalRead(TANK_TOP_PIN) == TANK_TOP_ON_LEVEL or digitalRead(LOW_WATER_PIN) == LOW_WATER_ON_LEVEL) {
system_state = STATUS_EMPTYING;
}
break;

case STATUS_NO_WATER:
digitalWrite(PUMP_PIN, LOW);
digitalWrite(VALVE_PIN, LOW);
if (digitalRead(LOW_WATER_PIN)) system_state = STATUS_IDLE;
if (digitalRead(LOW_WATER_PIN) != LOW_WATER_ON_LEVEL) system_state = STATUS_IDLE;
break;

case STATUS_NO_TIME:
Expand Down
30 changes: 15 additions & 15 deletions wokwi_sim_diagram.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
{ "type": "wokwi-arduino-uno", "id": "uno", "top": -5.7, "left": 175.25, "attrs": {} },
{
"type": "wokwi-slide-switch",
"id": "sw1",
"id": "tank_full_sw",
"top": -131.68,
"left": 199.6,
"rotate": 270,
"attrs": {}
"attrs": { "value": "1" }
},
{
"type": "wokwi-slide-switch",
"id": "sw2",
"id": "tank_empty_sw",
"top": -175.65,
"left": 200.65,
"rotate": 270,
"attrs": {}
"attrs": { "value": "" }
},
{
"type": "wokwi-led",
Expand Down Expand Up @@ -54,11 +54,11 @@
},
{
"type": "wokwi-slide-switch",
"id": "sw3",
"id": "low_water_sw",
"top": -218.7,
"left": 201.2,
"rotate": 270,
"attrs": {}
"attrs": { "value": "1" }
},
{
"type": "wokwi-rgb-led",
Expand All @@ -70,10 +70,10 @@
],
"connections": [
[ "led1:C", "uno:GND.2", "black", [ "h17.03", "v266.64", "h104.13" ] ],
[ "sw1:1", "sw2:1", "black", [ "h10.51", "v-36.84" ] ],
[ "sw1:1", "led1:C", "black", [ "h10.51", "v54.8" ] ],
[ "uno:5V", "sw1:3", "red", [ "v26.2", "h-86.33", "v-333.39" ] ],
[ "sw1:3", "sw2:3", "red", [ "h19.84", "v-49.47" ] ],
[ "tank_full_sw:1", "tank_empty_sw:1", "black", [ "h10.51", "v-36.84" ] ],
[ "tank_full_sw:1", "led1:C", "black", [ "h10.51", "v54.8" ] ],
[ "uno:5V", "tank_full_sw:3", "red", [ "v26.2", "h-86.33", "v-333.39" ] ],
[ "tank_full_sw:3", "tank_empty_sw:3", "red", [ "h19.84", "v-49.47" ] ],
[ "uno:5V", "lcd1:VCC", "red", [ "v0" ] ],
[ "uno:GND.2", "lcd1:GND", "black", [ "v0" ] ],
[ "uno:A4", "lcd1:SDA", "green", [ "v0" ] ],
Expand All @@ -91,15 +91,15 @@
[ "encoder1:DT", "uno:4", "white", [ "h10.06", "v-162.2", "h-195.2" ] ],
[ "uno:11", "led1:A", "violet", [ "v0" ] ],
[ "uno:10", "led2:A", "violet", [ "v0" ] ],
[ "uno:9", "sw1:2", "gold", [ "v0" ] ],
[ "uno:8", "sw2:2", "gold", [ "v0" ] ],
[ "uno:9", "tank_full_sw:2", "gold", [ "v0" ] ],
[ "uno:8", "tank_empty_sw:2", "gold", [ "v0" ] ],
[ "uno:GND.2", "rtc1:GND", "black", [ "v0" ] ],
[ "uno:5V", "rtc1:5V", "red", [ "v0" ] ],
[ "rtc1:SCL", "lcd1:SCL", "blue", [ "h65.12", "v-19.03" ] ],
[ "rtc1:SDA", "lcd1:SDA", "green", [ "h72.9", "v-6.49" ] ],
[ "sw2:1", "sw3:1", "black", [ "h9.2", "v-43.79" ] ],
[ "sw2:3", "sw3:3", "red", [ "h18.78", "v-1.12" ] ],
[ "sw3:2", "uno:7", "gold", [ "h0" ] ],
[ "tank_empty_sw:1", "low_water_sw:1", "black", [ "h9.2", "v-43.79" ] ],
[ "tank_empty_sw:3", "low_water_sw:3", "red", [ "h18.78", "v-1.12" ] ],
[ "low_water_sw:2", "uno:7", "gold", [ "h0" ] ],
[ "rgb1:B", "uno:A3", "green", [ "v0" ] ],
[ "rgb1:G", "uno:A2", "green", [ "v0" ] ],
[ "rgb1:R", "uno:A1", "green", [ "v26.4", "h7.49" ] ],
Expand Down

0 comments on commit 475273c

Please sign in to comment.