Bluetooth Controlled Car Using 8051
by hobby electronics in Circuits > Microcontrollers
1599 Views, 0 Favorites, 0 Comments
Bluetooth Controlled Car Using 8051
![IMG_20221009_224211.jpg](/proxy/?url=https://content.instructables.com/FFK/E258/L91CXTYM/FFKE258L91CXTYM.jpg&filename=IMG_20221009_224211.jpg)
It’s a frolicking experience to make new things using electronics. This is going to be my first ever instructable, in which I will ride you through a step-by-step guide on how to make a Bluetooth controlled car using an 8051 microcontroller. Well, as far as the microcontroller it sounds like a primitive approach, but I found it to be the best fit for today’s guide. Let’s get started!!
Supplies
![IMG_20221009_113846.jpg](/proxy/?url=https://content.instructables.com/FY3/ZGSI/L91CXTZL/FY3ZGSIL91CXTZL.jpg&filename=IMG_20221009_113846.jpg)
![IMG_20221009_114529.jpg](/proxy/?url=https://content.instructables.com/FBF/EXXJ/L91CXU08/FBFEXXJL91CXU08.jpg&filename=IMG_20221009_114529.jpg)
![IMG_20221009_114717.jpg](/proxy/?url=https://content.instructables.com/FNH/S24V/L91CXU0N/FNHS24VL91CXU0N.jpg&filename=IMG_20221009_114717.jpg)
![IMG_20221009_114724.jpg](/proxy/?url=https://content.instructables.com/F8U/9O82/L91CXU15/F8U9O82L91CXU15.jpg&filename=IMG_20221009_114724.jpg)
Components:
· AT89S52 microcontroller
· 40pin IC base
· HC-05 Bluetooth module
· L293D motor driver
· 16pin IC base
· Prototyping board
· Robo car chassis
· 18650 lithium-ion batteries
· 7805 voltage regulator
· 100uf capacitor
· 10uf capacitor
· 22pf capacitors
· 10k ohm resistor
· 120 ohm resistors
· 11.0592Mhz Crystal
· Red LEDs
· White LEDs
· Push button
· 2.2k ohm resistor
· 1k ohm resistor
· 6 pin Female header
· Connectors
· Connecting wires
Tools
· Soldering iron
· Solder
· Hot glue gun
· Plier
· Nuts and bolts
· Screwdriver
· Tweezer
· Wire clippers
Probing the Circuit
![Bluetooth controlled car.png](/proxy/?url=https://content.instructables.com/FZ7/PAKK/L92SC448/FZ7PAKKL92SC448.png&filename=Bluetooth controlled car.png)
A bit intuitive circuit of the robot is shown above. Let’s have a deeper look at it. The first and foremost important component is the 8051 microcontroller. The entire circuit is powered by a pack of 2 18650 batteries; voltage is regulated using 7805 voltage regulator. A 10k resistor along with a 10uf capacitor acts as bootup reset for the chip. 11.0592MHz of crystal is used to provide clock to the chip. For the sake of controlling the robocar via Bluetooth, HC-05 Bluetooth module is used. To protect the module from an input signal above the rated voltage(3.3v) from the microcontroller’s TX pin a voltage divider consisting of a 2.2k ohm resistor and a 1k ohm resistor is used. L293D will control the motors. Four LEDs(two front and two back) named F1, F2, B1, and B2 respectively are used along with 120ohm resistors. In the circuit, for convenience, the Port 2 of the microcontroller is connected with L293D and LEDs.
A Peeking Insight Into the 8051 Basics
![TMOD register.PNG](/proxy/?url=https://content.instructables.com/FLQ/OJXO/L91CXU3A/FLQOJXOL91CXU3A.png&filename=TMOD register.PNG)
![SCON register.PNG](/proxy/?url=https://content.instructables.com/F55/52AW/L91CXU3P/F5552AWL91CXU3P.png&filename=SCON register.PNG)
Before being staggered by the intricate concepts of the program, let’s first learn a bit about some important registers of 8051 featured in the program.
TMOD register
The main purpose of the TMOD register is to set different modes for the 8051 timers. The upper four bits of the register are used for timer 1 while the lower four are used for timer 0. Bits 5,4 and 1,0 are used to define different modes for their respective timers. In this project, we would use timer 1 in mode 2 to generate the baud rate for serial communication.
SCON register
As the TMOD register is used to set different modes for the timer, the SMOD register is used to set different modes for serial communication. Bit 7 and 6 are used to set different modes for Serial communication. This register also comprises of two flag bits, TI and RI which inform the microcontroller when a byte is sent or received. In the source code, we would use this bit to set mode 2 of serial communication and will also monitor the flags.
Assembling Everything Up
![F8U9O82L91CXU15.jpg](/proxy/?url=https://content.instructables.com/FFD/E4EY/L91CXUBX/FFDE4EYL91CXUBX.jpg&filename=F8U9O82L91CXU15.jpg)
![FBFEXXJL91CXU08.jpg](/proxy/?url=https://content.instructables.com/FCL/P0FP/L91CXUEB/FCLP0FPL91CXUEB.jpg&filename=FBFEXXJL91CXU08.jpg)
![IMG_20221009_123508.jpg](/proxy/?url=https://content.instructables.com/FMY/IQDR/L91CXUEZ/FMYIQDRL91CXUEZ.jpg&filename=IMG_20221009_123508.jpg)
![IMG_20221009_130128.jpg](/proxy/?url=https://content.instructables.com/FPX/WZMK/L91CXUFP/FPXWZMKL91CXUFP.jpg&filename=IMG_20221009_130128.jpg)
While the basics are out of the way, it’s time to get our hands dirty by assembling the robocar.
The first step is to assemble the car chassis. That’s fairly simple just follow the suit.
Building the Circuit Board
![IMG_20221009_211919.jpg](/proxy/?url=https://content.instructables.com/FZE/WM6D/L91CXUMV/FZEWM6DL91CXUMV.jpg&filename=IMG_20221009_211919.jpg)
![IMG_20221009_210256.jpg](/proxy/?url=https://content.instructables.com/FIP/KTON/L91CXUNV/FIPKTONL91CXUNV.jpg&filename=IMG_20221009_210256.jpg)
After the chassis is assembled the next step is to build up the main circuit board. For that I will use a prototyping (Vero) board, you could use a printed circuit board as well.
Once our circuit board is ready to rock and roll. The next step is to give a finishing touch and then program the microcontroller.
Finishing Up the Assembly
![IMG_20221009_215314.jpg](/proxy/?url=https://content.instructables.com/F18/KXAQ/L91CXUY9/F18KXAQL91CXUY9.jpg&filename=IMG_20221009_215314.jpg)
![IMG_20221009_221708.jpg](/proxy/?url=https://content.instructables.com/FGX/NA16/L91CXUZG/FGXNA16L91CXUZG.jpg&filename=IMG_20221009_221708.jpg)
Last but not least we will give a finishing touch to the robocar, to make it look a bit majestic and charismatic. By installing the 18650 battery holder and the front and back LEDs, the car is ready to elicit and reveal its qualities.
The Program
![Program 1.PNG](/proxy/?url=https://content.instructables.com/FWE/13EY/L91CXWJV/FWE13EYL91CXWJV.png&filename=Program 1.PNG)
![Program 2.PNG](/proxy/?url=https://content.instructables.com/FJ6/B0V9/L91CXWKS/FJ6B0V9L91CXWKS.png&filename=Program 2.PNG)
![Program 3.PNG](/proxy/?url=https://content.instructables.com/FSQ/E3MK/L91CXWLS/FSQE3MKL91CXWLS.png&filename=Program 3.PNG)
![Program 4.PNG](/proxy/?url=https://content.instructables.com/FHZ/01B5/L91CXWMT/FHZ01B5L91CXWMT.png&filename=Program 4.PNG)
The first section is pretty straightforward. First, we would include the 8051 register configuration file containing all definitions and the addresses of the 8051 registers. Then, we would define Port 2 pins as Left motor, Right motor, and Front and back LED pins respectively. The variable char rx_data and rx_char are used to store data received from the HC-05 Bluetooth module. The prototypes of the different functions going to be used in the program are also given at the top.
The main section of the program begins with initializing the Bluetooth Serial communication and setting the default states of different pins. Notice that LEDs states are set by default 1, the reason is that by virtue of the restraint output current of the 8051 chip, the LEDs’ negative terminals are connected with the chip. So, the LEDs would turn on by making the respective pins zero. Ultimately, they will receive maximum current and will glow at full brightness. Inside the while loop, the characters received by the microcontroller from HC-05 are copied into the rx_char variable, which is then checked one by one to perform respective operations. For instance, if the received character is ‘F’ then the microcontroller will make the Left motor and the right motor first pins high and the robocar will move forward.
In the Serial_init function, the TMOD register is used to set mode 2 for timer 1 to generate a baud rate of 9600 bps. SCON register is used to set mode 2 for serial communication and also enabling the REN (Reception enable bit) to make Serial reception available. Timer 1 is then started to generate the baud rate.
The Serial_print function is used to send a string of characters to HC-05, Serial_send function sends characters to HC-05. Before sending the character through Serial lines, it is first stored in the Serial Buffer register(temporary storage for sent and received bytes). The buffer register stores the data which is then dispatched via Serial lines. After being dispatched, the TI flag of SCON is set, which is cleared afterward for future Transmission.
In a contrary case for the Serial_read function, after data is received from the module it is again temporarily stored in the Buffer register, while the RI flag is set. This data is then copied from the buffer register to the rx_data variable which is then utilized in the main function as described above.
The delay_ms function is used to generate delay in milliseconds using the software instruction time rate method. For more information surf for software delay in the 8051 microcontroller.
Programming the Microcontroller
![Capture.PNG](/proxy/?url=https://content.instructables.com/FWG/IIRT/L92SC4JF/FWGIIRTL92SC4JF.png&filename=Capture.PNG)
![Software 1.PNG](/proxy/?url=https://content.instructables.com/FPR/TDNZ/L91CXXEN/FPRTDNZL91CXXEN.png&filename=Software 1.PNG)
![IMG_20221009_212051.jpg](/proxy/?url=https://content.instructables.com/F31/JH38/L91CXXJ3/F31JH38L91CXXJ3.jpg&filename=IMG_20221009_212051.jpg)
I have used Keil to write the C code for the project and also for the hex file. The hex file is burnt into the chip using progisp and usbasp programmer.
The App
![Screenshot_2022-10-10-00-51-42.png](/proxy/?url=https://content.instructables.com/FRJ/035H/L91CXXKF/FRJ035HL91CXXKF.png&filename=Screenshot_2022-10-10-00-51-42.png)
For controlling the car, I am using the Bluetooth RC car app on my android phone. You can download it from here Bluetooth RC Car - Apps on Google Play.
Finish Up
![IMG_20221009_224129.jpg](/proxy/?url=https://content.instructables.com/F87/M15M/L91CXXT3/F87M15ML91CXXT3.jpg&filename=IMG_20221009_224129.jpg)
That’s all from today. I hope you liked my instructable. For any queries and quests, you can ask me. I would love to help you. Thanks again. You Rock!!