Ever dreamed of building your own remote-controlled spy bot? With an Arduino and a few simple components, you can create a nimble, Bluetooth-controlled robot that can stealthily explore any environment. This project is a fantastic way to dive into the worlds of robotics, wireless communication, and embedded systems.
Our spy robot is a two-wheeled vehicle controlled by a smartphone. It uses a Bluetooth module to receive commands from an app, and an Arduino Uno to process these commands and control the motors. The caster wheel at the front provides balance, making it highly maneuverable.
The Build: Components You'll NeedTo bring your spy robot to life, you will need the following components:
Arduino Uno: The brain of the operation. It receives commands from the Bluetooth module and translates them into actions for the motors.
- Arduino Uno: The brain of the operation. It receives commands from the Bluetooth module and translates them into actions for the motors.
HC-05 or HC-06 Bluetooth Module: This is the communication hub. It creates a wireless serial connection between your smartphone and the Arduino. The HC-05 is preferred as it can be set as both master and slave.
- HC-05 or HC-06 Bluetooth Module: This is the communication hub. It creates a wireless serial connection between your smartphone and the Arduino. The HC-05 is preferred as it can be set as both master and slave.
L298N Motor Driver Module: This is the muscle. The Arduino's pins cannot supply enough power to drive DC motors directly. The L298N acts as a high-power switch, providing the necessary current and voltage to the motors based on the low-power signals from the Arduino.
- L298N Motor Driver Module: This is the muscle. The Arduino's pins cannot supply enough power to drive DC motors directly. The L298N acts as a high-power switch, providing the necessary current and voltage to the motors based on the low-power signals from the Arduino.
BO Motors (2) with Wheels: These are gear motors that provide the drive for your robot. They are compact, provide good torque, and come with matching wheels.
- BO Motors (2) with Wheels: These are gear motors that provide the drive for your robot. They are compact, provide good torque, and come with matching wheels.
Lithium-Ion Battery (18650) with Holder: A portable and rechargeable power source is crucial for a mobile robot. A 2-cell 18650 battery holder providing 7.4V is ideal for both the motor driver and the Arduino.
- Lithium-Ion Battery (18650) with Holder: A portable and rechargeable power source is crucial for a mobile robot. A 2-cell 18650 battery holder providing 7.4V is ideal for both the motor driver and the Arduino.
Caster Wheel: A small swiveling ball caster or roller wheel is attached to the front or back of the chassis to provide stability and balance for the two driven wheels.
- Caster Wheel: A small swiveling ball caster or roller wheel is attached to the front or back of the chassis to provide stability and balance for the two driven wheels.
Chassis: A base platform to mount all your components. You can use a pre-fabricated robot chassis or build your own from acrylic or wood.
- Chassis: A base platform to mount all your components. You can use a pre-fabricated robot chassis or build your own from acrylic or wood.
Jumper Wires & Breadboard: For making all the necessary connections in the circuit.
- Jumper Wires & Breadboard: For making all the necessary connections in the circuit.
Smartphone with Bluetooth Control App: You will need an app like "Arduino Bluetooth Controller" or "Bluetooth RC Car" to send control commands from your phone.
- Smartphone with Bluetooth Control App: You will need an app like "Arduino Bluetooth Controller" or "Bluetooth RC Car" to send control commands from your phone.
(Image Description: A diagram showing the circuit connections. The Arduino Uno is in the center. The HC-05 Bluetooth module is connected to pins 0 (RX) and 1 (TX). The L298N motor driver is connected: ENA to pin 5, IN1 to pin 4, IN2 to pin 3, IN3 to pin 8, IN4 to pin 7, and ENB to pin 6. Motor A is connected to the L298N's OUT1 and OUT2, and Motor B to OUT3 and OUT4. The battery is connected to the power input of the L298N.)
The Code: The Robot's IntelligenceThe Arduino code is what makes the robot responsive. It waits for a single character command from the Bluetooth module and then executes the corresponding movement.
How the Code Works:
In the setup()
function, it initializes the motor control pins as outputs and starts serial communication with the Bluetooth module.
- In the
setup()
function, it initializes the motor control pins as outputs and starts serial communication with the Bluetooth module.
The loop()
function constantly checks if data is available from the Bluetooth module.
- The
loop()
function constantly checks if data is available from the Bluetooth module.
When a character is received, a switch
statement determines the action:
'F' drives both motors Forward.
- 'F' drives both motors Forward.
'B' drives both motors Backward.
- 'B' drives both motors Backward.
'L' turns the robot Left by running the right motor forward and the left motor backward.
- 'L' turns the robot Left by running the right motor forward and the left motor backward.
'R' turns the robot Right by running the left motor forward and the right motor backward.
- 'R' turns the robot Right by running the left motor forward and the right motor backward.
'S'Stops all motors.
- 'S'Stops all motors.
- When a character is received, a
switch
statement determines the action:'F' drives both motors Forward.'B' drives both motors Backward.'L' turns the robot Left by running the right motor forward and the left motor backward.'R' turns the robot Right by running the left motor forward and the right motor backward.'S'Stops all motors.
The runMotor()
function is a helper that simplifies the logic for setting the motor direction.
- The
runMotor()
function is a helper that simplifies the logic for setting the motor direction.
cpp
// Spy Robot with Bluetooth Control
// Define motor control pins
#define enA 5
#define in1 4
#define in2 3
#define in3 8
#define in4 7
#define enB 6
char command;
void setup() {
// Set all motor control pins as outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Initialize serial communication for Bluetooth
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
command = Serial.read();
Serial.println(command); // Echo for debugging
switch (command) {
case 'F': // Move Forward
runMotor(HIGH, LOW, HIGH, LOW);
break;
case 'B': // Move Backward
runMotor(LOW, HIGH, LOW, HIGH);
break;
case 'L': // Turn Left
runMotor(LOW, HIGH, HIGH, LOW);
break;
case 'R': // Turn Right
runMotor(HIGH, LOW, LOW, HIGH);
break;
case 'S': // Stop
runMotor(LOW, LOW, LOW, LOW);
break;
}
}
}
void runMotor(int leftDir1, int leftDir2, int rightDir1, int rightDir2) {
digitalWrite(in1, leftDir1);
digitalWrite(in2, leftDir2);
digitalWrite(in3, rightDir1);
digitalWrite(in4, rightDir2);
// Set speed (adjust PWM value 0-255)
analogWrite(enA, 200);
analogWrite(enB, 200);
}
Comments