[try Beta version]
Not logged in

 
sequence for arduino

Dec 15, 2015 at 10:49am
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);
  }

 



whats wrong with this code ? its stuck in paperforward()
Dec 15, 2015 at 11:03am
#61 } while (1);
Last edited on Dec 15, 2015 at 11:03am
Dec 15, 2015 at 11:15am
Cant tell from the posted code.
If the function "loop" is getting called from "digitalWrite", since "PaperForward" is calling "digitalWrite" only, then what
kulkarnisr
said is correct
Dec 15, 2015 at 11:35am
#61 } while (1);

its for returning back to value

am i correct ?
Dec 15, 2015 at 11:38am
No. The "while" line specifies the condition for continuing to loop. The loop will continue to iterate as long as the condition in that statement is true.

Since 1 is always true, the loop will continue for ever.

Dec 15, 2015 at 11:53am
so i have to delete it ?
Dec 15, 2015 at 12:02pm
Well, obviously you need some sort of condition for your loop.

The first thing you need to decide is under what circumstances you want your loop to exit. Once you've worked that out, you'll be able to make a decision as to whether:

- you want to leave it as 1, and introduce some break statement within the loop when you want it to exit

- you want to change it to a suitable condition

- some combination of both.
Last edited on Dec 15, 2015 at 12:02pm
Dec 15, 2015 at 12:35pm
The comment in the code states:
 
// put your main code here, to run repeatedly: 

It looks as though remaining in that loop forever is an inherent part of the design. If it doesn't do what you want it to do, it is the design which you need to consider first. After you decide what you want the program to do, then you can start to write or change the code for it.

Or possibly the program is working properly, but the data it is getting as input is not as required.
Last edited on Dec 15, 2015 at 12:38pm
Topic archived. No new replies allowed.