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
|
int Relay1=2; // actuator 1 on
int Relay2=1; // actuator 1 off
int Relay3=3; // actuator 2 on
int Relay4=4; // actuator 2 off
int Relay5=5; // actuator 3 on
int Relay6=6; // actuator 3 off
int Relay7=7; // actuator 4 on
int Relay8=8; // actuator 4 off
int Sensorpin1=11; // inductive sensor 1
int Sensorpin2=12; // inductive sensor 2
int Sensorpin3=13; // thru beam sensor
int PIRpin=10; // PIR sensor
int val=LOW;
void setup() {
// put your setup code here, to run once:
pinMode (Relay1, OUTPUT); //
pinMode (Relay2, OUTPUT); //
pinMode (Relay3, OUTPUT); //
pinMode (Relay4, OUTPUT); //
pinMode (Relay5, OUTPUT); //
pinMode (Relay6, OUTPUT); //
pinMode (Relay7, OUTPUT); //
pinMode (Relay8, OUTPUT); //
pinMode (Sensorpin1,INPUT); // Inductive sensor 1
pinMode (Sensorpin2,INPUT); // Inductive sensor 2
pinMode (Sensorpin3,INPUT); // Thru beam sensor
pinMode (PIRpin, INPUT); // PIR Sensor
}
void loop() {
// put your main code here, to run repeatedly:
Reset();
do {
if (LOW == digitalRead(PIRpin))
{
delay (2000);
if (LOW == digitalRead(Sensorpin1) && val == digitalRead(Sensorpin2))
{
MetalForward(); // Relay1,2 & Relay 7,8
delay (7000);
MetalReverse(); // Relay 1,2 & Relay 7,8
delay (7000);
}
else if (LOW == digitalRead(Sensorpin3))
{
PaperForward(); // Relay 1,2 & Relay 5,6
delay (7000);
PaperReverse(); // Relay 1,2 & Relay 5,6
delay (7000);
}
else
{
BottleForward(); //Relay 3,4
delay(2000);
BottleReverse(); // Relay 3,4
delay (2000);
}
}
} while (1);
}
void MetalForward ()
{
digitalWrite (Relay1, HIGH);
digitalWrite (Relay2, LOW);
digitalWrite (Relay7, HIGH);
digitalWrite (Relay8, LOW);
}
void MetalReverse ()
{
digitalWrite (Relay1, LOW);
digitalWrite (Relay2, HIGH);
digitalWrite (Relay7, LOW);
digitalWrite (Relay8, HIGH);
}
void PaperForward ()
{
digitalWrite (Relay1, HIGH);
digitalWrite (Relay2, LOW);
digitalWrite (Relay5, LOW);
digitalWrite (Relay6, HIGH);
}
void PaperReverse ()
{
digitalWrite (Relay1, LOW);
digitalWrite (Relay2, HIGH);
digitalWrite (Relay5, HIGH);
digitalWrite (Relay6, LOW);
}
void BottleForward ()
{
digitalWrite (Relay3, LOW);
digitalWrite (Relay4, HIGH);
}
void BottleReverse ()
{
digitalWrite (Relay3, HIGH);
digitalWrite (Relay4, LOW);
}
void Reset ()
{
digitalWrite (Relay1, HIGH);
digitalWrite (Relay2, LOW);
digitalWrite (Relay3, HIGH);
digitalWrite (Relay4, LOW);
digitalWrite (Relay6, HIGH);
digitalWrite (Relay5, LOW);
digitalWrite (Relay7, LOW);
digitalWrite (Relay8, HIGH);
}
|