Arduino Uno board code for moving bridge fro railway , Road, and River Project. This kind of project is generally used in all over the world and live running. So this is good project for Science and Engineeing Students, For Submitting the educational project.
#include <Servo.h>
Servo myservo;
int val,val2,val3;
int m;
void setup()
{
Serial.begin(9600);
myservo.attach(9);
}
void loop()
{sawan:
val = analogRead(A0);
val2 = analogRead(A1);
val3 = analogRead(A2);
Serial.println(val);
Serial.println(val2);
Serial.println(val3);
if((val>val2)&&(val>val3))
{
m=val;
}
else
{
if(val2>val3)
m=val2;
else
m=val3;
}
int c=m/50;
Serial.println(c);
if(c>10&&c<12)
{
goto sawan;
}
else
{
switch(c)
{
case 1:
myservo.write(180);
delay(2000);
break;
case 2:
myservo.write(180);
delay(2000);
break;
case 3:
myservo.write(180);
delay(2000);
break;
case 4:
myservo.write(180);
delay(2000);
break;
case 5:
myservo.write(180);
delay(2000);
break;
case 6:
myservo.write(180);
delay(2000);
break;
case 7:
myservo.write(180);
delay(2000);
break;
case 8:
myservo.write(180);
delay(2000);
break;
case 9:
myservo.write(180);
delay(2000);
break;
case 10:
myservo.write(90);
delay(2000);
break;
case 11:
myservo.write(90);
delay(2000);
break;
case 12:
myservo.write(90);
delay(2000);
break;
case 13:
myservo.write(180);
delay(2000);
break;
case 14:
myservo.write(180);
delay(2000);
break;
case 15:
myservo.write(180);
delay(2000);
break;
case 16:
myservo.write(180);
delay(2000);
break;
case 17:
myservo.write(180);
delay(2000);
break;
case 18:
myservo.write(180);
delay(2000);
break;
case 19:
myservo.write(180);
delay(2000);
break;
case 20:
myservo.write(180);
delay(2000);
break;
default :
myservo.write(90);
}
}
}
Second Program For the Same Problem
#define motor 9#define e1 7
#define e2 6
void setup()
{
pinMode(8,INPUT);
Serial.begin(9600);
pinMode(motor,OUTPUT);
pinMode(e1,OUTPUT);
pinMode(e2,OUTPUT);
}
void loop()
{ delay(1000);
int sensor=digitalRead(8);
Serial.println(sensor);
if(sensor==1)
{
analogWrite(motor,1000);
analogWrite(e1,0);
analogWrite(e2,0);
}
else
{
for(int i=1;i<=10;i++)
{
analogWrite(motor,1000);
analogWrite(e1,0);
analogWrite(e2,255);
delay(100);
}
analogWrite(motor,0);
analogWrite(e1,0);
analogWrite(e2,0);
sawan();
}
delay(1000);
}
void train()
{
for(int i=1;i<=17;i++)
{
analogWrite(motor,1000);
analogWrite(e1,0);
analogWrite(e2,255);
delay(100);
}
analogWrite(motor,0);
analogWrite(e1,0);
analogWrite(e2,0);
vivek();
}
void vivek()
{
delay(10000);
for(int i=1;i<=27;i++)
{
analogWrite(motor,1000);
analogWrite(e1,255);
analogWrite(e2,0);
delay(100);
}
analogWrite(motor,0);
analogWrite(e1,0);
analogWrite(e2,0);
}
void sawan()
{
int s=100;
while(s<3000)
{
delay(100);
int sensor=digitalRead(8);
Serial.println(sensor);
if(sensor==0)
{
train();
}
else
{
s=s+100;
}
delay(100);
}
delay(7000);
for(int i=1;i<=10;i++)
{
analogWrite(motor,1000);
analogWrite(e1,255);
analogWrite(e2,0);
delay(100);
}
analogWrite(motor,0);
analogWrite(e1,0);
analogWrite(e2,0);
loop();
}
No comments:
Post a Comment