> ## Content Index
> Fetch the complete content index at: https://tpx-labs.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Multi-Functional Arduino-Controlled Robotic Car
- URL: https://tpx-labs.com/multi-functional-arduino-controlled-robotic-car/
- Published: 2025-07-24T11:18:25.000Z
- Updated: 2025-08-18T09:37:43.000Z
- Author: Omar TPX
- Tags: #Import 2026-10-03 16:41

# Introduction

I chose this project out of a genuine passion for merging creativity with technology. Although I could not cover every single detail in this report (that would take a lot more effort), I’m excited to share the core ideas, features, and challenges I faced while building this **Arduino-powered multi-functional car**.

# Description

This project centers around a multi-functional robotic car powered and controlled by an Arduino-based system. The car's core components include an Arduino Nano, HC-SR04 Ultrasonic Sensor, and a robust motor system featuring an L298N Motor Driver. A remote-control device, equipped with analog joysticks, switches, and potentiometers, communicates wirelessly with the car using the nRF24L01 module. The car boasts diverse functionalities, including anti-collision capabilities using the distance sensor, an MP3 player for music playback, a 3-dimensional control arm manipulated through joysticks, and police-like lights for added visual appeal.

# Features

- **Long-Range Communication**  
Equipped with an **NRF24L01 wireless transceiver**, the car can communicate up to **1 km** at speeds reaching **2 Mbps**.
- **3DOF Robotic Arm**  
Controlled by joysticks, the arm can move freely in three degrees of freedom and grasp objects.
- **MP3 Player**  
With the **DFPlayer Mini**, the car can store and play more than **250 songs**.
- **Anti-Collision System**  
Using the **HC-SR04 ultrasonic sensor**, the car detects obstacles and automatically adjusts its path.

