-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyringe_Pump_V1.ino
93 lines (82 loc) · 1.82 KB
/
Syringe_Pump_V1.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
/*
* Syringe Pump Program
* By: Tutla Ayatullah
*/
#define en_pin 2 /*1 = disable; 0 = enable*/
#define dir_pin 3 /*1 = CW; 0 = CCW*/
#define pul_pin 5
#define startPin 6
#define stopPin 7
#define fwdPin 8
#define revPin 9
#define enable_motor digitalWrite(en_pin,0)
#define disable_motor digitalWrite(en_pin,1)
#define stepsPerRevolution 1600
#define rotation 5
bool dir = 1, stat = 1, maju = 0, mundur = 0;
bool startBtn = 0, stopBtn = 0, fwdBtn = 0, revBtn = 0;
int step_del = 400, pos = 50;
char incByte = 0;
void setup() {
/*Output PIN*/
pinMode(en_pin, OUTPUT);
pinMode(dir_pin, OUTPUT);
pinMode(pul_pin, OUTPUT);
/*Input PIN*/
pinMode(startBtn, INPUT);
pinMode(stopBtn, INPUT);
pinMode(fwdBtn, INPUT);
pinMode(revBtn, INPUT);
/*Configure Stepper Motor*/
enable_motor;
digitalWrite(dir_pin,dir);
}
void loop() {
// startBtn = digitalRead(startPin);
fwdBtn = digitalRead(fwdPin);
revBtn = digitalRead(revPin);
if(startBtn){
stat = 1;
}
if(stat&&fwdBtn){
maju = 1;
mundur = 0;
}
else if(stat&&revBtn){
maju = 0;
mundur = 1;
}
if(stat){
if(maju){
enable_motor;
for(int i = 0;i<pos;i++){
step_fwd();
}
maju = 0;
}
else if(mundur){
enable_motor;
for(int i = 0;i<pos;i++){
step_bwd();
}
mundur = 0;
}
else{
disable_motor;/* Idle Condition*/
}
}
}
void step_fwd(){
digitalWrite(dir_pin, 1);
digitalWrite(pul_pin, HIGH);
delayMicroseconds(step_del);
digitalWrite(pul_pin, LOW);
delayMicroseconds(step_del);
}
void step_bwd(){
digitalWrite(dir_pin, 0);
digitalWrite(pul_pin, HIGH);
delayMicroseconds(step_del);
digitalWrite(pul_pin, LOW);
delayMicroseconds(step_del);
}