Saturday, 26 December 2020

Automatic car parking using 2 IR sensors Part (2)

 Circuit:-

We are adding one more IR sensor on the 10th pin of Arduino



Code:- 

#include<Servo.h>
int IR1 = 10;
int IR2 = 11;


Servo servo1;
Servo servo2;
void setup() {
pinMode(IR1,INPUT);
pinMode(IR2,INPUT);
servo1.attach(8);
servo2.attach(9);
servo2.write(0);
servo1.write(120);
delay(1000);
}

void loop() {
  if(digitalRead(IR1)==LOW && digitalRead(IR2)==HIGH)
  
 {
  servo2.write(90);
 servo1.write(0);
  
  
 
 }
 else if(digitalRead(IR1)==HIGH && digitalRead(IR2)==LOW)
 {
   servo2.write(0);
  servo1.write(120);
 }
}
 
You can purchase the raw material for this project from here:- 
https://amzn.to/3oKeh3C https://amzn.to/3nU8bxB https://amzn.to/2L00cjO https://amzn.to/37Rjp0p


No comments:

Post a Comment