Блог Константина » Arduino: контроллер откачки насоса

Arduino: контроллер откачки насоса

Встала потребность в контроллере для автоматического включения насоса в определенный промежуток времени.

Насос включается два раза в сутки, в 06.10 и в 18.10 на 54 секунды (за это время от прокачивает ~300 литров стоков).

Стоит OLED экран, и пищалка. Пищалка включается в момент работы насоса и пищит, когда дата и время на RTC сбилась (из-за этого насос перестает работать).

В будущем планируется поставить кнопку для принудительного включения насоса на определенное время.

Собственно вот код:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <SPI.h>
#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
 
RTC_DS1307 RTC;
 
int Relay = 8;
int Beep = 6; 
int length = 1;
char notes[] = "c";
int beats[] = { 1 };
int tempo = 300;
 
void setup () {
    Serial.begin(9600);
    pinMode(Relay, OUTPUT);
    pinMode(Beep, OUTPUT); 
    digitalWrite(Relay, LOW);
    Wire.begin();
    display.begin();
    RTC.begin();
    display.display();
    delay(2000);
    display.clearDisplay();
    display.display();
    delay(2000);
    display.clearDisplay();
}
 
void loop () {
    // Определяем время
 
    DateTime now = RTC.now();
    if  ( (now.hour() == 6 || now.hour() == 18) && now.minute() == 10 && now.second() >= 01 && now.second() < 55)
    {digitalWrite(Relay, HIGH);
    analogWrite(Beep, HIGH);}
  else
    {digitalWrite(Relay, LOW);
    analogWrite(Beep, LOW);}
 
	if (now.year() == 2000)
	{analogWrite(Beep, HIGH);}
 
 
    // Выводим время в монитор порта
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
 
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.print("06.10   18.10");
 
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0,20);
    display.print(now.hour()/10);
    display.print(now.hour()%10);
    display.print(".");
    display.print(now.minute()/10);
    display.print(now.minute()%10);
    display.print(".");
    display.print(now.second()/10);
    display.println(now.second()%10);
 
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0,40);
    display.print(now.day()/10);
    display.print(now.day()%10);
    display.print(".");
    display.print(now.month()/10);
    display.print(now.month()%10);
    display.print(".");
    display.println(now.year(), DEC);
    display.display();
    display.clearDisplay();
    delay(1000);
 }