top of page

All Blogs

Remote Controlled Car Using Raspberry Pi and Bluetooth

Writer's picture: Aryan AryaAryan Arya

Raspberry Pi is very popular for IoT projects because of its seamless ability of wireless communication over the internet. Raspberry Pi 3 has inbuilt Wi-Fi and Bluetooth, and Bluetooth is a very popular wireless communication Protocol. Today we going to build a Remote Controlled Car using Raspberry Pi 3 and Bluetooth, here we will use Smart Phone as a remote to control the car. We have previously built created this RC car using Arduino.


Here we are using Raspberry Pi 3 which have inbuilt Bluetooth, so we don't need to use any external USB Bluetooth dongle. Here we are using RFCOMM Bluetooth protocol for wireless communication.

Programming for Bluetooth in Python follows the socket programming model and communications between the Bluetooth devices is done through RFCOMM socket. RFCOMM (Radio Frequency Communication) is a Bluetooth Protocol which provided emulated RS-232 serial ports and also called as Serial Port Emulation. Bluetooth serial port profile is based on this protocol. RFCOMM is very popular in Bluetooth applications because of its wide support and publically available API. It is bound to L2CAP protocol.

If you have Raspberry Pi 2, then you either need to use external Bluetooth dongle or Bluetooth module HC-06. Check our previous projects for using these external Bluetooth devices: Controlling Raspberry Pi GPIO using Android App over Bluetooth and Raspberry Pi controlled Home Appliances

Installing Required Packages for Bluetooth Communication:

Before starting, we need to install some software for setting up Bluetooth communication in Raspberry Pi. You should have a Raspbian Jessie installed memory card ready with Raspberry Pi. Check this article to install the Raspbian OS and getting started with Raspberry Pi. So now we first need to update the Raspbian using below commands:

sudo apt-get update
sudo apt-get upgrade

Then we need to install few Bluetooth related packages:

sudo apt-get install bluetooth blueman bluez

Then reboot the Raspberry Pi:

sudo reboot

BlueZ is a open source project and official Linux Bluetooth protocol stack. It supports all the core Bluetooth protocols and now become part of official Linux Kernel.

Blueman provides the Desktop interface to manage and control the Bluetooth devices.

Finally we need python Library for Bluetooth communication so that we can send and receive data through RFCOMM using Python language:

sudo apt-get install python-bluetooth

Also install the GPIO support libraries for Raspberry Pi:

sudo apt-get install python-rpi.gpio

Now we are done with installing required packages for Bluetooth communication in Raspberry Pi.

Pairing Devices with Raspberry Pi over Bluetooth:

Pairing Bluetooth Devices, like mobile phone, with Raspberry Pi is very easy. Here we have paired our Android Smart phone with Raspberry Pi. We have previously installed BlueZ in Pi, which provides a command line utility called “bluetoothctl” to manage our Bluetooth devices.

Now open the bluetoothctl utility by below command:

sudo bluetoothctl

You can check all the commands of bluetoothctl utility by typing ‘help’. For now we need to enter below commands in given order:

[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# discoverable on
[bluetooth]# pairable on
[bluetooth]# scan on

After the last command “scan on”, you will see your Bluetooth device (Mobile phone) in the list. Make sure that your mobile has Bluetooth turned on and visible by nearby devices. Then copy the MAC address of you device and pair it by using given command:

pair <address of your phone>

Then you will be prompted for Passcode or Pin in your Terminal console then type passcode there and press enter. Then type the same passcode in your mobile phone when prompted and you are now successfully paired with Raspberry Pi. We have also explained this whole process in the Video given in previous GPIO controlling Tutorial. Here is the direct YouTube link.



As told earlier, you can also use Desktop interface to pair the Mobile phone. After installing Blueman, you will see a Bluetooth icon in right side of your Raspberry Pi desktop as shown below, using which you can easily do the pairing.



Selecting the Toy Car:

In this Raspberry Pi Controlled Car project we have used a toy car for demonstration. Here we have selected a RF toy car with moving left-right steering feature. After buying this car we have replaced its RF circuit with our Raspberry circuit. This car has two DC motors, one to rotate two front wheel and other one is to rotate two rear wheels. Front side motor is used for giving direction to car means turning left or right side (like real car steering feature). And rear side motor is used for driving the car in forward and backward direction. A Bluetooth of Raspberry is used to receive command wirelessly from android phone to control the car.



You can use any toy car which has two DC Motors to rotate front and Rear Wheels.


Circuit Diagram and Explanation:

In this Remote Controlled Car, we only need to connect Raspberry Pi with two motors using L293D module. For powering the Raspberry Pi and car we have used a mobile power bank. The mobile power bank is enough to power the Raspberry Pi and car’s motors but when we put power bank over car then due to the heavy weight of mobile power bank car would not be able to move properly. So we recommend to use the low weight power supply or Lithium batteries for powering the system. All the connections are shown in circuit diagram below. Also check our Robotics section to learn more about controlling Motors with different technologies.

Note: do not put more than 5v to the raspberry pi.


  • Content Is Not Available

 
 
 

Comments


1000+ Online here world wide

bottom of page