Input- NPN/NO proximity sensor (12V)
Output- Motor Forward, Motor Reverse, Alarm
Sensor will sense tooth disk fitted on Motor shaft. When tooth disk is rotating(520 tooths per minute) then motor will rotate in FWD direction,
When the proxymity sensor input doesn't sense, motor will rotate in reverse direction for 15 second, NO Effect of input sensed on Output.
After 15seconds over, motor will rotate in Forward direction. If suppose in span of 40 seconds motor rotates 2 times in reverse direction, then Forward & Reverse relay output will be Zero. Third relay Output Alarm is ON..
The sketch is as below-
int sensor = 4;
int Forward = 8;
int Reverse = 12;
int Alarm = 13;
int Count;
//unsigned long T1;
//unsigned long Time;
void setup()
{
pinMode(4,INPUT);
pinMode(8,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
Serial.begin(9600);
}
void loop()
{
delay(500);
if (digitalRead(4)==HIGH)
{
digitalWrite(8,HIGH); //Forward Motion ON
digitalWrite(12,LOW); // REVERSE motion Zero
digitalWrite(13,LOW); // NO ALARM
Count = 0;
Serial.print(Forward);
}
else if (digitalRead(4)==LOW)
{
digitalWrite(8,LOW); // Forward motion Zero
digitalWrite(13,LOW); // NO ALARM
digitalWrite(12,HIGH); // Reverse motion ON
Serial.print(Reverse);
delay(15000); // 15 Sec. HOW TO LOOP IT SO, THAT OUTPUT WILL REMAIN UNCHANGED for 15Seconds.
}
Count++;
//if (digitalRead(4)==LOW)
//{
// digitalWrite(8,LOW); // Forward motion Zero
// digitalWrite(12,HIGH); // Reverse motion ON
// digitalWrite(13,LOW); // NO ALARM
// Reverse direction for 15 Sec
// Serial.print(Reverse);
//}
// else
// {
// Count = Count + 1;
// }
if (Count>2)
{
digitalWrite(8,LOW); // Forward motion Zero
digitalWrite(12,LOW); // Reverse motion Zero
digitalWrite(13,HIGH); // Alarm relay activate.
Serial.print(Alarm);
}
}