Using multiple IR sensors you can make sure your Arduino vehicle does not become stuck along a wall or obstacle.
Functional Parts in the Project:
- FeeTech FT-MC-002-SMC – https://amzn.to/2MLIzoF
- FeeTech 2CH-SM-Controller (Motor Controller)
- Arduino Uno – https://store.arduino.cc/usa/arduino-uno-rev3
- IR Sensor – https://amzn.to/2IDw7SE
- Micro Breadboard – https://amzn.to/2XbFX7w
- USB Battery Pack


#include <Servo.h>
#define lIR 5
#define rIR 6
#define fIR 7
Servo lServo;
Servo rServo;
int lObstacle;
int rObstacle;
int fObstacle;
void setup() {
pinMode(lIR, INPUT);
pinMode(rIR, INPUT);
pinMode(fIR, INPUT);
lServo.attach(8);
rServo.attach(9);
}
void loop() {
lObstacle = digitalRead(lIR);
rObstacle = digitalRead(rIR);
fObstacle = digitalRead(fIR);
if (lObstacle == LOW) {
lServo.write(70);
rServo.write(110);
}
else if (rObstacle == LOW) {
lServo.write(110);
rServo.write(70);
}
else if (fObstacle == LOW) {
lServo.write(80);
rServo.write(100);
}
else {
lServo.write(80);
rServo.write(80);
}
delay(100);
}
Be the first to comment