文章目录[隐藏]
4G智能无人车按下前进松手即停和转弯调速的方案代码
1代码在底部 代码在底部 代码在底部 代码在底部1
在5G开始普及的今天,各种设备已经面向数字化,今天我们一起学习DIY一款4G智能无人车
硬件准备:
1.芯片模块:ESP8266—12E(带CH340G的USB转TTL模块)
2.L298N电机驱动
3.12V电池组(可以使用18650电池,建议6个)
4.电压指示模块
5.DIY小车
原理:ESP8266连接L298N驱动,驱动连接马达,ESP8266发出PWM波控制马达转动,调整转动方向等
DIY的第一步:组装无人车
以上为实物图
DIY的第二步:烧录MQTT固件
步骤1:登录安信可官方网站,找到软件下载,找到MQTT固件进行下载,同时下载FLASH软件,烧录固件的
(也可以联系我要最新,QQ1406678649)
FLASH
固件
步骤2:打开flash_download_tool_3.9.2.exe
点击OK
这里一定要选择正确
然后点击左下角START进行上传
完成后,就可以了哦,固件完成
DIY的第三步:烧录代码
代码可以分为两种,
第一种,直接烧录WIFI账户和密码,选择你即将给小车连接的WIFI即可,烧录完整代码后,开机,ESP8266模块将自动连接。下面展示部分连接代码形式:
/*技术支持QQ:1406678649 ******************技术微信:RanBaiWan1688****************/
/**需要商业合作请联系我************************************************************/
/**以下4G智能小车代码可以前进调速*转弯调速***如果想在全国任意位置控制小车*需要更换固件*需要固件请联系我*/
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
//#define BLINKER_ESP_SMARTCONFIG//
#include <Blinker.h>
char auth[] = "92acbbb5aff";//填写你电灯科技的密钥
char ssid[] = "c2580";//你WIFI的名称
char pswd[] = "ran7758258";//你WIFI的密码
第二种:一键配网方式
就是开机后,ESP8266自己发出WIFI,手机连接后,有弹窗强制进入网页,让用户填写WIFI名称、密码、点灯科技密钥,配置完成后,此时ESP8266自动关闭WIFI,之后主动连接你指定的WIFI。
部分代码展示
const char* AP_NAME = "4G智能小车";//wifi名字
//暂时存储wifi账号密码
char sta_ssid[32] = {0};
char sta_password[64] = {0};
//配网页面代码
const char* page_html = "\
<!DOCTYPE html>\r\n\
<html lang='en'>\r\n\
<head>\r\n\
<meta charset='UTF-8'>\r\n\
<meta name='viewport' content='width=device-width, initial-scale=1.0'>\r\n\
<title>Document</title>\r\n\
</head>\r\n\
<body>\r\n\
<form name='input' action='/' method='POST'>\r\n\
4G智能小车wifi名称: <br>\r\n\
<input type='text' name='ssid'><br>\r\n\
4G智能小车wifi密码:<br>\r\n\
<input type='text' name='password'><br>\r\n\
点灯科技密钥:<br>\r\n\
<input type='text' name='key'><br>\r\n\
<input type='submit' value='保存'>\r\n\
</form>\r\n\
</body>\r\n\
</html>\r\n\
";
此代码涉及商用,公开会扰乱市场,需要的私聊QQ:1406678649
完整的第一份代码:按下后一直前进,再次按下前进会停止
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
//#define BLINKER_ESP_SMARTCONFIG//
#include <Blinker.h>
char auth[] = "92acbbb54aff";
char ssid[] = "c2851";
char pswd[] = "12345678";
#define BUTTON_1 "b1"
#define BUTTON_2 "b2"
#define BUTTON_3 "b3"
#define BUTTON_4 "b4"
#define BUTTON_5 "b5"
#define BUTTON_6 "b6"
#define BUTTON_7 "b7"
#define BUTTON_8 "b8"
#define BUTTON_9 "b9"
#define slider_0 "r1"
#define slider_1 "r2"
BlinkerButton Button1(BUTTON_1);
BlinkerButton Button2(BUTTON_2);
BlinkerButton Button3(BUTTON_3);
BlinkerButton Button4(BUTTON_4);
BlinkerButton Button5(BUTTON_5);
BlinkerButton Button6(BUTTON_6);
BlinkerButton Button7(BUTTON_7);
BlinkerButton Button8(BUTTON_8);
BlinkerButton Button9(BUTTON_9);
BlinkerSlider Slider0(slider_0);
BlinkerSlider Slider1(slider_1);
int pwm1=60;
int pwm2=60;
int flag;//判断当前状态
void button1_callback(const String &state)
{
digitalWrite(12, LOW);
}
void button2_callback(const String &state)//前进
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
flag=1;
analogWrite(16, pwm1);
digitalWrite(5, LOW);
analogWrite(4, pwm2);
digitalWrite(2, LOW);
}
}
void button3_callback(const String &state) //垃圾袋开
{
digitalWrite(13, LOW);
}
void button4_callback(const String &state)//左转
{
digitalWrite(16, LOW);
analogWrite(5, pwm1);
analogWrite(4, pwm2);
digitalWrite(2, LOW);
flag=3;
}
void button5_callback(const String &state)//停止
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
flag=5;
}
}
void button6_callback(const String &state)//右转
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
analogWrite(16, pwm1);
digitalWrite(5,LOW);
digitalWrite(4, LOW);
analogWrite(2,pwm2);
flag=4;
}
}
void button7_callback(const String &state)//毛刷关
{
digitalWrite(12, HIGH);
}
void button8_callback(const String &state)//后退
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
digitalWrite(16, LOW);
analogWrite(5,pwm1);
digitalWrite(4, LOW);
analogWrite(2,pwm2);
flag=2;
}
}
void button9_callback(const String &state)//垃圾袋关
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
digitalWrite(13, HIGH);
}
}
void slider0_callback(int32_t value)
{
BLINKER_LOG("slider:", value);
pwm1=value;
switch(flag)
{
case 1: analogWrite(16, pwm1); break;
case 2: analogWrite(5, pwm1); break;
case 3: analogWrite(5, pwm1); break;
case 4: analogWrite(16, pwm1); break;
case 5: break;
default:break;
}
}
void slider1_callback(int32_t value)
{
BLINKER_LOG("slider:", value);
pwm2=value;
switch(flag)
{
case 1: analogWrite(4, pwm2); break;
case 2: analogWrite(2, pwm2); break;
case 3: analogWrite(2, pwm2); break;
case 4: analogWrite(4, pwm2); break;
case 5: break;
default:break;
}
}
//blinker初始化
void blinker_car_init()
{
//1-4号引脚设置为输出模式
pinMode(16, OUTPUT);//
pinMode(5, OUTPUT);//
pinMode(4, OUTPUT);//
pinMode(2, OUTPUT);//
pinMode(12, OUTPUT);//
pinMode(13, OUTPUT);//
}
void setup()
{
digitalWrite(D0, HIGH);
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D4, HIGH);
analogWriteRange(100);
analogWriteFreq(50);
//analogWrite(D2, 50);//0-100 50
//初始化小车参数
blinker_car_init();
//按钮绑定
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
Button6.attach(button6_callback);
Button7.attach(button7_callback);
Button8.attach(button8_callback);
Button9.attach(button9_callback);
Slider0.attach(slider0_callback);
Slider1.attach(slider1_callback);
Blinker.begin(auth,ssid,pswd);
// Blinker.begin(auth);
}
void loop()
{
Blinker.run();
}
第二份代码:按下后前进,松手立即停止
这个是判断语句,高手一看便知
当按下时前进,否则停止
如果你是小白,找我拿,QQ:1406678649
高手请自己复制粘贴
void button2_callback(const String &state)//forward
{
if (state == BLINKER_CMD_BUTTON_PRESSED)
{
analogWrite(16, too1);
digitalWrite(5, LOW);
analogWrite(4, too2);
digitalWrite(2, LOW);
}
else if (state == BLINKER_CMD_BUTTON_PRESSUP)
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
}
}
转弯调速的语句
在完整代码中:可以看到
BlinkerSlider Slider0(slider_0);
BlinkerSlider Slider1(slider_1);
以及
void slider0_callback(int32_t value) //too1
{
BLINKER_LOG("slider:", value);
too1=value;
switch(flag)
{
case 1: analogWrite(16, too1); break;
case 2: analogWrite(5, too1); break;
case 3: analogWrite(5, too1); break;
case 4: analogWrite(16, too1); break;
case 5: break;
default:break;
}
}
这就是前进后退的指示,
你需要添加新的PWM3和pwm4,在完整代码中复制修改即可
举例:
BlinkerSlider Slider0(slider_0);
BlinkerSlider Slider1(slider_1);
BlinkerSlider Slider2(slider_2);
BlinkerSlider Slider3(slider_3);
int too1=60;
int too2=60;
int too3=40;
int too4=40;
int flag;
t001就是PWM1波的代号,t002就是PWM2波的代号
修改后烧录即可
备注:小白可以加我要代码!!!有偿,,三十一份
如果是一键配网代码:五十一份
也可以自己慢慢学,代码都交给你们了
!!!以上代码保证可用!!!
版权声明:本文为CSDN博主「weixin_51357422」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_51357422/article/details/122664629
4G智能无人车按下前进松手即停和转弯调速的方案代码
1代码在底部 代码在底部 代码在底部 代码在底部1
在5G开始普及的今天,各种设备已经面向数字化,今天我们一起学习DIY一款4G智能无人车
硬件准备:
1.芯片模块:ESP8266—12E(带CH340G的USB转TTL模块)
2.L298N电机驱动
3.12V电池组(可以使用18650电池,建议6个)
4.电压指示模块
5.DIY小车
原理:ESP8266连接L298N驱动,驱动连接马达,ESP8266发出PWM波控制马达转动,调整转动方向等
DIY的第一步:组装无人车
以上为实物图
DIY的第二步:烧录MQTT固件
步骤1:登录安信可官方网站,找到软件下载,找到MQTT固件进行下载,同时下载FLASH软件,烧录固件的
(也可以联系我要最新,QQ1406678649)
FLASH
固件
步骤2:打开flash_download_tool_3.9.2.exe
点击OK
这里一定要选择正确
然后点击左下角START进行上传
完成后,就可以了哦,固件完成
DIY的第三步:烧录代码
代码可以分为两种,
第一种,直接烧录WIFI账户和密码,选择你即将给小车连接的WIFI即可,烧录完整代码后,开机,ESP8266模块将自动连接。下面展示部分连接代码形式:
/*技术支持QQ:1406678649 ******************技术微信:RanBaiWan1688****************/
/**需要商业合作请联系我************************************************************/
/**以下4G智能小车代码可以前进调速*转弯调速***如果想在全国任意位置控制小车*需要更换固件*需要固件请联系我*/
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
//#define BLINKER_ESP_SMARTCONFIG//
#include <Blinker.h>
char auth[] = "92acbbb5aff";//填写你电灯科技的密钥
char ssid[] = "c2580";//你WIFI的名称
char pswd[] = "ran7758258";//你WIFI的密码
第二种:一键配网方式
就是开机后,ESP8266自己发出WIFI,手机连接后,有弹窗强制进入网页,让用户填写WIFI名称、密码、点灯科技密钥,配置完成后,此时ESP8266自动关闭WIFI,之后主动连接你指定的WIFI。
部分代码展示
const char* AP_NAME = "4G智能小车";//wifi名字
//暂时存储wifi账号密码
char sta_ssid[32] = {0};
char sta_password[64] = {0};
//配网页面代码
const char* page_html = "\
<!DOCTYPE html>\r\n\
<html lang='en'>\r\n\
<head>\r\n\
<meta charset='UTF-8'>\r\n\
<meta name='viewport' content='width=device-width, initial-scale=1.0'>\r\n\
<title>Document</title>\r\n\
</head>\r\n\
<body>\r\n\
<form name='input' action='/' method='POST'>\r\n\
4G智能小车wifi名称: <br>\r\n\
<input type='text' name='ssid'><br>\r\n\
4G智能小车wifi密码:<br>\r\n\
<input type='text' name='password'><br>\r\n\
点灯科技密钥:<br>\r\n\
<input type='text' name='key'><br>\r\n\
<input type='submit' value='保存'>\r\n\
</form>\r\n\
</body>\r\n\
</html>\r\n\
";
此代码涉及商用,公开会扰乱市场,需要的私聊QQ:1406678649
完整的第一份代码:按下后一直前进,再次按下前进会停止
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
//#define BLINKER_ESP_SMARTCONFIG//
#include <Blinker.h>
char auth[] = "92acbbb54aff";
char ssid[] = "c2851";
char pswd[] = "12345678";
#define BUTTON_1 "b1"
#define BUTTON_2 "b2"
#define BUTTON_3 "b3"
#define BUTTON_4 "b4"
#define BUTTON_5 "b5"
#define BUTTON_6 "b6"
#define BUTTON_7 "b7"
#define BUTTON_8 "b8"
#define BUTTON_9 "b9"
#define slider_0 "r1"
#define slider_1 "r2"
BlinkerButton Button1(BUTTON_1);
BlinkerButton Button2(BUTTON_2);
BlinkerButton Button3(BUTTON_3);
BlinkerButton Button4(BUTTON_4);
BlinkerButton Button5(BUTTON_5);
BlinkerButton Button6(BUTTON_6);
BlinkerButton Button7(BUTTON_7);
BlinkerButton Button8(BUTTON_8);
BlinkerButton Button9(BUTTON_9);
BlinkerSlider Slider0(slider_0);
BlinkerSlider Slider1(slider_1);
int pwm1=60;
int pwm2=60;
int flag;//判断当前状态
void button1_callback(const String &state)
{
digitalWrite(12, LOW);
}
void button2_callback(const String &state)//前进
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
flag=1;
analogWrite(16, pwm1);
digitalWrite(5, LOW);
analogWrite(4, pwm2);
digitalWrite(2, LOW);
}
}
void button3_callback(const String &state) //垃圾袋开
{
digitalWrite(13, LOW);
}
void button4_callback(const String &state)//左转
{
digitalWrite(16, LOW);
analogWrite(5, pwm1);
analogWrite(4, pwm2);
digitalWrite(2, LOW);
flag=3;
}
void button5_callback(const String &state)//停止
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
flag=5;
}
}
void button6_callback(const String &state)//右转
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
analogWrite(16, pwm1);
digitalWrite(5,LOW);
digitalWrite(4, LOW);
analogWrite(2,pwm2);
flag=4;
}
}
void button7_callback(const String &state)//毛刷关
{
digitalWrite(12, HIGH);
}
void button8_callback(const String &state)//后退
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
digitalWrite(16, LOW);
analogWrite(5,pwm1);
digitalWrite(4, LOW);
analogWrite(2,pwm2);
flag=2;
}
}
void button9_callback(const String &state)//垃圾袋关
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
digitalWrite(13, HIGH);
}
}
void slider0_callback(int32_t value)
{
BLINKER_LOG("slider:", value);
pwm1=value;
switch(flag)
{
case 1: analogWrite(16, pwm1); break;
case 2: analogWrite(5, pwm1); break;
case 3: analogWrite(5, pwm1); break;
case 4: analogWrite(16, pwm1); break;
case 5: break;
default:break;
}
}
void slider1_callback(int32_t value)
{
BLINKER_LOG("slider:", value);
pwm2=value;
switch(flag)
{
case 1: analogWrite(4, pwm2); break;
case 2: analogWrite(2, pwm2); break;
case 3: analogWrite(2, pwm2); break;
case 4: analogWrite(4, pwm2); break;
case 5: break;
default:break;
}
}
//blinker初始化
void blinker_car_init()
{
//1-4号引脚设置为输出模式
pinMode(16, OUTPUT);//
pinMode(5, OUTPUT);//
pinMode(4, OUTPUT);//
pinMode(2, OUTPUT);//
pinMode(12, OUTPUT);//
pinMode(13, OUTPUT);//
}
void setup()
{
digitalWrite(D0, HIGH);
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D4, HIGH);
analogWriteRange(100);
analogWriteFreq(50);
//analogWrite(D2, 50);//0-100 50
//初始化小车参数
blinker_car_init();
//按钮绑定
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
Button6.attach(button6_callback);
Button7.attach(button7_callback);
Button8.attach(button8_callback);
Button9.attach(button9_callback);
Slider0.attach(slider0_callback);
Slider1.attach(slider1_callback);
Blinker.begin(auth,ssid,pswd);
// Blinker.begin(auth);
}
void loop()
{
Blinker.run();
}
第二份代码:按下后前进,松手立即停止
这个是判断语句,高手一看便知
当按下时前进,否则停止
如果你是小白,找我拿,QQ:1406678649
高手请自己复制粘贴
void button2_callback(const String &state)//forward
{
if (state == BLINKER_CMD_BUTTON_PRESSED)
{
analogWrite(16, too1);
digitalWrite(5, LOW);
analogWrite(4, too2);
digitalWrite(2, LOW);
}
else if (state == BLINKER_CMD_BUTTON_PRESSUP)
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
}
}
转弯调速的语句
在完整代码中:可以看到
BlinkerSlider Slider0(slider_0);
BlinkerSlider Slider1(slider_1);
以及
void slider0_callback(int32_t value) //too1
{
BLINKER_LOG("slider:", value);
too1=value;
switch(flag)
{
case 1: analogWrite(16, too1); break;
case 2: analogWrite(5, too1); break;
case 3: analogWrite(5, too1); break;
case 4: analogWrite(16, too1); break;
case 5: break;
default:break;
}
}
这就是前进后退的指示,
你需要添加新的PWM3和pwm4,在完整代码中复制修改即可
举例:
BlinkerSlider Slider0(slider_0);
BlinkerSlider Slider1(slider_1);
BlinkerSlider Slider2(slider_2);
BlinkerSlider Slider3(slider_3);
int too1=60;
int too2=60;
int too3=40;
int too4=40;
int flag;
t001就是PWM1波的代号,t002就是PWM2波的代号
修改后烧录即可
备注:小白可以加我要代码!!!有偿,,三十一份
如果是一键配网代码:五十一份
也可以自己慢慢学,代码都交给你们了
!!!以上代码保证可用!!!
版权声明:本文为CSDN博主「weixin_51357422」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_51357422/article/details/122664629
暂无评论