![](https://tpx-labs.com/content/images/2025/08/Capture.PNG)

![](https://tpx-labs.com/content/images/2025/08/Capture-1.PNG)

# Components Used

## Components in the Car

- NRF24L01 – wireless communication
- HC-SR04 – anti-collision
- 4 Wheels + Motors – movement
- L298N – motor driver
- Arduino Nano – main controller
- PCA9685 – servo control
- 4x MG90s Servos – robotic arm
- 1x SG90 Servo – ultrasonic sensor
- DFPlayer + 2W Speaker – audio system
- LEDs – blue/red police effect
- Resistors + DC-DC regulator

## Intro to NRF24L01

NRF24L01 is a wireless transceiver module (works on SPI Protocol), which is used for sending and receiving data at an operating radio frequency of 2.4 to 2.5 GHz ISM band.

![](https://tpx-labs.com/content/images/2025/08/image.png)

This transceiver module consists of a frequency generator, shock burst mode controller, power amplifier, crystal oscillator modulator, and demodulator.

### Wiring Diagram

The nRF24L01+ are RF transceiver modules that can be used for wireless communications. They operate at a voltage range of 1.9 – 3.6V for power. This nRF24L01 breakout adapter can be powered off 5V-12V and supplies well regulated 3.3V to the NRF24L01 socket. It also breaks out the pins for easier hookup and has a power on LED.

![](https://tpx-labs.com/content/images/2025/08/image-1.png)

### Code Explanation

![](https://tpx-labs.com/content/images/2025/08/image-2.png)

This code sets up communication using the RF24 library for Arduino. It defines CE\_PIN and CSN\_PIN, initializes an RF24 radio object with these pins, and sets a communication address. The setup function configures the radio for reception, specifying the address and power level.

This code is intended for a receiver (listening) side to communicate with a transmitter side using NRF24L01 radio modules.

It defines a **Data structure** containing variables representing different sensor readings, switch states, and joystick positions. The `radio.read()` function reads the data into the structure, limited by the NRF24L01’s **32-byte payload size**. I used `int16_t` and `uint8_t` to keep within that limit.

![](https://tpx-labs.com/content/images/2025/08/image-3.png)

💡

****I faced a problem while testing the NRF. When I set the power to the maximum it appear that there is some noise in the data. In order for the transmitter to operate at maximum power, it turns out that a longer antenna must be used and sufficient power must be provided to ensure that problems do not occur.**

![](https://tpx-labs.com/content/images/2025/08/image-31.png)

![](https://tpx-labs.com/content/images/2025/08/image-32.png)

## Intro to HC-SR04

**HC-SR04** is an ultrasonic sensor, also known as an ultrasonic transducer that is based on a transmitter and receiver and mainly used to determine the distance from the target object. 

![](https://tpx-labs.com/content/images/2025/08/image-5.png)

The amount of time it takes to send and receive waves will determine how far the object is placed from the sensor .It mainly depends on the sound waves working on “non-contact” technology.

### Wiring and Code

<HCSR04.h> I used the library for the HC-SR04 ultrasonic sensor. This library provides functions to interact with the sensor easily.

An instance of the HCSR04 class named hc is created with the trigger pin connected to pin 20 and the echo pin connected to pin 21\. This sets up the sensor with the specified pins.

The avoid\_collision function checks if the distance measured by the ultrasonic sensor (hc.dist()) is less than 10 units (in centimeters). If the distance is less than 10 units, it calls the Stop\_F() function.

![](https://tpx-labs.com/content/images/2025/08/image-6.png)

### Demo Video

0:00 

/0:02 

1× 

## Intro to **L298N**

**The L298N** is a dual H-Bridge motor driver which allows speed and direction control of two DC motors at the same time. The module can drive DC motors that have voltages between 5 and 35V, with a peak current up to 2A. Let's take a closer look at the pinout of L298N module and explain how it works.

![](https://tpx-labs.com/content/images/2025/08/image-9.png)

The L298N motor driver has two channels, channel A and channel B. To operate the motor in channel A, connect pins Out 1 and Out 2\. Then connect pins Enable A and Enable B to the motor. The Enable A pin must be high to turn the motor on. To operate the motor in the counterclockwise direction, make the Input 1 pin low. For optimal performance of this motor type, the L298N motor driver is ideally paired with a 5V power supply.

![](https://tpx-labs.com/content/images/2025/08/image-8.png)

### Wiring and Code

The sketch below will show you how to control the speed and spinning direction of a DC motor using the L298N Motor Driver and can serve as the basis for more practical experiments and projects.

![](https://tpx-labs.com/content/images/2025/08/image-11.png)

I used int16\_t to reserve as little space as possible since the values ​​are fixed

**NOTE: When accelerating or decelerating the motor, you may hear it humming, especially at lower PWM values. This is normal; there is nothing to be concerned about. This happens because the DC motor requires a minimum amount of voltage to operate.**

![](https://tpx-labs.com/content/images/2025/08/image-12.png)

In the setup section of the code, all of the motor control pins, including the direction and speed control pins, are configured as digital OUTPUT.

these functions provide a convenient way to control the movement of a robotic car. By calling these functions with appropriate triggers (like user input or sensor readings), can make the car move forward, backward, turn left, turn right, or stop.

## Intro to **DFPlayer**

**The DFPlayer Mini MP3 Player** For Arduino is a small and low cost MP3 module with an simplified output directly to the speaker. The module can be used as a stand alone module with attached battery, speaker and push buttons or used in combination with microcontrollers such as Arduino, Raspberry Pi and any microcontrollers with Uart.

![](https://tpx-labs.com/content/images/2025/08/image-14.png)

### Specs

- 30 adjustable volume levels, 6 EQ settings
- Supports up to **100 folders**, each with 255 songs
- Serial/I/O/AD control modes

### Wiring and Code

I used a library Called <DFRobotDFPlayerMini.h> without this library I would have to send a HEX bytes to control the module.

![](https://tpx-labs.com/content/images/2025/08/image-15.png)

SoftwareSerial is a library that enables serial communication with a digital pin other than the serial port.

**Limitations of This Library:**

It cannot transmit and receive data at the same time.

If using multiple software serial ports, only one can receive data at a time.

**NOTE: It doesn’t work with 115200 baud rate**

![](https://tpx-labs.com/content/images/2025/08/image-16.png)

This code defines a music player function, Play\_Music, that takes input data from a controller via the Data structure. It checks the state of the left and right joystick switches (L\_J\_SW and R\_J\_SW), and based on their status. The playCurrentTrack function is then called to play the corresponding track. The input data is received from a transmitter module (TX module).

0:00 

/0:05 

1× 

## Intro to **DFPlayer**

The **PCA9685** is a 16-channel PWM controller that communicates over I2C, commonly used for precise control of LEDs and servos in robotics and lighting applications. It offers 12-bit resolution for accurate control and features an integrated oscillator for simplified design.

![](https://tpx-labs.com/content/images/2025/08/image-17.png)

### Specs

Contains an I2C-controlled PWM driver with a built-in clock. It means, unlike the TLC5940 family, you do not need to continuously send it signals tying up your microcontroller; it's completely free running!

Supports using only two pins to control 16 free-running PWM outputs.

12-bit resolution for each output - for servos, that means about 4us resolution at an update rate of 60Hz.

### Wiring and Code

The Adafruit\_PWMServoDriver library, which is used for controlling servo motors through PWM signals.

The Adafruit\_PWMServoDriver(0x40) line initializes an object named pca of the Adafruit\_PWMServoDriver class with the I2C address 0x40.

The function is designed to control a servo with a specified speed to avoid rapid and potentially jerky movements. By checking the elapsed time since the last movement (elapsedTime\_2) against the defined servoSpeed, the function ensures that the servo position is updated at a controlled rate. This approach helps in creating smoother and more controlled movements of the servo motor.

![](https://tpx-labs.com/content/images/2025/08/image-18.png)

To control the 3Dof Arm I created A function called Arm\_Control which take a data input from the left and right joysticks from the remote controller and do some calculations to move the arm according to the moves of the joysticks.

![](https://tpx-labs.com/content/images/2025/08/image-19.png)

![](https://tpx-labs.com/content/images/2025/08/image-21.png)

### Demo Video

0:00 

/0:04 

1× 

## Controller Components

- 2x Analog Joysticks – car & arm control
- 2x Toggle Switches – mode/feature control
- 2x Switches – feature activation
- 2x Potentiometers – fine-tuning (not used due to limited pins)
- **MPU9250 IMU** – provides yaw, pitch, roll
- Buzzer – startup sound feedback
- NRF24L01 – wireless communication
- Arduino Uno – main controller
- 12V battery + DC-DC step-down regulator

The startup plays a melody + LED blink for feedback.

![](https://tpx-labs.com/content/images/2025/08/image-23.png)

![](https://tpx-labs.com/content/images/2025/08/image-24.png)

## Wiring and code

![](https://tpx-labs.com/content/images/2025/08/image-25.png)

**2X Left and Right Analog Joysticks:** used for controlling the movement of the car. The joysticks may control the forward/backward motion and left/right steering.

**2X Toggle Switches:** These switches could be employed for toggling specific modes or features on the car. For example, switching between different operational modes like standard driving and arm control mode.

**2X Switches:** These additional switches could serve various purposes, such as turning on/off specific features or activating certain functions like lights or the MP3 player.

**2X Potentiometers:** Not used in the code because there is no left input pins for them.

**MPU9250:** This sensor provides information about the orientation and movement of the remote control device. It might be used for controlling the robotic arm or for other advanced control features.

**Buzzer:** provides audio feedback, signaling the user when the remote control device is activated.

![](https://tpx-labs.com/content/images/2025/08/image-26.png)

**DC-DC Step Down Voltage Regulator Module:** This module regulates the voltage from the 12V battery to a stable level suitable for the components on the remote control device, ensuring consistent and reliable operation.

**Pin Definitions:** Various digital and analog pins are defined for buttons (Mode\_SW, RIGHT\_SW, LEFT\_SW, RIGHT\_JOYSTICK\_SW, LEFT\_JOYSTICK\_SW), a buzzer (Buzzer), an LED (LED), and joystick inputs (RIGHT\_JOYSTICK\_X, RIGHT\_JOYSTICK\_Y, LEFT\_JOYSTICK\_X, LEFT\_JOYSTICK\_Y).

Initializes pin modes, sets up the MPU9250 sensor, starts communication with the nRF24L01 module, and prepares the radio for writing.

Creates a Data struct to store sensor and control data. Updates sensor data (Yaw, Roll, Pitch) using the MPU9250 sensor. Reads the states of various switches, buttons, and joysticks. Writes the collected data to the nRF24L01 radio transmitter for communication with the car.

The code reads sensor data from the MPU9250 sensor, captures the states of various buttons and joysticks, organizes this information into a Data struct, and transmits it wirelessly to the car using the nRF24L01 module. The startup melody and LED blink provide feedback to the user, indicating the remote control is ready for use.

**Melody Function:**

![](https://tpx-labs.com/content/images/2025/08/image-27.png)

playMelody function generates a melody  
using the tone function to play a startup sound on the buzzer.

**Startup Feedback:**

The startup melody and LED blink provide feedback to the user, indicating that the remote is active and ready for operation.

### Demo Video

0:00 

/0:06 

1× 

### MPU-9250 IMU Sensor

![](https://tpx-labs.com/content/images/2025/08/image-29.png)

The **MPU9250** is a motion tracking device that combines a 3-axis gyroscope, a 3-axis accelerometer, and a 3-axis magnetometer into a single chip. It is commonly used in applications that require precise measurement of motion, orientation, and magnetic field strength.

The MPU9250 provides data such as yaw, pitch, and roll angles, as well as raw sensor readings. These data can be utilized to understand the device's orientation and motion in 3D space.

Inside the if statement, three sensor readings are retrieved:

![](https://tpx-labs.com/content/images/2025/08/image-30.png)

data.Yaw = mpu.getYaw();: Gets the yaw angle, which represents the rotation around the vertical axis.

data.Roll = mpu.getRoll();: Gets the roll angle, representing the rotation around the longitudinal axis.

data.Bitch = mpu.getPitch();: Gets the pitch angle, representing the rotation around the lateral axis.

# Schematic

![](https://tpx-labs.com/content/images/2025/08/ac.PNG)

![](https://tpx-labs.com/content/images/2025/08/casc.PNG)

Transmitter and Reciever Full Wiring Diagram

# Code

**Transmitter Side**

```cpp
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include "MPU9250.h"

RF24 radio(9, 10);
const byte address[6] = "00001";
MPU9250 mpu;

#define Mode_SW            5
#define RIGHT_SW           7
#define LEFT_SW            4
#define Buzzer             6
#define LED                8
#define RIGHT_JOYSTICK_SW  3
#define LEFT_JOYSTICK_SW   2
#define CE_PIN             9
#define CSN_PIN            10
#define RIGHT_JOYSTICK_X   A2
#define RIGHT_JOYSTICK_Y   A3
#define LEFT_JOYSTICK_X    A0
#define LEFT_JOYSTICK_Y    A1

int melody[] = {
  392, 150,  // G4
  523, 150,  // C5
  659, 150,  // E5
  784, 150,  // G5
  987, 150,  // B5
  1319, 150, // E6
  1046, 150, // C6
  1568, 150  // G6
};

struct Data {
  int16_t Yaw;
  int16_t Roll;
  int16_t Bitch;
  uint8_t Mode;
  uint8_t R_SW;
  uint8_t L_SW;
  uint8_t R_J_SW;
  uint8_t L_J_SW;
  uint16_t R_J_X;
  uint16_t R_J_Y;
  uint16_t L_J_X;
  uint16_t L_J_Y;
};

void setup() {
  pinMode(Mode_SW, INPUT_PULLUP);
  pinMode(RIGHT_JOYSTICK_SW, INPUT_PULLUP);
  pinMode(LEFT_JOYSTICK_SW, INPUT_PULLUP);
  pinMode(RIGHT_SW, INPUT_PULLUP);
  pinMode(LEFT_SW, INPUT_PULLUP);
  pinMode(Buzzer, OUTPUT);
  pinMode(LED, OUTPUT);

  Wire.begin();
  playMelody();
  delay(2000);
  mpu.setup(0x68);

  digitalWrite(LED, HIGH);
  Serial.begin(115200);

  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_LOW);
  radio.stopListening();
}

void loop() {
  Data data;

  if (mpu.update()) {
    data.Yaw = mpu.getYaw();
    data.Roll = mpu.getRoll();
    data.Bitch = mpu.getPitch();
  }

  data.R_SW = digitalRead(RIGHT_SW);
  data.L_SW = digitalRead(LEFT_SW);
  data.R_J_SW = digitalRead(RIGHT_JOYSTICK_SW);
  data.L_J_SW = digitalRead(LEFT_JOYSTICK_SW);
  data.Mode = digitalRead(Mode_SW);
  data.R_J_X = analogRead(RIGHT_JOYSTICK_X);
  data.R_J_Y = analogRead(RIGHT_JOYSTICK_Y);
  data.L_J_X = analogRead(LEFT_JOYSTICK_X);
  data.L_J_Y = analogRead(LEFT_JOYSTICK_Y);

  radio.write(&data, sizeof(data));
}

void playMelody() {
  for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i += 2) {
    int noteDuration = melody[i + 1];
    tone(Buzzer, melody[i], noteDuration);
    delay(noteDuration);
    noTone(Buzzer);
    delay(20);
  }
}

```

**Receiver Side**

```cpp
#include <HCSR04.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include <Adafruit_PWMServoDriver.h>

#define CE_PIN 9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);
const byte address[6] = "00001";
HCSR04 hc(20, 21); // (trig pin, echo pin)
Adafruit_PWMServoDriver pca = Adafruit_PWMServoDriver(0x40);
SoftwareSerial softwareSerial(17, 8);
DFRobotDFPlayerMini player;

// Motor pins
int16_t m1a = 2;
int16_t m2a = 3;
int16_t m1b = 4;
int16_t m2b = 7;
int16_t ENA = 5;
int16_t ENB = 6;

// LEDs
int16_t Blue_Led = 14;
int16_t Red_Led = 15;

// Servo channels
int16_t X_Axis_Servo = 4;
int16_t Y_Axis_Servo = 3;
int16_t Z_Axis_Servo = 2;
int16_t Clamp_Servo = 1;
int16_t Ultrasonic_Servo = 0;

// Timing
unsigned long prevTime = millis();
unsigned long currentTime = millis();
unsigned long prevTime_2 = 0;

bool led1_state = false;

// Servo positions
float posX = 2023;
float posY = 1500;
float posZ = 1160;
float Clamp = 1300;

// Movement
int x, y, z;
int speed;
int pos;
int servoSpeed = 50;
int currentTrack = 1;

// Limits
int X_limit[2] = { 1750, 2250 };
int Y_limit[2] = { 1100, 2400 };
int Z_limit[2] = { 500, 2150 };
int C_limit[2] = { 1300, 2450 };

struct Data {
  int16_t Yaw;
  int16_t Roll;
  int16_t Bitch;
  uint8_t Mode;
  uint8_t R_SW;
  uint8_t L_SW;
  uint8_t R_J_SW;
  uint8_t L_J_SW;
  uint16_t R_J_X;
  uint16_t R_J_Y;
  uint16_t L_J_X;
  uint16_t L_J_Y;
};

void setup() {
  pca.begin();
  pca.setPWMFreq(60);
  softwareSerial.begin(9600);
  player.begin(softwareSerial);

  pinMode(ENB, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(m1a, OUTPUT);
  pinMode(m1b, OUTPUT);
  pinMode(m2a, OUTPUT);
  pinMode(m2b, OUTPUT);
  pinMode(Blue_Led, OUTPUT);
  pinMode(Red_Led, OUTPUT);

  Serial.begin(115200);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening();
  player.volume(25);

  Init();
}

void loop() {
  delay(5);
  currentTime = millis();
  if (radio.available()) {
    Data data;
    radio.read(&data, sizeof(data));
    Police_Leds(data);
    avoid_collision();

    if (data.Mode) {
      Arm_Control(data);
      Imu_Control(data);
    } else {
      Car_Control(data);
    }

    Play_Music(data);
  }
}

void avoid_collision() {
  if (hc.dist() < 10) {
    Stop_F();
  }
}

void Init() {
  pca.writeMicroseconds(Z_Axis_Servo, 1260);
  pca.writeMicroseconds(X_Axis_Servo, 2030);
  pca.writeMicroseconds(Y_Axis_Servo, 1500);
  pca.writeMicroseconds(Clamp_Servo, 1300);
  pca.writeMicroseconds(Ultrasonic_Servo, 1500);
}

void Play_Music(Data data) {
  if (!data.L_J_SW) {
    currentTrack = (currentTrack > 1) ? currentTrack - 1 : 9;
    playCurrentTrack();
  }

  if (!data.R_J_SW) {
    currentTrack = (currentTrack < 9) ? currentTrack + 1 : 1;
    playCurrentTrack();
  }
}

void playCurrentTrack() {
  player.play(currentTrack);
}

void Arm_Control(Data data) {
  servoSpeed = 20;

  // Y-axis up
  if (between(data.L_J_Y, 560, 1023) && between(data.L_J_X, 500, 520)) {
    posY += 10;
    if (!between(posY, Y_limit[0], Y_limit[1])) posY -= 10;
    controlServoWithSpeed(Y_Axis_Servo, posY);
  }

  // Y-axis down
  else if (between(data.L_J_Y, 0, 490) && between(data.L_J_X, 500, 520)) {
    posY -= 10;
    if (!between(posY, Y_limit[0], Y_limit[1])) posY += 10;
    controlServoWithSpeed(Y_Axis_Servo, posY);
  }

  // X-axis right
  else if (between(data.L_J_X, 0, 500) && between(data.L_J_Y, 520, 525)) {
    posX += 10;
    if (!between(posX, X_limit[0], X_limit[1])) posX -= 10;
    controlServoWithSpeed(X_Axis_Servo, posX);
  }

  // X-axis left
  else if (between(data.L_J_X, 525, 1023) && between(data.L_J_Y, 520, 525)) {
    posX -= 10;
    if (!between(posX, X_limit[0], X_limit[1])) posX += 10;
    controlServoWithSpeed(X_Axis_Servo, posX);
  }

  // Z-axis up
  else if (between(data.R_J_X, 500, 530) && between(data.R_J_Y, 550, 1023)) {
    posZ += 10;
    if (!between(posZ, Z_limit[0], Z_limit[1])) posZ -= 10;
    controlServoWithSpeed(Z_Axis_Servo, posZ);
  }

  // Z-axis down
  else if (between(data.R_J_Y, 0, 495) && between(data.R_J_X, 500, 530)) {
    posZ -= 10;
    if (!between(posZ, Z_limit[0], Z_limit[1])) posZ += 10;
    controlServoWithSpeed(Z_Axis_Servo, posZ);
  }

  // Clamp open
  else if (between(data.R_J_Y, 495, 505) && between(data.R_J_X, 550, 1023)) {
    Clamp += 10;
    if (!between(Clamp, C_limit[0], C_limit[1])) Clamp -= 10;
    controlServoWithSpeed(Clamp_Servo, Clamp);
  }

  // Clamp close
  else if (between(data.R_J_X, 0, 480) && between(data.R_J_Y, 495, 505)) {
    Clamp -= 10;
    if (!between(Clamp, C_limit[0], C_limit[1])) Clamp += 10;
    controlServoWithSpeed(Clamp_Servo, Clamp);
  }
}

void Imu_Control(Data data) {
  if (between(data.Roll, -5, 5) && between(data.Bitch, -40, -10)) {
    speed = map(data.Bitch, 5, -40, 0, 255);
    analogWrite(ENA, speed);
    analogWrite(ENB, speed);
    Forward_W();
  } else if (between(data.Roll, -5, 5) && between(data.Bitch, 10, 40)) {
    speed = map(data.Bitch, 10, 40, 0, 255);
    analogWrite(ENA, speed);
    analogWrite(ENB, speed);
    Backward_S();
  } else if (between(data.Roll, -5, 5) && between(data.Bitch, -9, 9)) {
    Stop_F();
  } else if (between(data.Roll, 10, 40) && between(data.Bitch, -9, 9)) {
    pos = map(data.Roll, 10, 40, 1500, 800);
    controlServoWithSpeed(Ultrasonic_Servo, pos);
    speed = map(data.Roll, 10, 40, 0, 255);
    analogWrite(ENA, speed);
    analogWrite(ENB, speed);
    Right_D();
  } else if (between(data.Roll, -40, -10) && between(data.Bitch, -9, 9)) {
    pos = map(data.Roll, -10, -40, 1500, 2100);
    controlServoWithSpeed(Ultrasonic_Servo, pos);
    speed = map(data.Roll, -10, -40, 0, 255);
    analogWrite(ENA, speed);
    analogWrite(ENB, speed);
    Left_A();
  }
}

void Car_Control(Data data) {
  Init();
  if (between(data.L_J_Y, 520, 525) && between(data.L_J_X, 0, 515)) {
    speed = map(data.L_J_X, 512, 0, 0, 255);
    analogWrite(ENA, speed);
    analogWrite(ENB, speed);
    Forward_W();
  } else if (between(data.L_J_Y, 520, 525) && between(data.L_J_X, 510, 515)) {
    controlServoWithSpeed(Ultrasonic_Servo, 1500);
    Stop_F();
  } else if (between(data.L_J_Y, 500, 530) && between(data.L_J_X, 550, 1023)) {
    speed = map(data.L_J_X, 512, 1023, 0, 255);
    analogWrite(ENA, speed);
    analogWrite(ENB, speed);
    Backward_S();
  } else if (between(data.L_J_Y, 530, 1023) && between(data.L_J_X, 510, 515)) {
    pos = map(data.L_J_Y, 520, 1023, 1500, 2100);
    controlServoWithSpeed(Ultrasonic_Servo, pos);
    speed = map(data.L_J_Y, 523, 1023, 0, 255);
    analogWrite(ENA, speed);
    analogWrite(ENB, speed);
    Left_A();
  } else if (between(data.L_J_Y, 0, 520) && between(data.L_J_X, 510, 515)) {
    pos = map(data.L_J_Y, 520, 0, 1500, 800);
    controlServoWithSpeed(Ultrasonic_Servo, pos);
    speed = map(data.L_J_Y, 522, 0, 0, 255);
    analogWrite(ENA, speed);
    analogWrite(ENB, speed);
    Right_D();
  }
}

bool between(int number, int min, int max) {
  return number >= min && number <= max;
}

void Debug(Data data) {
  Serial.print("Yaw :"); Serial.print(data.Yaw);
  Serial.print(" Roll :"); Serial.print(data.Roll);
  Serial.print(" Bitch :"); Serial.print(data.Bitch);
  Serial.print(" R_SW :"); Serial.print(data.R_SW);
  Serial.print(" L_SW :"); Serial.print(data.L_SW);
  Serial.print(" R_J_SW :"); Serial.print(data.R_J_SW);
  Serial.print(" L_J_SW :"); Serial.print(data.L_J_SW);
  Serial.print(" Mode :"); Serial.print(data.Mode);
  Serial.print(" L_J_X :"); Serial.print(data.L_J_X);
  Serial.print(" L_J_Y :"); Serial.print(data.L_J_Y);
  Serial.print(" R_J_X :"); Serial.print(data.R_J_X);
  Serial.print(" R_J_Y :"); Serial.println(data.R_J_Y);
}

void Police_Leds(Data data) {
  if (data.L_SW == 1) {
    unsigned long elapsedTime = currentTime - prevTime;
    if (elapsedTime >= 150) {
      led1_state = !led1_state;
      digitalWrite(Blue_Led, led1_state ? HIGH : LOW);
      digitalWrite(Red_Led, !led1_state ? HIGH : LOW);
      prevTime = currentTime;
    }
  } else {
    digitalWrite(Blue_Led, LOW);
    digitalWrite(Red_Led, LOW);
  }
}

void controlServoWithSpeed(int servoPin, int targetPos) {
  unsigned long currentTime_2 = millis();
  unsigned long elapsedTime_2 = currentTime_2 - prevTime_2;
  if (elapsedTime_2 >= servoSpeed) {
    pca.writeMicroseconds(servoPin, targetPos);
    prevTime_2 = currentTime_2;
  }
}

void Forward_W() {
  digitalWrite(m1a, 1);
  digitalWrite(m1b, 1);
  digitalWrite(m2a, 0);
  digitalWrite(m2b, 0);
}

void Backward_S() {
  digitalWrite(m1a, 0);
  digitalWrite(m1b, 0);
  digitalWrite(m2a, 1);
  digitalWrite(m2b, 1);
}

void Left_A() {
  digitalWrite(m1a, 0);
  digitalWrite(m1b, 1);
  digitalWrite(m2a, 0);
  digitalWrite(m2b, 0);
}

void Right_D() {
  digitalWrite(m1a, 1);
  digitalWrite(m1b, 0);
  digitalWrite(m2a, 0);
  digitalWrite(m2b, 0);
}

void Stop_F() {
  digitalWrite(m1a, 0);
  digitalWrite(m1b, 0);
  digitalWrite(m2a, 0);
  digitalWrite(m2b, 0);
}

```

# Project Conclusion

In conclusion, the Arduino-controlled multi-functional car project represents a successful integration of various components to create a versatile and interactive robotic system.  
The car, equipped with features such as anti-collision capabilities, an MP3 player, a 3-dimensional control arm, police-like lights, and powerful motors, showcases the potential of combining hardware and software for innovative applications.  
The remote control device, with its array of controls including joysticks, switches, and potentiometers, serves as a user-friendly interface for wirelessly commanding the car.  
The incorporation of an MPU9250 sensor enhances the control experience by providing precise motion and orientation data.  
Through careful coding and configuration, the project achieves seamless communication between the remote control and the car using the nRF24L01 module.  
The modular code structure, encapsulating functionalities into functions and structures, enhances readability and maintainability.

Challenges and Solutions:  
Throughout the project, several challenges were encountered and addressed. These included:

Integration Complexity:  
Combining various components, each with its unique functionality, required meticulous planning and testing to ensure proper interaction and synchronization.

Wireless Communication Stability:  
Achieving stable and reliable wireless communication between the remote control and the car posed challenges related to signal interference and range limitations.  
Adjustments to the communication protocols and hardware configurations were implemented to enhance reliability.

Sensor Calibration:  
Calibrating and fine-tuning the MPU9250 sensor for accurate readings demanded thorough understanding of sensor behavior and calibration techniques. Iterative adjustments were made to achieve optimal performance.

Project Motivation:  
The decision to undertake this project stemmed from a desire to explore and apply a diverse range of skills in electronics, programming, and robotics.  
The project presented an opportunity to integrate multiple components, ranging from basic motors to advanced sensors, to create a comprehensive and functional robotic system.  
Moreover, the project allowed for hands-on experience in wireless communication, sensor integration, and real-time control – skills that are valuable in various engineering and robotics applications.  
The motivation was not only to create a functional robot but also to delve into the intricacies of designing and implementing complex systems.  
In conclusion, the Arduino-controlled multi-functional car project serves as both an educational endeavor and a tangible representation of creativity and technical proficiency in the field of robotics and embedded systems.  
The challenges encountered throughout the project served as valuable learning experiences, contributing to an enhanced understanding of hardware-software integration and robotic control.

## Gallery

![](https://tpx-labs.com/content/images/2025/08/20231201_161334.jpg)

![](https://tpx-labs.com/content/images/2025/08/20231201_161416.jpg)

![](https://tpx-labs.com/content/images/2025/08/20231201_161430.jpg)

![](https://tpx-labs.com/content/images/2025/08/20231201_161515.jpg)

![](https://tpx-labs.com/content/images/2025/08/20231201_161533.jpg)

![](https://tpx-labs.com/content/images/2025/08/20231201_161602.jpg)

![](https://tpx-labs.com/content/images/2025/08/20231201_161649.jpg)

![](https://tpx-labs.com/content/images/2025/08/20231201_161722.jpg)

![](https://tpx-labs.com/content/images/2025/08/20231201_161759.jpg)

## Video

0:00 

/0:57 

1×