You can use IR Sensors to create a line following vehicle with Arduino. When the IR Sensors go over electrical tape they read as if there is nothing in front of them.
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 leftIR 8
#define rightIR 9
Servo leftWheel;
Servo rightWheel;
int leftReading;
int rightReading;
void setup() {
pinMode(leftIR, INPUT);
pinMode(rightIR, INPUT);
leftWheel.attach(10);
rightWheel.attach(11);
Serial.begin(9600);
}
void loop() {
leftReading = digitalRead(leftIR);
rightReading = digitalRead(rightIR);
Serial.println(leftReading);
Serial.println(rightReading);
if (leftReading == LOW && rightReading == LOW) {
leftWheel.write(87);
rightWheel.write(87);
}
else if (leftReading == HIGH && rightReading == LOW) {
leftWheel.write(90);
rightWheel.write(87);
}
else if (leftReading == LOW && rightReading == HIGH) {
leftWheel.write(87);
rightWheel.write(90);
}
else {
leftWheel.write(90);
rightWheel.write(90);
}
delay(10);
}
Be the first to comment