Component Name: DIY Mini Battery Powered 4 Wheel Drive Car
The DIY Mini Battery Powered 4 Wheel Drive Car is a small-scale, battery-powered vehicle designed for prototyping and development in the Internet of Things (IoT) ecosystem. This component is ideal for robotics, automation, and STEM education projects. The car is equipped with four-wheel drives, making it suitable for navigating various terrain types.
Technical Specifications:
Microcontroller: Arduino Board (e.g., Arduino Uno or Arduino Nano)
Motor Driver: L298N Motor Driver IC
Motors: 4 x DC Geared Motors (e.g., TT Gear Motor 200RPM)
Power Source: 4 x AA Batteries or 1 x Lithium-Ion Battery (3.7V 1000mAh)
Communication Protocol: Serial Communication (UART)
### Example 1: Basic Obstacle Avoidance Using Ultrasonic Sensor
In this example, we will demonstrate how to use the DIY Mini Battery Powered 4 Wheel Drive Car to avoid obstacles using an ultrasonic sensor. We will use the Arduino Uno board as the microcontroller.
DIY Mini Battery Powered 4 Wheel Drive Car
Arduino Uno board
Ultrasonic Sensor (e.g., HC-SR04)
Jumper wires
Code:
```c++
#include <Arduino.h>
// Define motor pins
const int leftMotorForward = 2;
const int leftMotorBackward = 3;
const int rightMotorForward = 4;
const int rightMotorBackward = 5;
// Define ultrasonic sensor pins
const int trigPin = 6;
const int echoPin = 7;
void setup() {
// Initialize motor pins as outputs
pinMode(leftMotorForward, OUTPUT);
pinMode(leftMotorBackward, OUTPUT);
pinMode(rightMotorForward, OUTPUT);
pinMode(rightMotorBackward, OUTPUT);
// Initialize ultrasonic sensor pins
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// Read distance from ultrasonic sensor
int distance = readDistance();
// If obstacle is detected (distance < 20 cm), avoid it
if (distance < 20) {
avoidObstacle();
} else {
// Move forward
moveForward();
}
int readDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
int duration = pulseIn(echoPin, HIGH);
int distance = duration 0.034 / 2;
return distance;
}
void avoidObstacle() {
// Turn right
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorBackward, HIGH);
delay(500);
// Move backward
digitalWrite(leftMotorBackward, HIGH);
digitalWrite(rightMotorBackward, HIGH);
delay(500);
// Turn left
digitalWrite(leftMotorBackward, HIGH);
digitalWrite(rightMotorForward, HIGH);
delay(500);
}
void moveForward() {
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorForward, HIGH);
}
```
### Example 2: Remote Control Using Bluetooth Module
In this example, we will demonstrate how to control the DIY Mini Battery Powered 4 Wheel Drive Car using a Bluetooth module and a smartphone app.
DIY Mini Battery Powered 4 Wheel Drive Car
Arduino Uno board
Bluetooth Module (e.g., HC-05 or HC-06)
Smartphone with Bluetooth capability
Jumper wires
Code:
```c++
#include <Arduino.h>
#include <SoftwareSerial.h>
// Define motor pins
const int leftMotorForward = 2;
const int leftMotorBackward = 3;
const int rightMotorForward = 4;
const int rightMotorBackward = 5;
// Define Bluetooth module pins
const int bluetoothTx = 10;
const int bluetoothRx = 11;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
// Initialize motor pins as outputs
pinMode(leftMotorForward, OUTPUT);
pinMode(leftMotorBackward, OUTPUT);
pinMode(rightMotorForward, OUTPUT);
pinMode(rightMotorBackward, OUTPUT);
// Initialize Bluetooth module
bluetooth.begin(9600);
}
void loop() {
// Read data from Bluetooth module
if (bluetooth.available() > 0) {
char command = bluetooth.read();
// Process commands from smartphone app
if (command == 'F') {
moveForward();
} else if (command == 'B') {
moveBackward();
} else if (command == 'L') {
turnLeft();
} else if (command == 'R') {
turnRight();
}
}
}
void moveForward() {
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorForward, HIGH);
}
void moveBackward() {
digitalWrite(leftMotorBackward, HIGH);
digitalWrite(rightMotorBackward, HIGH);
}
void turnLeft() {
digitalWrite(leftMotorBackward, HIGH);
digitalWrite(rightMotorForward, HIGH);
}
void turnRight() {
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorBackward, HIGH);
}
```
Note: In this example, you need to pair the Bluetooth module with your smartphone and send commands using a terminal or a custom app. The commands should be sent as single characters (e.g., 'F' for forward, 'B' for backward, 'L' for left, and 'R' for right).