-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm.ino
More file actions
147 lines (119 loc) · 4.12 KB
/
Copy pathalgorithm.ino
File metadata and controls
147 lines (119 loc) · 4.12 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "RTClib.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Fan motor control is now done with a VFD:
// - RUN/STOP through a digital output (to a relay or direct DI, depending on VFD wiring)
// - Speed as 0..100% through PWM (use PWM-to-0..10V module for VFD analog input)
void vfdControlBegin();
void vfdSetSpeedPercent(int percent);
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int screenPreviousMillis;
const int SCREEN_INTERVAL_MILLIS = 1000;
const int pinBurnerFeeder = 8;
const int pinHotWaterPump = 9;
const int pinCentralHeatingPump = 10;
const int pinStorageFeeder = 11;
const int pinFlameSensor = A0;
const int buttonPin = 13;
const int pinOneWireTempSensors = 7;
bool relays = true;
// Temperature Sensors
OneWire oneWire(pinOneWireTempSensors); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
int deviceCount = 0;
float tempC, boiler_temp, hot_water_temp, waste_gas_temp;
bool thermostat = true;
// Real-Time Clock
RTC_DS1307 rtc;
DateTime now;
// Button
int buttonState = 0;
// Flame Sensor
int flameSensorValue = 0; // variable to store the value coming from the sensor
unsigned long flameSensorPreviousMillis = 0;
const int FLAME_INTERVAL_MILLIS = 1000;
unsigned int flameCounts = 0;
unsigned int flameSum = 0;
const byte FLAME_SENSOR_SAMPLES = 10;
bool flameOn;
int motor_running = HIGH; // initial state of LED
long rememberTime = 0; // this is used by the code
// Other
unsigned long onDuration;
unsigned long offDuration;
int fanPower;
bool chimney_needs_clean;
// Count cycle time
int loop_counter; //holds the count for every loop pass
int time_shown_counter; //holds the count for every loop pass
long loop_timer_now; //holds the current millis
long loop_timer_previous_millis; //holds the previous millis
float loop_time; //holds difference (loop_timer_now - previous_millis) = total execution time
long show_time_counter_every = 100; //Show average time every x loops
void setup()
{
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(buttonPin, INPUT);
pinMode(pinBurnerFeeder, OUTPUT);
pinMode(pinHotWaterPump, OUTPUT);
pinMode(pinCentralHeatingPump, OUTPUT);
pinMode(pinStorageFeeder, OUTPUT);
digitalWrite(pinBurnerFeeder, HIGH);
digitalWrite(pinHotWaterPump, HIGH);
digitalWrite(pinCentralHeatingPump, HIGH);
digitalWrite(pinStorageFeeder, HIGH);
sensors.begin(); // Start up the library
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
deviceCount = sensors.getDeviceCount();
Serial.print(deviceCount, DEC);
Serial.println(" devices.");
Serial.println("");
Serial.print("Loading Clock... ");
rtc.begin();
Serial.println("Done");
vfdControlBegin();
//checkflame(pinFlameSensor, 800, 3, 1000);
}
void loop()
{
buttonState = digitalRead(buttonPin);
sensors.requestTemperatures(); // Send command to all the sensors for temperature conversion
boiler_temp = sensors.getTempCByIndex(0);
hot_water_temp = sensors.getTempCByIndex(1);
waste_gas_temp = sensors.getTempCByIndex(2);
motor_control(boiler_temp, &onDuration, &offDuration, &fanPower);
vfdSetSpeedPercent(fanPower);
if (motor_running == LOW)
{
if ((millis() - rememberTime) >= onDuration)
{
motor_running = HIGH;
rememberTime = millis();
}
}
else
{
if ((millis() - rememberTime) >= offDuration)
{
motor_running = LOW;
rememberTime = millis();
}
}
if (relays)
{
digitalWrite(pinBurnerFeeder, motor_running);
thermostat ? digitalWrite(pinCentralHeatingPump, LOW) : digitalWrite(pinCentralHeatingPump, HIGH);
hot_water_temp < 60 ? digitalWrite(pinHotWaterPump, LOW) : digitalWrite(pinHotWaterPump, HIGH);
}
chimney_needs_clean = waste_gas_temp > 130 ? true : false;
update_lcd(rtc.now());
flame_counts();
loopcount();
}