Bilibili project display video: https://www.bilibili.com/video/BV1Wy4y1z7a5
csdn data link: https://download.csdn.net/download/mbs520/13124051
Baidu network disk data link: https://pan.baidu.com/s/1p93c_CG3TJvcAXAENR_X0g
extraction code: dwe2
Remember to like it if you take it away!
Baidu Cloud Disk Download Center:
1. Material preparation
1. Motor selection
Name: Hall Code Motor
Model: 620 to 12V
You can use a DC motor here. This is expensive. Search for DC gear motors on the Internet. It is best to bring a wheel for easy installation.
2. The frame of the trolley. The
blogger saw the wood
directly or bought the chassis of the smart trolley.
3. Main control chip selection
Name: STC89C52 single-chip microcomputer minimum system board
Purchase link: https://m.tb.cn/h.43JCfUl?sm=0792c6
4. Motor drive
Name: LN298
features: large drive current, stable work, that is, more electricity
5. Power Supply
Name: 18650 Lithium Battery
Features: relatively cheap, relatively common
Voltage: 3.7V
(mine is a dismantled power bank, which is ugly)
6. Bluetooth module
Name: HC-05
Features: can connect to mobile phones
2. Circuit principle
Circuit diagram (please download the information if you can’t see clearly)
Note: The +12V pin of the 298 is input, and the +5V pin is 5V output
.
Connect according to the picture
Three, source code
/*******************************************
名称:51蓝牙小车
作者:化作尘
时间:2020年11月18日21:36:47
*******************************************/
#include "reg52.h"
#define uchar unsigned char
#define uint unsigned char
/***小车控制定义**/
#define DIR P1
#define QIAN 0xaa
#define HOU 0x55
#define ZUO 0x5a
#define YOU 0xa5
#define STOP 0x00
void uart_init();
void uart_tx_string(uchar *str);
void uart_tx_byte(uchar str);
void Delayms(unsigned int n);
uchar rec;
/*********************************************************
函数名:主函数
*********************************************************/
void main()
{
uart_init();
DIR = STOP;
Delayms(1);
uart_tx_string("hello buletooch car!\n");
while(1)
{
switch(rec)
{
case 1:DIR = QIAN; break;
case 2:DIR = HOU; break;
case 3:DIR = ZUO; break;
case 4:DIR = YOU; break;
case 5:DIR = STOP; break;
}
}
}
/*********************************************************
函数名:串口中断
*********************************************************/
void uart_timer() interrupt 4
{
if(RI)
{
RI=0;
rec=SBUF;
uart_tx_byte('&');
Delayms(2);
uart_tx_byte(rec);
Delayms(2);
uart_tx_byte('&');
}
}
/*********************************************************
函数名:串口初始化
波特率:9600
晶振:11.059M
*********************************************************/
void uart_init()
{
TMOD=TMOD&0x0F;
TMOD=0x20;
TH1=0xFD;
TL1=0xFD;
TR1=1;
SCON=SCON&0x0F;
SCON=0x50;
EA=1;
ES=1;
}
/*********************************************************
函数名:串口发送一个字节
*********************************************************/
void uart_tx_byte(uchar str)
{
SBUF=str;
while(!TI);
}
/*********************************************************
函数名:串口发送一个字符串
*********************************************************/
void uart_tx_string(uchar *str)
{
while(*str!='\0')
{
uart_tx_byte(*str++);
Delayms(2);
}
}
/*********************************************************
函数名:延时函数
*********************************************************/
void Delayms(unsigned int n)
{
unsigned int i,j;
for(j=n;j>0;j--)
for(i=112;i>0;i--);
}
Four, debugging
1. HC-05 Bluetooth module debugging The
default baud rate of HC-05 is 9600. If it is not 9600, modify the method.
Use the serial port assistant to connect the computer to the module, connect to the baud rate of 38400, press the small button to enter the AT mode before powering on the module.
Modify the baud rate command: AT+UART=9600,0,0
2. Bluetooth serial port app
Open the bluetooth serial port app in the data or search the "Bluetooth serial port" directly in the application store to download.
How to use:
1) Keyboard -> open editing mode -> click on the keyboard to start editing
2) Set according to the following figure:
3) Connect Bluetooth and start testing
The test may have errors in the positive and negative directions, just change the code or wiring.
Bluetooth car video: https://www.bilibili.com/video/BV1Wy4y1z7a5