SunFounder 3in1 Kit
• If the right IR module detects your hand, turn right.
• If neither the infrared module nor the ultrasonic module detects your hand, let the car stop.
void loop() {
float distance = readSensorData();
int left = digitalRead(leftIR); // 0: Obstructed 1: Empty
int right = digitalRead(rightIR);
int speed = 150;
if (distance>5 && distance<10){
moveForward(speed);
}
if(!left&&right){
turnLeft(speed);
}else if(left&&!right){
turnRight(speed);
}else{
stopMove();
}
}
5.9 8. Self-Driving Car
This project is a combination of the two projects 6. Play with Ultrasonic Module and 5. Play with Obstacle Avoidance
Module. 2 infrared obstacle avoidance modules do short distance or edge detection, and ultrasonic modules do long
distance detection to confirm that the car does not hit an obstacle during the free driving process.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
3 in 1 Starter Kit 380+
You can also buy them separately from the links below.
COMPONENT INTRODUCTION PURCHASE LINK
Arduino Uno R4 Minima
L9110 Motor Driver Module -
TT Motor -
Ultrasonic Module
Obstacle Avoidance Module
Wiring
5.9. 8. Self-Driving Car 253