-
Notifications
You must be signed in to change notification settings - Fork 0
/
PoolRobot.ino
122 lines (103 loc) · 4.48 KB
/
PoolRobot.ino
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
// PoolRobot 2022
// Steven Chesser
// v1.3
const int jetPIN = 16; // Relay trigger to relay for JET motor ground wire.
const int drvPwrPIN = 17; // Relay trigger to relay for OONO Forward and Reverse Relay Module Relay.
// We want to cut power to the drive motor via this relay.
// Then once it is off, we can change the direction of this relay.
// Then let the relay have power again.
const int drvDirPIN = 18; // Relay trigger to OONO Forward and Reverse Relay Module Relay for direction.
const int testDrive = 3000; // Move 3 seconds
const unsigned int driveTime = 60000; // 60 seconds to drive in either direction.
// This could be increased or decreased for your pool size to optimize it.
const int dropTime = 15000; // 15 seconds to drop to bottom of pool.
// Add more time if got A deep pool.
// Remove time if is it not.
const int stopTime = 3000; // 3 seconds to move after a STOP.
// Just A small delay of time when shutting off motors.
// These cheap relays most use, try to give it a little time if going to lower it.
// Don't just set it to zero.
const int startupDelay = 15000; // 15 second delay on startup to allow drop into water to sink to bottom.
// If your bot likes to float for A while before fully sinking, increase this.
// Turn on JET to push robot down and/or against wall
void jetON() {
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("jetON");
digitalWrite (jetPIN, HIGH);
delay(stopTime);
digitalWrite(LED_BUILTIN, LOW);
}
// Turn off JET to let robot drop to bottom off pool and/or switch direciton
void jetOFF() {
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("jetOFF");
digitalWrite (jetPIN, LOW);
delay(stopTime);
digitalWrite(LED_BUILTIN, LOW);
}
void driveDirection(unsigned int moveTime, int relayDir) {
Serial.println("driveDirection Start");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(drvPwrPIN, LOW); // TURN MOTOR OFF
delay(1000);
digitalWrite(drvDirPIN, relayDir); // Trigger relay to move in forward or reverse
delay(1000);
digitalWrite(drvPwrPIN, HIGH); // TURN MOTOR ON
Serial.print("Waiting ");
Serial.print(moveTime);
Serial.println(" milliseconds...");
delay(moveTime);
digitalWrite(drvPwrPIN, LOW); // TURN MOTOR OFF
digitalWrite(LED_BUILTIN, LOW);
Serial.println("driveDirection Stop");
}
// Simple test of JET and Drive Motor
// Currently does not do much testing in way of things
// but could possibly use aid of some of extra sensors added
// to insure robot is moving and such?
bool testRun() {
Serial.println("testRun Started");
Serial.println("");
Serial.print("Waiting ");
Serial.print(startupDelay);
Serial.println(" milliseconds...");
Serial.println("");
delay(startupDelay);
jetON();
delay(stopTime);
driveDirection(testDrive, LOW);
delay(stopTime);
driveDirection(testDrive, HIGH);
Serial.println("testRun Ended");
return true;
}
// Stage up Microcontroller and relays
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(jetPIN, OUTPUT);
pinMode(drvPwrPIN, OUTPUT);
pinMode(drvDirPIN, OUTPUT);
digitalWrite (jetPIN, LOW); // OFF
digitalWrite (drvPwrPIN, LOW); // OFF
digitalWrite (drvDirPIN, LOW); // OFF
while (!Serial) delay(1);
Serial.println("");
Serial.println("Starting pool robot");
Serial.println("");
testRun();
}
// The robots controller box is providing 24 volts
// and this loop will just run until the controller box shuts off the 24 volts
// So we don't have to do anything special as once voltage is cut, the microcontroller turns off.
void loop() {
jetON(); // Turn JET ON
driveDirection(driveTime,LOW); // Drive forward for "driveTime" milliseconds
jetOFF(); // Turn JET OFF to Drop/Change directions
delay(dropTime); // Now wait for "dropTime" milliseconds
jetON(); // Turn JET ON
driveDirection(driveTime,HIGH); // Drive backwards for "driveTime" milliseconds
jetOFF(); // Turn JET OFF to Drop/Change directions
delay(dropTime); // Now wait for "dropTime" milliseconds
}