-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathir_sensor_based_servo_motor_movements.ino
More file actions
61 lines (60 loc) · 1.18 KB
/
ir_sensor_based_servo_motor_movements.ino
File metadata and controls
61 lines (60 loc) · 1.18 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
#define sensor 5
#define led 13
// defines pins numbers
const int stepPin = 3;
const int dirPin = 4;
const int stepPin2 = 6;
int j = 0,val = 0;
void setup()
{
pinMode(sensor, INPUT);
pinMode(led, OUTPUT);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(7,OUTPUT);
digitalWrite(7,HIGH);
}
void loop()
{
j = 0;
while(j < 2){
if(j == 0){
digitalWrite(dirPin,HIGH);
motorpositive();
delay(1000);
}
else {
digitalWrite(dirPin,LOW);
motorpositive();
delay(1000);
}
j++;
}
}
int sensorfunc(){
int readsen = digitalRead(sensor);
if( readsen == LOW) {
digitalWrite(led, LOW);
Serial.println(readsen);
return 1;
}
else {
digitalWrite(led,HIGH);
return 0;
}
}
void motorpositive(){
for(int x = 0; x < 180; x++) {
digitalWrite(stepPin,HIGH);
if(j == 1 && x < 50)
digitalWrite(stepPin2,HIGH);
delay(5);
digitalWrite(stepPin,LOW);
if(j == 1 && x < 50)
digitalWrite(stepPin2,LOW);
delay(5);
do{
val = sensorfunc();
}while(val == 1);
}
}