-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor_pump3.ino
154 lines (122 loc) · 2.12 KB
/
motor_pump3.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
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
#include <Stepper.h>
//Pins for stepper
const int stepsPerRevolution = 200;
char val;
//black-out4
//red-out3
//orange-out1
//green-out2
//in1-3
//in2-4
//in3-5
//in4-6
//enable short
//arduino common ground w/ source
Stepper myStepper(stepsPerRevolution, 3, 4, 5, 6);
//pumps
int enA = 9;
int in1 = 10;
int in2 = 12;
int enB = 7;
int in3 = 11;
int in4 = 8;
int enC=A0; //eA
int in5=A1; //i1
int in6=A2; //i2
int in7=A3; //i3
int in8=A4; //i4
int enD=13; //eb
void pump() //activates pump
{
if(Serial.available())
{
val=Serial.read();
}
if(val=='1')
{ digitalWrite(in2, HIGH);
}
if(val=='2')
{ digitalWrite(in3, HIGH);
}
if(val=='3')
{ digitalWrite(in5, HIGH);
}
if(val=='4')
{ digitalWrite(in7, HIGH);
}
}
void stopp() // stops all pumps
{
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
digitalWrite(in5, LOW);
digitalWrite(in6, LOW);
digitalWrite(in7, LOW);
digitalWrite(in8, LOW);
}
void stepm()
{
if(Serial.available())
{
val=Serial.read();
}
if(val=='a')
{
myStepper.step(700/6); //one sixth rev
val='0';
}
if(val=='c')
{
myStepper.step(-700/6);
val='0';
}
}
void setup() {
myStepper.setSpeed(30);
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(enC, OUTPUT);
pinMode(enD, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(in5, OUTPUT);
pinMode(in6, OUTPUT);
pinMode(in7, OUTPUT);
pinMode(in8, OUTPUT);
digitalWrite(in2, LOW);
analogWrite(enA, 200);
digitalWrite(in1, LOW);
digitalWrite(in3, LOW);
analogWrite(enB, 200);
digitalWrite(in4, LOW);
analogWrite(enC, 200);
digitalWrite(in5, LOW);
digitalWrite(in6, LOW);
analogWrite(enD, 200);
digitalWrite(in8, LOW);
digitalWrite(in7, LOW);
Serial.begin(9600);
val='0';
}
void loop() {
if(Serial.available())
{
val=Serial.read();
}
if(val=='c'||val=='a') //stepper control
{
stepm();
}
if(val=='1'||val=='2'||val=='3'||val=='4')
{
pump(); //activate pump
}
if(val=='s')
{
stopp();
}
}