-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathWashingMachine.ino
More file actions
324 lines (247 loc) · 6.75 KB
/
WashingMachine.ino
File metadata and controls
324 lines (247 loc) · 6.75 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
Author : Kiran Abraham Korah
beep.exe@gmail.com
http://bincoder.com/
https://github.com/redocnib
Fully Automatic Washing Machine Logic Board
*/
#include <Wire.h>
#include <EEPROM.h>
//-- I2C 16x2 LCD Display Support Added!
//-- [LCD : http://ecx.images-amazon.com/images/I/51NJ2CGn63L.jpg ,
//-- I2C Interface : http://ecx.images-amazon.com/images/I/51QKT0ft6RL.jpg]
/////------------------------------------- LCD MODULE INITIALIZATION -----------------------//
#include "src/LiquidCrystal/LCD.h"
#include "src/LiquidCrystal/LiquidCrystal_I2C.h"
#define I2C_ADDR 0x3F // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
/////---------------------------------- END OF LCD MODULE INITIALIZATION -------------------//
//-------- Relay State Setups -------//
#define CLOCKWISE HIGH
#define ANTICLOCKWISE LOW
#define RELAY_ON LOW
#define RELAY_OFF HIGH
//----------------------------------//
// PORTS //
#define MotorPowerPort 2
#define MototrDirectionPort 6
#define WaterFillValvePort 4
#define WaterDrainValvePort 5
#define CONTROL_SWITCH 8
// GLOBAL PROCESS VARIABLES //
double process_start = 0L;
unsigned long process_duration = 0L;
int motor_status = CLOCKWISE;
int process = 0;
String process_name = "";
int process_max = 10;
long millis_padding = 0;
// ------------------------ //
void setup() {
Serial.begin(9600);
lcd.begin (16, 2);
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd_cleanPrint("Hello, WELCOME !!!", "--- v0.3 Alpha---");
lcd_blinkScreen(3);
delay(1000);
processInit();
}
void loop() {
// put your main code here, to run repeatedly:
if (doProcess())
{
processReset();
lcd_blinkScreen(3);
lcd_cleanPrint("Washing Complete !", "--- v0.3 Alpha---");
delay(3000);
}
}
//-------------------------LCD Derived Methods----------------------------------//
void lcdProgressBar(double val,double outof)
{
}
void lcd_blinkScreen(int t)
{
for (int i = 0; i < t; i++)
{
lcd.setBacklight(LOW);
delay(500);
lcd.setBacklight(HIGH);
delay(500);
}
}
void lcd_cleanPrint(String line1, String line2)
{
delay(100);
lcd.clear();
lcd.home ();
lcd.setCursor (0, 0);
lcd.print(line1);
lcd.setCursor (0, 1);
lcd.print(line2);
delay(100);
}
void lcd_Clean()
{
delay(100);
lcd.clear();
lcd.home ();
}
//------------------PROCESS AND OPERATIONS ---------------------------------//
boolean doProcess() //Return is Completed !
{
if (process == 0)drainWater(1);
else if (process == 1)fillWater(5);
//doSoak(2);
else if (process == 2)doWash(4000, 10, "WASHING DRESS");
else if (process == 3)drainWater(2);
else if (process == 4)fillWater(5);
else if (process == 5)doWash(5000, 8, "RINSING DRESS 1");
else if (process == 6)drainWater(3);
else if (process == 7)fillWater(5);
else if (process == 8)doWash(6000, 7, "RINSING DRESS 2");
else if (process == 9)drainWater(2);
else if (process == 10)doSpin(3, CLOCKWISE);
else return true;
processUpdate();
return false;
}
double process_pivot = 0;
void processUpdate()
{
double process_current = millis_padded();
if ((process_current - process_start) >= process_duration)
{
process++;
processReset();
delay(1000);
}
else
{
if ((process_current - process_pivot) > 1000) //If past a minimum of one sec
{
//double remain=(process_remain/1000)/60;
process_pivot = process_current;
lcd_Clean();
lcd.setCursor (0, 0);
lcd.print(process_name);
lcd.setCursor (0, 1);
process_current = (process_current - process_start);
process_current = process_current / 1000;
if (process_current >= 60)
{
process_current = process_current / 60;
lcd.print((int)process_current);
lcd.print("Min");
}
else
{
lcd.print((int)process_current);
lcd.print("Sec");
}
lcd.print("/");
process_current = process_duration / 1000;
if (process_current >= 60)
{
process_current = process_current / 60;
lcd.print((int)process_current);
lcd.print("Min");
}
else
{
lcd.print((int)process_current);
lcd.print("Sec");
}
}
}
}
void processInit()
{
pinMode(MotorPowerPort, OUTPUT);
pinMode(MototrDirectionPort, OUTPUT);
pinMode(WaterFillValvePort, OUTPUT);
pinMode(WaterDrainValvePort, OUTPUT);
pinMode(CONTROL_SWITCH, INPUT_PULLUP);
process_duration = 0;
process = 0;
process_start = millis_padded();
motor_status = CLOCKWISE;
digitalWrite(MotorPowerPort, RELAY_OFF);
digitalWrite(MototrDirectionPort, CLOCKWISE);
digitalWrite(WaterFillValvePort, RELAY_OFF);
digitalWrite(WaterDrainValvePort, RELAY_OFF);
}
void processReset()
{
process_start = millis_padded();
process_duration = 0;
motor_status = CLOCKWISE;
digitalWrite(MotorPowerPort, RELAY_OFF);
digitalWrite(MototrDirectionPort, CLOCKWISE);
digitalWrite(WaterFillValvePort, RELAY_OFF);
digitalWrite(WaterDrainValvePort, RELAY_OFF);
}
void setProcessDuration(int mins)
{
process_duration = mins2millis(mins);
}
//---------------------Process In Detail --------------------------------------//
void doWash(int cycle_delay, int time_mins, String title)
{
process_name = title;
setProcessDuration(time_mins);
if (motor_status == CLOCKWISE)motor_status = ANTICLOCKWISE;
else motor_status = CLOCKWISE;
digitalWrite(MotorPowerPort, RELAY_OFF); //TURN OFF MAIN POWER TO MOTOR
delay(1000);
digitalWrite(MototrDirectionPort, motor_status); //SET MOTOR DIRECTION
delay(1000);
digitalWrite(MotorPowerPort, RELAY_ON); //TURN ON MAIN POWER TO MOTOR
delay(cycle_delay);
}
void fillWater(int time_mins)
{
process_name = "FILLING WATER";
setProcessDuration(time_mins);
digitalWrite(WaterFillValvePort, RELAY_ON);
}
void drainWater(int time_mins)
{
process_name = "DRAINING WATER";
setProcessDuration(time_mins);
digitalWrite(WaterDrainValvePort, RELAY_ON);
}
void doSpin(int time_mins, int DIR)
{
process_name = "DRY SPINNING";
setProcessDuration(time_mins);
digitalWrite(WaterDrainValvePort, RELAY_ON);
delay(3000);
digitalWrite(MototrDirectionPort, CLOCKWISE);
delay(1000);
digitalWrite(MotorPowerPort, RELAY_ON);
}
void doSoak(int time_mins)
{
process_name = "SOAKING DRESS";
setProcessDuration(time_mins);
delay(1000);
//JUST WAIT :)
}
//---------------------------------------------------------------------------------------//
unsigned long mins2millis(int mins)
{
return (((unsigned long)mins) * 60 * 1000);
}
double millis_padded()
{
return (millis() + millis_padding);
}