SunFounder 3in1 Kit
• Otherwise read the distance detected by the ultrasonic module.
• If the distance is greater than 50cm, let the car go forward.
• If the distance is between 2-10cm, let the car backward before turning.
• If the distance is between 10-50cm, let the car go forward at low speed.
void loop() {
int left = digitalRead(leftIR); // 0: Obstructed 1: Empty
int right = digitalRead(rightIR);
if (!left && right) {
backLeft(150);
} else if (left && !right) {
backRight(150);
} else if (!left && !right) {
moveBackward(150);
} else {
float distance = readSensorData();
Serial.println(distance);
if (distance > 50) { // Safe
moveForward(200);
} else if (distance < 10 && distance > 2) { // Attention
moveBackward(200);
delay(1000);
backLeft(150);
delay(500);
} else {
moveForward(150);
}
}
}
5.10 9. Remote Control
This kit comes with an IR receiver, which allows you to use an IR remote control to control the movement of the car.
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.
256 Chapter 5. Car Projects