本帖最后由 molun 于 2023-12-12 11:00 编辑
#申请原创# @21小跑堂 21ic项目外包平台DIY大赛——蓝牙智能小车DIY
成品展示
前言
说起玩具车,没有哪一个“男孩子”是可以拒绝的,即便是像我这样初为人父,400多个月的“大男孩”,也希望拥有一辆自己DIY的玩具小车。
恰逢21ic论坛项目外包举办DIY大赛,有幸中签,希望我对电子DIY的热爱可以延续到我的一对双胞胎宝宝,激起他们将来对电子技术的热爱,将来成为这个行业当中的一员!
遥控玩具小车,已经有很多人做过了,在网络上搜索,可以找到很多教程展示,有基于51单片机、STM32单片机、ESP32、Arduino UNO为主控的小车项目;有基于蓝牙、WIFI、4G、红外遥控、语音控制等多种控制形式;有使用双电机双轮、双电机双轮+万向轮、四电机四轮的版本,甚至独轮平衡的版本;根据使用车轮的不同、驱动芯片的不同,车体框架的不同,有各种形态,发挥你的动手能力,可以基于开源项目打造出自己独一无二的遥控小车。
开箱
本次我们拿到是基于51单片机STC89C52RC和“HC-05”蓝牙模块,车体材质为FR-4电路板。
该套件某宝有售,清单如下:
准备工作
我这里准备有正点原子T65电烙铁、100W Type-C笔记本电源(为T65供电)、镊子两把、焊锡丝(材料包中也有)、高温海绵、硅胶垫、指甲刀(剪去插件多余引脚)、螺丝刀,辅助工具:手机支架、充电宝、LED灯。PWLINK2烧录器、CH340 USB转串口工具。
首先拆分电路板上的扩展版,掰下来即可,多余的部分可以使用水口钳剪去,我手头没拿,使用镊子加紧,掰掉多余部分。
所有扩展板拆分完毕后,可以进入焊接环节。
焊接
高温海绵泡水湿润,电烙铁预热。
T65小巧便携,出门就随身带着,使用RedmiBook Pro 15笔记本电源供电,升温迅速。
根据PCB上的丝印对元器件进行焊接。
需要注意IN5822二极管、电解电容、以及二极管的极性。
焊接完毕这些后先可以进行组装,使用铜柱、螺丝、螺母、扩展片把电池盒、电机、车轮、万向轮、电流表组装到车架上。
电池盒使用2颗平头螺丝固定。
两个电机接线焊接一致即可。(如图正极在左,负极在右)
镊子夹住螺母,方便上紧螺丝。
我第一次焊接专门焊接接线端子相反,看资料焊接一致更好,因为涉及参考程序,建议新手如此。
没拿水口钳,心疼坏我了,怕把我的指甲钳剪坏,还好,小米9.9的指甲钳扛住了所有。
所有零件焊接完成展示
焊接喇叭和LED刚开始有点蒙住了,找了找原理图,焊接就有方向了。
原理图
这里L293D电路部分功能等同于L298N驱动模块
9012 NPN型三极管驱动喇叭和LED,需要注意区分引脚第一脚,平面朝向自己,左边为第一脚,即集电极C。(B代表基极,C代表集电极,E代表发射极)
根据原理图所示,喇叭正极接5V,负极接9012第一脚,9012第三脚接GND,第二脚与电阻连接。电阻另一端与排针连接,方便使用杜邦线与51最小系统板连接。
4只LED灯并联,正极接入5V,负极连接9012第一脚,9012第三脚接GND,第二脚与电阻连接。电阻另一端与排针连接。蓝牙模块只需要把6针排母、4针排针焊接到洞洞板,4个排针分别与中间的排母针连接即可。
至此,电路焊接完成。这里建议洞洞板区域连接可以使用原件引脚做跳线,容易焊接,只靠焊锡连接2.54的焊接孔,不仅浪费焊锡丝也需要很高的技巧。
电路连接
根据原理图,使用杜邦线把最小系统板与各端口连接起来。
IN1连接P1.2;
IN2连接P1.3;
IN3连接P1.6;
IN4连接P1.7;
EN1连接P1.4;
EN2连接P1.5;
蜂鸣器连接P2.3;
LED连接 P2.7;
HC-05 TXD连接 P3.0(RXD);
HC-05 RXD连接 P3.1(TXD);
代码
51 Bluetooth car.c
#include <string.h>
#include "reg51.h" //包含51系统头文件
#include "bst_car.h" //包含bst_car.h智能小车头文件
unsigned char pwm_val_left = 0; //变量定义
unsigned char pwm_val_right = 0;
unsigned char push_val_left ; //左轮占空比N/20 //速度调节变量 0-20 0最小,20最大
unsigned char push_val_right ; //右轮占空比N/20
bit Right_PWM_ON = 1; //右轮PWM开关
bit Left_PWM_ON = 1; //左轮PWM开关
bit startBit = 0; //串口接收开始标志位
bit newLineReceived = 0; //串口一帧协议包接收完成
unsigned char control=0X03; //车运动控制全局变量
unsigned char inputString[50]; //接收数据协议
/*小车运行状态枚举*/
enum{
enSTOP = 0,
enRUN,
enBACK,
enLEFT,
enRIGHT
}enCarState;
#define enMinMin() {push_val_left =20;push_val_right =20;}
#define enMin() {push_val_left =24;push_val_right =24;}
#define enMidle() {push_val_left =28;push_val_right =28;}
#define enMax() {push_val_left =32;push_val_right =32;}
#define run_car '1'//按键前
#define back_car '2'//按键后
#define left_car '3'//按键左
#define right_car '4'//按键右
#define stop_car '0'//按键停
int g_volume = 0;
int g_carstate = 0;
char returntemp[] = "$0,0,0,0,0,0,0,0,0,0,0,0,0#";
//延时函数
void delay(unsigned int xms)
{
unsigned int i,j;
for(i=xms;i>0;i--) //i=xms即延时约xms毫秒
for(j=112;j>0;j--);
}
//前进
void run(void)
{
Left_moto_go; //左轮前进
Right_moto_go; //右轮前进
}
//左转
void leftrun(void)
{
Right_moto_go; //右轮前进
Left_moto_Stop; //左轮停止
}
//右转
void rightrun(void)
{
Left_moto_go; //左轮前进
Right_moto_Stop; //右轮停止
}
//后退
void back(void)
{
Left_moto_back; //左轮后退
Right_moto_back; //右轮后退
}
//停转
void stop(void)
{
Left_moto_Stop; //左轮停转
Right_moto_Stop; //右轮停转
}
//左旋转
void tleft(void)
{
Left_moto_back; //左轮后退
Right_moto_go; //右轮前进
}
//右旋转
void tright(void)
{
Left_moto_go ; //左轮前进
Right_moto_back ; //右轮后退
}
//PWM调制电机转速
/************************************************************************/
/* 左轮调速 */
/*调节push_val_left的值改变左电机转速,占空比*/
void pwm_out_left_moto(void)
{
if(Left_PWM_ON)
{
if(pwm_val_left<=push_val_left)
{
EN1=1;
}
else
{
EN1=0;
}
if(pwm_val_left>=32)
pwm_val_left=0;
}
else
{
EN1=0; //若未开启PWM则EN1=0 左轮 停止
}
}
/************************************************************************/
/* 右轮调速 */
/*调节push_val_right的值改变右电机转速,占空比*/
void pwm_out_right_moto(void)
{
if(Right_PWM_ON)
{
if(pwm_val_right<=push_val_right) //20ms内电平信号 111 111 0000 0000 0000 00
{
EN2=1; //占空比6:20
}
else
{
EN2=0;
}
if(pwm_val_right>=32)
pwm_val_right=0;
}
else
{
EN2=0; //若未开启PWM则EN2=0 右轮 停止
}
}
//TIMER0中断服务子函数产生PWM信号
void timer0()interrupt 1 using 2
{
TH0=0XFC; //1Ms定时
TL0=0X66;
pwm_val_left++;
pwm_val_right++;
pwm_out_left_moto();
pwm_out_right_moto();
}
void timer2() interrupt 5 //定时器2
{
TF2 = 0;
TH2 = 0; //1Ms定时
TL2 = 0;
}
/******************************************************************/
/* 串口中断程序*/
/******************************************************************/
void UART_SER () interrupt 4
{
unsigned char n; //定义临时变量
static int num = 0;
if(RI) //判断是接收中断产生
{
RI = 0; //标志位清零
n = SBUF; //读入缓冲区的值
//control=n;
if(n == '[backcolor=rgb(247, 247, 247)]reg51.h
[code]#ifndef __STC89C5xRC_RDP_H__
#define __STC89C5xRC_RDP_H__
/////////////////////////////////////////////////
/* The following is STC additional SFR */
/* sfr AUXR = 0x8e; */
/* sfr AUXR1 = 0xa2; */
/* sfr IPH = 0xb7; */
sfr P4 = 0xe8;
sbit P46 = P4^6;
sbit P45 = P4^5; //ISP下载需勾选"ALE脚用作P4.5口"
sbit P44 = P4^4;
sbit P43 = P4^3;
sbit P42 = P4^2;
sbit P41 = P4^1;
sbit P40 = P4^0;
sfr XICON = 0xc0;
sfr WDT_CONTR = 0xe1;
sfr ISP_DATA = 0xe2;
sfr ISP_ADDRH = 0xe3;
sfr ISP_ADDRL = 0xe4;
sfr ISP_CMD = 0xe5;
sfr ISP_TRIG = 0xe6;
sfr ISP_CONTR = 0xe7;
/* Above is STC additional SFR */
/*--------------------------------------------------------------------------
REG51F.H
Header file for 8xC31/51, 80C51Fx, 80C51Rx+
Copyright (c) 1988-1999 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
Modification according to DataSheet from April 1999
- SFR's AUXR and AUXR1 added for 80C51Rx+ derivatives
--------------------------------------------------------------------------*/
/* BYTE Registers */
sfr P0 = 0x80;
sbit P00 = P0^0;
sbit P01 = P0^1;
sbit P02 = P0^2;
sbit P03 = P0^3;
sbit P04 = P0^4;
sbit P05 = P0^5;
sbit P06 = P0^6;
sbit P07 = P0^7;
sfr P1 = 0x90;
sbit P10 = P1^0;
sbit P11 = P1^1;
sbit P12 = P1^2;
sbit P13 = P1^3;
sbit P14 = P1^4;
sbit P15 = P1^5;
sbit P16 = P1^6;
sbit P17 = P1^7;
sfr P2 = 0xA0;
sbit P20 = P2^0;
sbit P21 = P2^1;
sbit P22 = P2^2;
sbit P23 = P2^3;
sbit P24 = P2^4;
sbit P25 = P2^5;
sbit P26 = P2^6;
sbit P27 = P2^7;
sfr P3 = 0xB0;
sbit P30 = P3^0;
sbit P31 = P3^1;
sbit P32 = P3^2;
sbit P33 = P3^3;
sbit P34 = P3^4;
sbit P35 = P3^5;
sbit P36 = P3^6;
sbit P37 = P3^7;
sfr PSW = 0xD0;
sfr ACC = 0xE0;
sfr B = 0xF0;
sfr SP = 0x81;
sfr DPL = 0x82;
sfr DPH = 0x83;
sfr PCON = 0x87;
sfr TCON = 0x88;
sfr TMOD = 0x89;
sfr TL0 = 0x8A;
sfr TL1 = 0x8B;
sfr TH0 = 0x8C;
sfr TH1 = 0x8D;
sfr IE = 0xA8;
sfr IP = 0xB8;
sfr SCON = 0x98;
sfr SBUF = 0x99;
/* 80C51Fx/Rx Extensions */
sfr AUXR = 0x8E;
sfr AUXR1 = 0xA2;
sfr SADDR = 0xA9;
sfr IPH = 0xB7;
sfr SADEN = 0xB9;
sfr T2CON = 0xC8;
sfr T2MOD = 0xC9;
sfr RCAP2L = 0xCA;
sfr RCAP2H = 0xCB;
sfr TL2 = 0xCC;
sfr TH2 = 0xCD;
/* PCA SFR
sfr CCON = 0xD8;
sfr CMOD = 0xD9;
sfr CCAPM0 = 0xDA;
sfr CCAPM1 = 0xDB;
sfr CCAPM2 = 0xDC;
sfr CCAPM3 = 0xDD;
sfr CCAPM4 = 0xDE;
sfr CL = 0xE9;
sfr CCAP0L = 0xEA;
sfr CCAP1L = 0xEB;
sfr CCAP2L = 0xEC;
sfr CCAP3L = 0xED;
sfr CCAP4L = 0xEE;
sfr CH = 0xF9;
sfr CCAP0H = 0xFA;
sfr CCAP1H = 0xFB;
sfr CCAP2H = 0xFC;
sfr CCAP3H = 0xFD;
sfr CCAP4H = 0xFE;
*/
/* BIT Registers */
/* PSW */
sbit CY = PSW^7;
sbit AC = PSW^6;
sbit F0 = PSW^5;
sbit RS1 = PSW^4;
sbit RS0 = PSW^3;
sbit OV = PSW^2;
sbit F1 = PSW^1;
sbit P = PSW^0;
/* TCON */
sbit TF1 = TCON^7;
sbit TR1 = TCON^6;
sbit TF0 = TCON^5;
sbit TR0 = TCON^4;
sbit IE1 = TCON^3;
sbit IT1 = TCON^2;
sbit IE0 = TCON^1;
sbit IT0 = TCON^0;
/* IE */
sbit EA = IE^7;
sbit EC = IE^6;
sbit ET2 = IE^5;
sbit ES = IE^4;
sbit ET1 = IE^3;
sbit EX1 = IE^2;
sbit ET0 = IE^1;
sbit EX0 = IE^0;
/* IP */
/* sbit PPC = IP^6;*/
sbit PT2 = IP^5;
sbit PS = IP^4;
sbit PT1 = IP^3;
sbit PX1 = IP^2;
sbit PT0 = IP^1;
sbit PX0 = IP^0;
/* P3 */
sbit RD = P3^7;
sbit WR = P3^6;
sbit T1 = P3^5;
sbit T0 = P3^4;
sbit INT1 = P3^3;
sbit INT0 = P3^2;
sbit TXD = P3^1;
sbit RXD = P3^0;
/* SCON */
sbit SM0 = SCON^7; // alternatively "FE"
sbit FE = SCON^7;
sbit SM1 = SCON^6;
sbit SM2 = SCON^5;
sbit REN = SCON^4;
sbit TB8 = SCON^3;
sbit RB8 = SCON^2;
sbit TI = SCON^1;
sbit RI = SCON^0;
/* P1 */
/* PCA
sbit CEX4 = P1^7;
sbit CEX3 = P1^6;
sbit CEX2 = P1^5;
sbit CEX1 = P1^4;
sbit CEX0 = P1^3;
sbit ECI = P1^2;
*/
sbit T2EX = P1^1;
sbit T2 = P1^0;
/* T2CON */
sbit TF2 = T2CON^7;
sbit EXF2 = T2CON^6;
sbit RCLK = T2CON^5;
sbit TCLK = T2CON^4;
sbit EXEN2 = T2CON^3;
sbit TR2 = T2CON^2;
sbit C_T2 = T2CON^1;
sbit CP_RL2= T2CON^0;
/* CCON */
/* PCA
sbit CF = CCON^7;
sbit CR = CCON^6;
sbit CCF4 = CCON^4;
sbit CCF3 = CCON^3;
sbit CCF2 = CCON^2;
sbit CCF1 = CCON^1;
sbit CCF0 = CCON^0;
*/
/////////////////////////////////////////////////
#endif
bst_car.h
#ifndef __BSTCAR_H__
#define __BSTCAR_H__
/************51 Bluetooth car头文件*************/
//定义小车驱动输入IO口
sbit IN1=P1^2;
sbit IN2=P1^3;
sbit IN3=P1^6;
sbit IN4=P1^7;
sbit EN1=P1^4;
sbit EN2=P1^5;
//定义蜂鸣器驱动IO口
sbit FM=P2^3;
//定义车灯驱动IO口
sbit FIRE = P2^7;
#define Left_moto_go {IN1=0,IN2=1;} //左轮前进
#define Right_moto_go {IN3=1,IN4=0;} //右轮前进
#define Left_moto_back {IN1=1,IN2=0;} //左轮后退
#define Right_moto_back {IN3=0,IN4=1;} //右轮后退
#define Left_moto_Stop {IN1=0,IN2=0;} //左轮停转 //EN1=0;
#define Right_moto_Stop {IN3=0,IN4=0;} //右轮停转 //EN2=0;
#endif
reg51.h
#ifndef __STC89C5xRC_RDP_H__
#define __STC89C5xRC_RDP_H__
/////////////////////////////////////////////////
/* The following is STC additional SFR */
/* sfr AUXR = 0x8e; */
/* sfr AUXR1 = 0xa2; */
/* sfr IPH = 0xb7; */
sfr P4 = 0xe8;
sbit P46 = P4^6;
sbit P45 = P4^5; //ISP下载需勾选"ALE脚用作P4.5口"
sbit P44 = P4^4;
sbit P43 = P4^3;
sbit P42 = P4^2;
sbit P41 = P4^1;
sbit P40 = P4^0;
sfr XICON = 0xc0;
sfr WDT_CONTR = 0xe1;
sfr ISP_DATA = 0xe2;
sfr ISP_ADDRH = 0xe3;
sfr ISP_ADDRL = 0xe4;
sfr ISP_CMD = 0xe5;
sfr ISP_TRIG = 0xe6;
sfr ISP_CONTR = 0xe7;
/* Above is STC additional SFR */
/*--------------------------------------------------------------------------
REG51F.H
Header file for 8xC31/51, 80C51Fx, 80C51Rx+
Copyright (c) 1988-1999 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
Modification according to DataSheet from April 1999
- SFR's AUXR and AUXR1 added for 80C51Rx+ derivatives
--------------------------------------------------------------------------*/
/* BYTE Registers */
sfr P0 = 0x80;
sbit P00 = P0^0;
sbit P01 = P0^1;
sbit P02 = P0^2;
sbit P03 = P0^3;
sbit P04 = P0^4;
sbit P05 = P0^5;
sbit P06 = P0^6;
sbit P07 = P0^7;
sfr P1 = 0x90;
sbit P10 = P1^0;
sbit P11 = P1^1;
sbit P12 = P1^2;
sbit P13 = P1^3;
sbit P14 = P1^4;
sbit P15 = P1^5;
sbit P16 = P1^6;
sbit P17 = P1^7;
sfr P2 = 0xA0;
sbit P20 = P2^0;
sbit P21 = P2^1;
sbit P22 = P2^2;
sbit P23 = P2^3;
sbit P24 = P2^4;
sbit P25 = P2^5;
sbit P26 = P2^6;
sbit P27 = P2^7;
sfr P3 = 0xB0;
sbit P30 = P3^0;
sbit P31 = P3^1;
sbit P32 = P3^2;
sbit P33 = P3^3;
sbit P34 = P3^4;
sbit P35 = P3^5;
sbit P36 = P3^6;
sbit P37 = P3^7;
sfr PSW = 0xD0;
sfr ACC = 0xE0;
sfr B = 0xF0;
sfr SP = 0x81;
sfr DPL = 0x82;
sfr DPH = 0x83;
sfr PCON = 0x87;
sfr TCON = 0x88;
sfr TMOD = 0x89;
sfr TL0 = 0x8A;
sfr TL1 = 0x8B;
sfr TH0 = 0x8C;
sfr TH1 = 0x8D;
sfr IE = 0xA8;
sfr IP = 0xB8;
sfr SCON = 0x98;
sfr SBUF = 0x99;
/* 80C51Fx/Rx Extensions */
sfr AUXR = 0x8E;
sfr AUXR1 = 0xA2;
sfr SADDR = 0xA9;
sfr IPH = 0xB7;
sfr SADEN = 0xB9;
sfr T2CON = 0xC8;
sfr T2MOD = 0xC9;
sfr RCAP2L = 0xCA;
sfr RCAP2H = 0xCB;
sfr TL2 = 0xCC;
sfr TH2 = 0xCD;
/* PCA SFR
sfr CCON = 0xD8;
sfr CMOD = 0xD9;
sfr CCAPM0 = 0xDA;
sfr CCAPM1 = 0xDB;
sfr CCAPM2 = 0xDC;
sfr CCAPM3 = 0xDD;
sfr CCAPM4 = 0xDE;
sfr CL = 0xE9;
sfr CCAP0L = 0xEA;
sfr CCAP1L = 0xEB;
sfr CCAP2L = 0xEC;
sfr CCAP3L = 0xED;
sfr CCAP4L = 0xEE;
sfr CH = 0xF9;
sfr CCAP0H = 0xFA;
sfr CCAP1H = 0xFB;
sfr CCAP2H = 0xFC;
sfr CCAP3H = 0xFD;
sfr CCAP4H = 0xFE;
*/
/* BIT Registers */
/* PSW */
sbit CY = PSW^7;
sbit AC = PSW^6;
sbit F0 = PSW^5;
sbit RS1 = PSW^4;
sbit RS0 = PSW^3;
sbit OV = PSW^2;
sbit F1 = PSW^1;
sbit P = PSW^0;
/* TCON */
sbit TF1 = TCON^7;
sbit TR1 = TCON^6;
sbit TF0 = TCON^5;
sbit TR0 = TCON^4;
sbit IE1 = TCON^3;
sbit IT1 = TCON^2;
sbit IE0 = TCON^1;
sbit IT0 = TCON^0;
/* IE */
sbit EA = IE^7;
sbit EC = IE^6;
sbit ET2 = IE^5;
sbit ES = IE^4;
sbit ET1 = IE^3;
sbit EX1 = IE^2;
sbit ET0 = IE^1;
sbit EX0 = IE^0;
/* IP */
/* sbit PPC = IP^6;*/
sbit PT2 = IP^5;
sbit PS = IP^4;
sbit PT1 = IP^3;
sbit PX1 = IP^2;
sbit PT0 = IP^1;
sbit PX0 = IP^0;
/* P3 */
sbit RD = P3^7;
sbit WR = P3^6;
sbit T1 = P3^5;
sbit T0 = P3^4;
sbit INT1 = P3^3;
sbit INT0 = P3^2;
sbit TXD = P3^1;
sbit RXD = P3^0;
/* SCON */
sbit SM0 = SCON^7; // alternatively "FE"
sbit FE = SCON^7;
sbit SM1 = SCON^6;
sbit SM2 = SCON^5;
sbit REN = SCON^4;
sbit TB8 = SCON^3;
sbit RB8 = SCON^2;
sbit TI = SCON^1;
sbit RI = SCON^0;
/* P1 */
/* PCA
sbit CEX4 = P1^7;
sbit CEX3 = P1^6;
sbit CEX2 = P1^5;
sbit CEX1 = P1^4;
sbit CEX0 = P1^3;
sbit ECI = P1^2;
*/
sbit T2EX = P1^1;
sbit T2 = P1^0;
/* T2CON */
sbit TF2 = T2CON^7;
sbit EXF2 = T2CON^6;
sbit RCLK = T2CON^5;
sbit TCLK = T2CON^4;
sbit EXEN2 = T2CON^3;
sbit TR2 = T2CON^2;
sbit C_T2 = T2CON^1;
sbit CP_RL2= T2CON^0;
/* CCON */
/* PCA
sbit CF = CCON^7;
sbit CR = CCON^6;
sbit CCF4 = CCON^4;
sbit CCF3 = CCON^3;
sbit CCF2 = CCON^2;
sbit CCF1 = CCON^1;
sbit CCF0 = CCON^0;
*/
/////////////////////////////////////////////////
#endif
以上代码基于开源代码修改,另外可以借助AI编写代码,对于基础比较薄弱的爱好者来说非常利好。
通过通译灵码还可以对代码进行分析注释,甚至生成测试程序
代码编译
代码的编译需要使用到keil,需要下载MDK-ARM,C51,C251。下载地址:https://www.keil.com/download/product/烧录固件需要使用STC-ISP工具,下载地址:https://www.stcai.com/gjrj
固件烧录
这里需要注意,串口工具TX、RX分别连接最小系统RXD、TXD,将串口工具插入电脑,打开STC-ISP工具后,选择芯片型号为STC89C52RC,扫描串口,选择你串口工具的COM端口,点击打开程序文件,选择使用keil进行编译之后生成的.hex格式固件,点击 下载/编程 按钮,同时把串口工具GND VCC插到最小系统板上,操作无误的话,程序会烧录进单片机,程序操作日志中有提示烧录完成。
我第一次使用51单片机,这一步折腾过很多次,更换了2个串口工具,究其然是需要掌握正确的烧录步骤。
遥控体验
小车遥控可以通过上面这两个软件,蓝牙小车APP或者HC蓝牙助手
蓝牙小车软件是别人开源的,搜索蓝牙模块信号,输入配对码1234进行连接,连接成功即可进行操作
HC蓝牙助手是汇承科技开发的调试工具,搜素到HC-05后进行连接
可以对按钮进行设置,这里有方向按钮和按钮组
设置按钮名称和发送的值(代码中定义的值)
设置完毕后关闭该按钮即可进行调试
同理设置其他按钮
还可以在通信界面发送其他值进行调试控制
关于供电
电路设计是需要2颗18650电池进行串联供电,手头只有自己为随身WIFI棒子DIY的电源,只能提供5V输出,接入系统后电机勉强能动一下
后来细看原理图,L293D是需要2组电压供电的,考虑到L7805还是比较耐压的,于是把TP路由器的电源接入小车,9V 600mA输出,恰好可以正常工作。
关于拓展
后续可以加入家中吃灰的超声波模块、红外避障模块等,对小车功能做进一步增强,当然也可以使用ESP-32、安信可Ai-M61-32S开发板、甚至合宙Air780E、移远EC600S开发板替代51最小系统作为主控,学习尝试WIFI、4G控制的小车,实现ESP32-CAM摄像头图传、GPS定位等功能。
鸣谢
感谢21ic项目外包平台提供的此次DIY机会,最后在晒晒我的娃,希望他们将来也能够爱上电子技术,能够成为从业者,为我们国家的信息与电子产业添砖加瓦!
蓝牙小车.zip
(41.24 KB)
HCbluetooth.zip
(3.21 MB)
蓝牙小车APP.zip
(385.56 KB)
|