Arduino UNO Board Code For Ultrsonic Sensor with Realy and LED Pin for High and LOW Demo
#define trigPin 8
#define LEDPin 12
int relay1=2;
int relay2=3;
int relay3=4;
int relay4=5;
int i=1,s;
int a=10,b=10,c=10,d=10;
int maximumRange = 200;
int minimumRange = 0;
long duration, distance;
void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration/58.2;
switch(i)
{
case 1:
{
while(a<1000)
{
digitalWrite(relay4,LOW);
digitalWrite(relay1,HIGH);
while(distance<5)
{
digitalWrite(relay1,LOW);
delay(1000);
s=2;
a=1000;
break;
}
delay(100);
a=a+100;
}
s=2;
a=100;
break;
}
case 2:
{
while(b<1000)
{
digitalWrite(relay1,LOW);
digitalWrite(relay2,HIGH);
delay(100);
while(distance<5)
{
digitalWrite(relay2,LOW);
delay(1000);
s=3;
b=1000;
break;
}
delay(100);
b=b+100;
}
s=3;
b=100;
break;
}
case 3:
{
while(c<1000)
{
digitalWrite(relay2,LOW);
digitalWrite(relay3,HIGH);
while(distance<5)
{
digitalWrite(relay3,LOW);
delay(1000);
s=4;
c=1000;
break;
}
delay(100);
c=c+100;
}
s=4;
c=100;
break;
}
case 4:
{
while(d<1000)
{
digitalWrite(relay3,LOW);
digitalWrite(relay4,HIGH);
while(distance<5)
{
digitalWrite(relay4,LOW);
delay(1000);
s=1;
d=1000;
break;
}
delay(100);
d=d+100;
}
s=1;
d=100;
break;
}
}
delay(1000);
i=s;
}
SQL Query for Purchase Order details Programming Logic and Code with Syntax
No comments:
Post a Comment