-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal Code.txt
59 lines (50 loc) · 1.97 KB
/
Final Code.txt
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
#include <Servo.h> //Using servo motor
Servo myservo1 , myservo2;
int pos1 = 0 , pos2 = 0 , pin1 = 6 , pin2 = 12;
int led = 4 , ir1 = 11 , ir2 = 10 , ir3 = 9 , dc1 = 2 , dc2 = 35;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT); //pin for LED
pinMode(ir1,INPUT); //pin for IR-1 to sense mud
pinMode(ir2,INPUT); //pin for IR-2 to sense seeds
pinMode(ir3,INPUT); //pin for IR-3 to sense box being filled to capacity
pinMode(dc1,OUTPUT); //pin1 for DC motor
pinMode(dc2,OUTPUT); //pin2 for DC motor
myservo1.attach(pin1); //pin for servo-1 to control outlet of mud
myservo2.attach(pin2); //pin for servo-2 to control outlet of seeds
}
void loop()
{
int ir1_state , ir2_state , ir3_state;
ir1_state = digitalRead(ir1);
ir2_state = digitalRead(ir2);
ir3_state = digitalRead(ir3);
if(ir1_state == 1 && ir2_state == 1 && ir3_state == 0) //if mud and seeds are present and the box is not filled
{
digitalWrite(led,HIGH); //LED glows indicating that machine is under process
for(pos1 = 0 , pos2 = 0; pos1 <=50 , pos2 <= 30 ; pos1++ , pos2++) //both servo's goes from 0 degrees to 90 degrees
{
myservo1.write(pos1);
myservo2.write(pos2);
delay(10);
digitalWrite(dc1,HIGH); //DC motor runs
}
for(pos1 = 50 ,pos2 = 30; pos1 >=0 , pos2 >= 0; pos1-- , pos2--) //both servo's goes from 90 degrees to 0 degrees
{
myservo1.write(pos1);
myservo2.write(pos2);
delay(10);
digitalWrite(dc1,HIGH); //DC motor runs
}
digitalWrite(dc1,HIGH); //DC motor runs
}
else
{
Serial.println("Process Completed");
myservo1.write(pos1);
myservo2.write(pos2);
digitalWrite(led,LOW); //LED turns off indicating that machine has completed the process
digitalWrite(dc1,LOW); //DC turns off
}
}