Hello, I have an Arduino project which is a three-storey electric elevator.
The electronic parts are the ir sensor, number three, as well as three buttons, also h bridge and dc motor. I have a problem, which is how to connect the electronic parts to each other without overlapping the condition, meaning if I press the second button, it moves to the third floor as soon as the second ir sensor works, the motor stops And if you press the third button, the motor works, as soon as the third ir sensor works, the motor stops, as well as the first, and so on. At the same time, the ball is repeated. Please help please.
int enA=5;
int in1=0;
int in2=1;
int ir_1=2;
int ir_2=3;
int ir_3=4;
int btn_1=10;
int btn_2=11;
int btn_3=12;
Int A = 2;
Int B = 3;
Int F = 4;
Int D = 5;
Int E = 6;
Int G = 7;
void setup() {
pinMode (A, OUTPUT);
pinMode (B, OUTPUT);
pinMode (F, OUTPUT);
pinMode (D, OUTPUT);
pinMode (E, OUTPUT);
pinMode (G, OUTPUT);
pinMode(enA,OUTPUT);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(ir_1,INPUT);
pinMode(ir_2,INPUT);
pinMode(ir_3,INPUT);
pinMode(btn_1,INPUT);
pinMode(btn_2,INPUT);
pinMode(btn_3,INPUT);
}
void loop() {
b1=digitalRead(btn_1);
b2=digitalRead(btn_2);
b3=digitalRead(btn_3);
if(digitalRead(btn_1)==1){
if(digitalRead(ir_3)==1){
motor_Fade();
}else if(digitalRead(ir_1)==0){
motor_off();
}
}
if(digitalRead(btn_3)==1){
if(digitalRead(ir_1)==1){
motor_back_Fade();
}else if(digitalRead(ir_3)==0){
motor_off();
}
}
if(digitalRead(btn_2)==1){
if(digitalRead(ir_1)==1){
if(digitalRead(ir_3)==1){
motor_Fade();
}else if(digitalRead(ir_1)==0){
motor_back_Fade();
}else{
motor_off();
}
}
}
}
void motor_Fade(){
digitalWrite(in1,1);
digitalWrite(in2,0);
analogWrite(enA,200);
delay(400);
}
void motor_back_Fade(){
digitalWrite(in1,0);
digitalWrite(in2,1);
analogWrite(enA,200);
delay(400);
}
void motor_off(){
digitalWrite(in1,0);
digitalWrite(in2,0);
delay(400);
}