Arduino机器人车无线控制采用HC-05蓝牙,NRF24L01和HC-12收发模块

在本教程中,我们将学习如何无线控制之前视频中制作的Arduino机器人汽车。我将向您展示三种不同的无线控制方法,使用HC-05蓝牙模块,NRF24L01收发模块和HC-12远程无线模块,以及使用智能手机和定制的Android应用程序。你可以观看下面的视频或阅读下面的书面教程了解更多细节。

我已经有关于如何连接和使用Arduino板的每个模块的教程,所以如果你需要更多的细节,你可以随时查看它们。在下面的文章中可以找到它们的链接。

利用HC-05蓝牙模块实现Arduino机器人小车控制

我们将从蓝牙通信,为此我们需要两个HC-05蓝牙模块,需要配置为主设备和从设备。

Arduino机器人车HC-05蓝牙控制

我们可以通过使用AT命令轻松做到这一点,我把操纵杆设置为master,把Arduino机器人车设置为slave。下面是这个例子的完整电路原理图:

Arduino机器人车HC-05蓝牙控制电路原理图

你可以从下面的链接中获得这个例子所需的组件:

必威外围提钱披露:这些是联盟链接。作为亚马逊助理,我从合格购买中获得。

源代码

我们将使用相同的代码前一教程,我们直接用操纵杆控制Arduino机器人车,我们会对它做一些修改。

HC-05主代码:

/* Arduino Robot Car Wireless Control using HC-05 Bluetooth == MASTER DEVICE -操纵杆== by Dejan Nedelkovski, www.HowToMechatbet188官方网站ronics.com */ int xAxis, yAxis; /* Arduino Robot Car Wireless Control using HC-05 Bluetooth == MASTER DEVICE -操纵杆== by Dejan Nedelkovski, www.HowToMechatronics.com;void setup() {Serial.begin(38400);//蓝牙模块默认通信速率}void loop() {xAxis = analogRead(A0);//读取操纵杆x轴yAxis = analogRead(A1);//读取操纵杆y轴//通过串口将值发送到从HC-05蓝牙设备serial .write(xAxis/4);//除以4从0 - 1023转换为0 - 256,(1字节)范围延迟(20);}

主设备或操纵杆的代码非常简单。我们只需要读取操纵杆的X和Y值,操纵杆实际上是调节电机的速度,然后通过串口发送到从机HC-05蓝牙设备。我们可以注意到,通过将操纵杆从0到1023的模拟值转换为0到255的数值。

我们这样做是因为从0到255的范围,可以通过蓝牙设备以1字节的形式发送,这更容易被另一边或Arduino机器人汽车接受。

所以在这里,如果串行收到了两个字节,X和Y值,使用serial .read()函数,我们将读取它们。

// Arduino Robot Car的代码//读取来自操纵杆或主蓝牙设备的传入数据while (Serial.available() >= 2) {x = Serial.read();延迟(10);y = Serial.read ();}

现在我们只需将值转换回0到1023的范围,适用于下面的电机控制代码,我们已经解释了它在上一个视频中的工作原理。betway

//将0 - 255范围转换回0 - 1023,适用于xAxis = x*4以下的电机控制代码;yaxis = y * 4;

只需快速注意,在上传代码时,我们需要断开Arduino板的RX和TX引脚。

完整的HC-05 Slave代码:

/ * Arduino机器人汽车无线控制使用HC-05蓝牙==奴隶设备 -  Arduino机器人Car ==由Dejan Nedelkovski,www.www.mfxpo.com * / #define ena 9 #define In1bet188官方网站 4 #define In2 5 #define In2 5 #define eNB 10#define In3 6 #define In4 7 int Xaxis,Yaxis;unsigned int x = 0;unsigned int y = 0;int motorSpeedA = 0;int motorSpeedB = 0;void setup() {pinMode(enA, OUTPUT);pinMode (enB、输出);pinMode(三机一体、输出);pinMode (in2、输出); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); Serial.begin(38400); // Default communication rate of the Bluetooth module } void loop() { // Default value - no movement when the Joystick stays in the center x = 510 / 4; y = 510 / 4; // Read the incoming data from the Joystick, or the master Bluetooth device while (Serial.available() >= 2) { x = Serial.read(); delay(10); y = Serial.read(); } delay(10); // Convert back the 0 - 255 range to 0 - 1023, suitable for motor control code below xAxis = x*4; yAxis = y*4; // Y-axis used for forward and backward control if (yAxis < 470) { // Set Motor A backward digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // Set Motor B backward digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Convert the declining Y-axis readings for going backward from 470 to 0 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 470, 0, 0, 255); motorSpeedB = map(yAxis, 470, 0, 0, 255); } else if (yAxis > 550) { // Set Motor A forward digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // Set Motor B forward digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // Convert the increasing Y-axis readings for going forward from 550 to 1023 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 550, 1023, 0, 255); motorSpeedB = map(yAxis, 550, 1023, 0, 255); } // If joystick stays in middle the motors are not moving else { motorSpeedA = 0; motorSpeedB = 0; } // X-axis used for left and right control if (xAxis < 470) { // Convert the declining X-axis readings from 470 to 0 into increasing 0 to 255 value int xMapped = map(xAxis, 470, 0, 0, 255); // Move to left - decrease left motor speed, increase right motor speed motorSpeedA = motorSpeedA - xMapped; motorSpeedB = motorSpeedB + xMapped; // Confine the range from 0 to 255 if (motorSpeedA < 0) { motorSpeedA = 0; } if (motorSpeedB > 255) { motorSpeedB = 255; } } if (xAxis > 550) { // Convert the increasing X-axis readings from 550 to 1023 into 0 to 255 value int xMapped = map(xAxis, 550, 1023, 0, 255); // Move right - decrease right motor speed, increase left motor speed motorSpeedA = motorSpeedA + xMapped; motorSpeedB = motorSpeedB - xMapped; // Confine the range from 0 to 255 if (motorSpeedA > 255) { motorSpeedA = 255; } if (motorSpeedB < 0) { motorSpeedB = 0; } } // Prevent buzzing at low speeds (Adjust according to your motors. My motors couldn't start moving if PWM value was below value of 70) if (motorSpeedA < 70) { motorSpeedA = 0; } if (motorSpeedB < 70) { motorSpeedB = 0; } analogWrite(enA, motorSpeedA); // Send PWM signal to motor A analogWrite(enB, motorSpeedB); // Send PWM signal to motor B }

使用智能手机和定制的Android应用程序的Arduino机器人汽车控制

接下来,让我们看看如何使用一个定制构建Android应用.机器人车的电路示意图与前一个例子完全相同,HC-05蓝牙模式设置为从设备。

Arduino机器人车Android智能手机控制

另一方面,使用麻省理工学院应用程序发明家在线应用程序我们将构建我们自己的Android应用程序,这是它的样子。

所以基本上这款应用模拟的是一个操纵杆,它的外观是由两个图像或图像精灵组成的。

麻省理工学院应用发明人操纵杆应用Arduino机器人汽车控制教程

如果我们看看这个应用程序的块,我们可以看到,当操纵杆精灵被拖动时,操纵杆球的图像被移动到手指的当前位置,同时我们发送x和y在蓝牙到Arduino汽车的价值。麻省理工学院应用程序发明家操纵杆应用程序块

Arduino以与前面示例相同的方式接受这些值,即使用Serial。读功能。

//从智能手机Android应用读取传入的数据while (Serial.available() >= 2) {x = Serial.read();延迟(10);y = Serial.read ();}

另外,我们需要做的是将从智能手机接收到的X和Y值转换为0到1023的范围,适合下面的电机控制代码。这些值取决于画布大小,我从应用中获得的X和Y值从60到220,使用map()函数我可以轻松地转换它们。

//确保我们收到正确的值if (x > 60 & x < 220) {xAxis = map(x, 220, 60, 1023, 0);//将智能手机X和Y值转换为0 - 1023范围,适合电机控制代码下面的电机}if (Y > 60 & Y < 220) {yAxis = map(Y, 220, 60, 0,1023);}

在应用程序块中,我们还可以看到,当图像精灵被润色时,操纵杆球将移回画布的中心,并将适当的值发送给汽车以停止移动。你可以在网站上找到并下载这个应用程序的文章,以及两个操纵杆的图像,这样你就可以创建自己的或修改这个应用程序。

您可以下载下面的Android应用程序,以及操纵杆的两个图像:

完整的Arduino代码:

/ * Arduino机器人汽车无线控制使用HC-05蓝牙和自定义版Android App ==从设备 -  Arduino Robot Car == by Dejan Nedelkovski,www.www.mfxpo.com * / #define ena 9 #define In1 4 #debet188官方网站fine在2 5 #define eNB 10 #define In3 6 #define In4 7 int Xaxis,Yaxis;Int x = 0;Int y = 0;int motorSpeedA = 0;int motorSpeedB = 0;void setup() {pinMode(enA, OUTPUT);pinMode (enB、输出);pinMode(三机一体、输出);pinMode (in2、输出); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); Serial.begin(38400); // Default communication rate of the Bluetooth module } void loop() { // Default value - no movement when the Joystick stays in the center xAxis = 510; yAxis = 510; // Read the incoming data from the Smartphone Android App while (Serial.available() >= 2) { x = Serial.read(); delay(10); y = Serial.read(); } delay(10); // Makes sure we receive corrent values if (x > 60 & x < 220) { xAxis = map(x, 220, 60, 1023, 0); // Convert the smartphone X and Y values to 0 - 1023 range, suitable motor for the motor control code below } if (y > 60 & y < 220) { yAxis = map(y, 220, 60, 0, 1023); } // Y-axis used for forward and backward control if (yAxis < 470) { // Set Motor A backward digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // Set Motor B backward digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Convert the declining Y-axis readings for going backward from 470 to 0 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 470, 0, 0, 255); motorSpeedB = map(yAxis, 470, 0, 0, 255); } else if (yAxis > 550) { // Set Motor A forward digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // Set Motor B forward digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // Convert the increasing Y-axis readings for going forward from 550 to 1023 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 550, 1023, 0, 255); motorSpeedB = map(yAxis, 550, 1023, 0, 255); } // If joystick stays in middle the motors are not moving else { motorSpeedA = 0; motorSpeedB = 0; } // X-axis used for left and right control if (xAxis < 470) { // Convert the declining X-axis readings from 470 to 0 into increasing 0 to 255 value int xMapped = map(xAxis, 470, 0, 0, 255); // Move to left - decrease left motor speed, increase right motor speed motorSpeedA = motorSpeedA - xMapped; motorSpeedB = motorSpeedB + xMapped; // Confine the range from 0 to 255 if (motorSpeedA < 0) { motorSpeedA = 0; } if (motorSpeedB > 255) { motorSpeedB = 255; } } if (xAxis > 550) { // Convert the increasing X-axis readings from 550 to 1023 into 0 to 255 value int xMapped = map(xAxis, 550, 1023, 0, 255); // Move right - decrease right motor speed, increase left motor speed motorSpeedA = motorSpeedA + xMapped; motorSpeedB = motorSpeedB - xMapped; // Confine the range from 0 to 255 if (motorSpeedA > 255) { motorSpeedA = 255; } if (motorSpeedB < 0) { motorSpeedB = 0; } } // Prevent buzzing at low speeds (Adjust according to your motors. My motors couldn't start moving if PWM value was below value of 70) if (motorSpeedA < 70) { motorSpeedA = 0; } if (motorSpeedB < 70) { motorSpeedB = 0; } analogWrite(enA, motorSpeedA); // Send PWM signal to motor A analogWrite(enB, motorSpeedB); // Send PWM signal to motor B }

利用NRF24L01收发模块实现Arduino机器人汽车无线控制

现在我们可以进入下一种方法,利用无线控制Arduino机器人车NRF24L01收发器模块

Arduino机器人车NRF24L01收发模块教程

这是电路原理图。我们可以注意到,这些模块使用SPI通信,所以与前面的示例相比,我将L298N驱动的Enable A和Enable B引脚移动到Arduino板的引脚2和3。NRF24L01无线Arduino机器人小车控制电路原理图您可以在以下内获取NRF24L01模块亚马逊的链接

源代码

对于这个示例,我们需要安装RF24库。与前面的示例类似,在定义一些引脚并将模块设置为发射器后,我们读取操纵杆的X和Y值,并将其发送到Arduino机器人车上的另一个NRF24L01模块。

首先,我们可以注意到模拟读数是字符串,它使用String.toCharArray()函数被放入字符数组中。然后使用radio.write()函数,我们将该字符数组数据发送到另一个模块。

变送器代码:

/* Arduino Robot Car Wireless Control using the NRF24L01 Transceiver module == Transmitter - Joystick == by Dejan Nedelkovski, www.bet188官方网站HowToMechatronics.com Library: TMRh20/RF24, https://github.com/tmrh20/RF24/ */ #include  #include < NRF24L01 .h> #include  radio(8,9);// CE, CSN const字节地址[6]= "00001";char xyData[32] = "";字符串xAxis桠溪;void setup() {Serial.begin(9600);radio.begin ();radio.openWritingPipe(地址);radio.setPALevel (RF24_PA_MIN);radio.stopListening ();} void loop() {xAxis = analogRead(A0); // Read Joysticks X-axis yAxis = analogRead(A1); // Read Joysticks Y-axis // X value xAxis.toCharArray(xyData, 5); // Put the String (X Value) into a character array radio.write(&xyData, sizeof(xyData)); // Send the array data (X value) to the other NRF24L01 modile // Y value yAxis.toCharArray(xyData, 5); radio.write(&xyData, sizeof(xyData)); delay(20); }

在另一边。在Arduino机器人车上,在将模块定义为接收器后,我们使用radio.read()函数接受数据。然后使用atoi()函数,我们将接收到的数据或来自操纵杆的X和Y值转换为整数值,这适用于下面的电机控制代码。

//来自Arduino机器人Car的代码 -  NRF24L01示例(radio.Available()){//,如果NRF240L01模块接收到数据无线电.Read(&roceedData,sizeof(roceaddata));//读取数据并将其放入字符数组xAxis = atoi(&receivedData[0]);//将字符数组中的数据(接收到的X值)转换为整数delay(10);radio.read(&roceeddata,sizeof(recaptdata));桠溪= atoi (&receivedData [0]);延迟(10);}

这很简单,但当然,正如我已经说过的,如果你需要更多的细节如何连接和设置模块,你可以随时查看我的特定教程。

接收器代码:

/* Arduino Robot Car Wireless Control using the NRF24L01 Transceiver module == Receiver - Arduino Robot Car == by Dejan Nedelkovski, www.bet188官方网站HowToMechatronics.com Library: TMRh20/RF24, https://github.com/tmrh20/RF24/ */ #include  #include < NRF24L01 .h> #include  #define enA 2 //注意:在之前的视频中Pin 10 #define in3 6 #define in4 7 RF24 radio(8,9);// CE, CSN const字节地址[6]= "00001";char receivedData[32] = "";int xAxis桠溪;int motorSpeedA = 0;int motorSpeedB = 0;void setup() {pinMode(enA, OUTPUT);pinMode (enB、输出);pinMode(三机一体、输出); pinMode(in2, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); Serial.begin(9600); radio.begin(); radio.openReadingPipe(0, address); radio.setPALevel(RF24_PA_MIN); radio.startListening(); } void loop() { if (radio.available()) { // If the NRF240L01 module received data radio.read(&receivedData, sizeof(receivedData)); // Read the data and put it into character array xAxis = atoi(&receivedData[0]); // Convert the data from the character array (received X value) into integer delay(10); radio.read(&receivedData, sizeof(receivedData)); yAxis = atoi(&receivedData[0]); delay(10); } // Y-axis used for forward and backward control if (yAxis < 470) { // Set Motor A backward digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // Set Motor B backward digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Convert the declining Y-axis readings for going backward from 470 to 0 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 470, 0, 0, 255); motorSpeedB = map(yAxis, 470, 0, 0, 255); } else if (yAxis > 550) { // Set Motor A forward digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // Set Motor B forward digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // Convert the increasing Y-axis readings for going forward from 550 to 1023 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 550, 1023, 0, 255); motorSpeedB = map(yAxis, 550, 1023, 0, 255); } // If joystick stays in middle the motors are not moving else { motorSpeedA = 0; motorSpeedB = 0; } // X-axis used for left and right control if (xAxis < 470) { // Convert the declining X-axis readings from 470 to 0 into increasing 0 to 255 value int xMapped = map(xAxis, 470, 0, 0, 255); // Move to left - decrease left motor speed, increase right motor speed motorSpeedA = motorSpeedA - xMapped; motorSpeedB = motorSpeedB + xMapped; // Confine the range from 0 to 255 if (motorSpeedA < 0) { motorSpeedA = 0; } if (motorSpeedB > 255) { motorSpeedB = 255; } } if (xAxis > 550) { // Convert the increasing X-axis readings from 550 to 1023 into 0 to 255 value int xMapped = map(xAxis, 550, 1023, 0, 255); // Move right - decrease right motor speed, increase left motor speed motorSpeedA = motorSpeedA + xMapped; motorSpeedB = motorSpeedB - xMapped; // Confine the range from 0 to 255 if (motorSpeedA > 255) { motorSpeedA = 255; } if (motorSpeedB < 0) { motorSpeedB = 0; } } // Prevent buzzing at low speeds (Adjust according to your motors. My motors couldn't start moving if PWM value was below value of 70) if (motorSpeedA < 70) { motorSpeedA = 0; } if (motorSpeedB < 70) { motorSpeedB = 0; } analogWrite(enA, motorSpeedA); // Send PWM signal to motor A analogWrite(enB, motorSpeedB); // Send PWM signal to motor B }

利用HC-12远程收发器实现Arduino机器人汽车无线控制

对于最后一种Arduino机器人小车的无线控制方法,我们将使用HC-12远程收发模块.这些模块之间的通信距离可达1.8公里。

本例的电路原理图与HC-05蓝牙模块的电路原理图几乎相同,因为它们使用相同的方法通过串口与Arduino进行通信。

利用HC-12远程收发器实现Arduino机器人汽车无线控制

你可以在下面得到HC-12收发模块亚马逊的链接

源代码

操纵杆代码与蓝牙通信的码完全相同。我们只是读取操纵杆的模拟值,并使用Serial.Write()函数将它们发送到另一个模块。

变送器代码:

/* Arduino机器人汽车无线控制使用HC-12远程无线模块==发射器-操纵杆== by Dejan Nedelkovski, www.HowToMechatronics.com */ int xAxis, yAxis;bet188官方网站void setup() {Serial.begin(9600);//蓝牙模块默认通信速率}void loop() {xAxis = analogRead(A0);//读取操纵杆x轴yAxis = analogRead(A1);//读取操纵杆y轴//通过串口将值发送到从HC-05蓝牙设备serial .write(xAxis/4);//除以4从0 - 1023转换为0 - 256,(1字节)范围延迟(20);}

在另一边,随着时间()循环我们等到数据到达,然后使用Serial.read()函数读取它并将其转换回0到1023范围内,适用于下面的电机控制码。

接收器代码:

/* Arduino Robot Car Wireless Control using HC-12 long range Wireless module == Receiver - Arduino Robot Car == by Dejan Nedelkovski, www.HowTbet188官方网站oMechatronics.com */ / #define enB 9 #define in1 4 #define in2 5 #define enB 10 #define in3 6 #define in4 7 int xAxis, yAxis;Int x = 0;Int y = 0;int motorSpeedA = 0;int motorSpeedB = 0;void setup() {pinMode(enA, OUTPUT);pinMode (enB、输出);pinMode(三机一体、输出);pinMode (in2、输出);pinMode (in3、输出); pinMode(in4, OUTPUT); Serial.begin(9600); // Default communication rate of the Bluetooth module } void loop() { // Default value - no movement when the Joystick stays in the center xAxis = 510; yAxis = 510; // Read the incoming data from the while (Serial.available() == 0) {} x = Serial.read(); delay(10); y = Serial.read(); delay(10); // Convert back the 0 - 255 range to 0 - 1023, suitable for motor control code below xAxis = x * 4; yAxis = y * 4; // Y-axis used for forward and backward control if (yAxis < 470) { // Set Motor A backward digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // Set Motor B backward digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Convert the declining Y-axis readings for going backward from 470 to 0 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 470, 0, 0, 255); motorSpeedB = map(yAxis, 470, 0, 0, 255); } else if (yAxis > 550) { // Set Motor A forward digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // Set Motor B forward digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // Convert the increasing Y-axis readings for going forward from 550 to 1023 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 550, 1023, 0, 255); motorSpeedB = map(yAxis, 550, 1023, 0, 255); } // If joystick stays in middle the motors are not moving else { motorSpeedA = 0; motorSpeedB = 0; } // X-axis used for left and right control if (xAxis < 470) { // Convert the declining X-axis readings from 470 to 0 into increasing 0 to 255 value int xMapped = map(xAxis, 470, 0, 0, 255); // Move to left - decrease left motor speed, increase right motor speed motorSpeedA = motorSpeedA - xMapped; motorSpeedB = motorSpeedB + xMapped; // Confine the range from 0 to 255 if (motorSpeedA < 0) { motorSpeedA = 0; } if (motorSpeedB > 255) { motorSpeedB = 255; } } if (xAxis > 550) { // Convert the increasing X-axis readings from 550 to 1023 into 0 to 255 value int xMapped = map(xAxis, 550, 1023, 0, 255); // Move right - decrease right motor speed, increase left motor speed motorSpeedA = motorSpeedA + xMapped; motorSpeedB = motorSpeedB - xMapped; // Confine the range from 0 to 255 if (motorSpeedA > 255) { motorSpeedA = 255; } if (motorSpeedB < 0) { motorSpeedB = 0; } } // Prevent buzzing at low speeds (Adjust according to your motors. My motors couldn't start moving if PWM value was below value of 70) if (motorSpeedA < 70) { motorSpeedA = 0; } if (motorSpeedB < 70) { motorSpeedB = 0; } analogWrite(enA, motorSpeedA); // Send PWM signal to motor A analogWrite(enB, motorSpeedB); // Send PWM signal to motor B }

所以这对本教程来说几乎是一切。随意询问以下意见部分中的任何问题。

53回复

  1. 城市

    非常感谢
    我打算为类似的东西制作代码,现在我节省了很多时间

    谢谢你分享所有这些

    Ps:因为我以前从未使用过MIT App Inventor,如果项目文件是可用的,那么基于你的构建和学习使用这个应用程序会更容易实验
    我是说这些,因为我看到了在其他项目中,您可以使用项目文件。bet188me

    我订阅了你的YouTube频道,我认为你应该拥有比现在更多的订阅者。我想你很快就能拿到了

    回复
      • 默罕默德Sameer

        感谢一百万兄弟。你已经节省了很多其他的时间并帮助了,以便我们可以做出更多的提前薄薄

  2. 本杰明

    你好呀,

    我想用smarthphone建造自己的机器人车。我下载了应用程序,我用右电路原理构建机器人。我连接到HC-05,我触摸了操纵杆球,没有发生任何事情。有时我听到来自电机的一些噪音,有时它已经运行,但只有一种方式,只有1个电机。在您的视频中,您谈论画布大小。我在哪里可以看到?
    你知道我该怎么解决吗?
    谢谢

    回复
    • 德扬Nedelkovski

      嗯,您可能需要调整画布大小。此调整应在App块中完成。首先,您应该检查您在手机上触摸的区域中获得的值,然后确保与驱动电机的值匹配。

      回复
      • 内森

        我如何确定如何确定帆布区域的值?我猜测了64在“获取CurrentX - 64”中和“140-64”的值必须更改......对吗?
        我用的是三星note3,和本杰明有同样的问题。
        谢谢。

  3. 优素福sameh

    你好谢谢你的努力工作我想建立的汽车控制通过一个智能手机蓝牙和我一切根据教程应用但有一个问题,当我试图阻止运动不停止,汽车将会在一个高速如果你能帮助我解决这个问题我将非常感激的
    谢谢

    回复
    • 德扬Nedelkovski

      嘿,问题可能出在智能手机应用程序中。当发布应用程序操纵杆时,应用程序应该发送正确的值,以便电机停止旋转,就像解释的那样。

      回复
  4. Deepti.

    Nano需要通过USB连接才能供电吗?如果是这样,我们还能怎么给它供电,让我们可以随身携带遥控器,而不用依赖笔记本电脑连接呢?(如果这是一个愚蠢的问题,我很抱歉,我对Arduino和电子真的是新的,这是我的第一个项目之一。)必威lolbet188me

    回复
    • 德扬Nedelkovski

      你可以用电池给Arduino供电。Arduino上有一个Vin引脚,可以提供7.2v到12V的电压。这是与电源插座相同的连接,这些12V将通过板载电压调节器,使其为适合Arduino的5V。

      回复
  5. Pranav Desai.

    嘿,
    我试图制作这辆车。在MIT应用程序Inventor的块中,您将电流x和当前y减去64(拖动图像普通时)。您还从64中减去140(当AignerPrite触摸时)。您还发送140(Send1bytenumber)。
    你能解释这些事情的意思吗?

    谢谢!

    回复
    • 德扬Nedelkovski

      嘿,画布大小约为130px,所以为了将它定位在屏幕的中间,我需要减去其值的一半,因为x,y定位的值位于画布的左上角。

      回复
      • Pranav Desai.

        谢谢!
        在Arduino的教程中,你帮了我很多!
        坚持下去!

  6. rahul yadav.

    嘿!
    如果我改变传输输入到加速度计而不是操纵杆,使用hc-12作为通信设备,我需要如何改变相同的传输代码?

    谢谢!

    回复
    • 德扬Nedelkovski

      嗯,您需要读取加速度计数据,并以相同的方式将该数据发送到接收器。当然,代码将取决于加速度计模型,但是您可以检查我的MEMS加速度计教程,该教程解释了如何使用Arduino的加速度计。

      回复
  7. 阴暗的

    谢谢很多工作。
    但我面临着问题
    我用你告诉我们连接了一切,但最多的是一个不起作用,另一个只是移动2或3度......我几乎听到了它的声音并让我在应用程序上给我这个消息
    “无法将259分为1字节”
    是一个解决方案

    回复
    • 德扬Nedelkovski

      该错误指示当您向Arduino发送值259时,该值大于一个字节。您可以注意到,在应用程序中,我们只向Arduino发送了1个字节,因此可以发送0到255的值。如果你想发送更大的值,它不能在1个字节。所以你应该确保你只发送低于255的数值,你必须限制应用中的操纵杆,或者在触摸操纵杆区域时调整这些数值。

      回复
  8. 特里

    伟大的项目,有什么原因我不能使用Arduino Nano或Micro的作为项目两边的控制器吗?

    保持良好的工作,谢谢分享

    回复
  9. Cyrill

    你好,我正在做一个通过蓝牙进行无线控制的项目。我在youtube上看过你的视频。我也使用h桥和12v电源。我应该做什么来防止可能arduino和h桥安全特别IC谢谢

    回复
    • 德扬

      嘿,很好,如果H-Bridge模块在5V上工作,那么您可以安全地使用Arduino,同时通过VIN PIN(12V到VIN PIN)或电源插孔为Arduino供电。

      回复
  10. 巴里

    首先,我要感谢您,还尝试了至少5个其他类似的项目,没有巨大的结果,我发现了您每次第一次工作的NRFL(我现在建于3)。bet188me我的孙子们想比赛他们有没有办法将每对(控制器和坦克)设置为自己的频道,以便它们不会相互干扰?。

    谢谢你。

    回复
    • 德扬

      听你这么说我很高兴。是的,这是可能的,但请检查RF24库文档,你应该在那里找到关于这个主题的更多细节,目前我没有这样的例子。

      回复
  11. 泰勒米埃尔南德斯

    你好!非常感谢您的教程,我希望为我的工程课使用它。我遵循了你的原理图,将代码上传到Arduino,下载了应用程序,我无法让它正常工作。我可以立即连接到蓝牙模块,但是当我使用操纵杆时,我几乎没有回复。我可以有1个电机有时移动,甚至它始终处于相同的方向。

    任何可能导致这件事的想法吗?I went line by line through the code multiple times, triple checked the circuit, so I think the issue might be the app but I struggle to understand how to use MIT app inventor 2. I tried modifying your app but I can’t get it to work. Any ideas what the issue might be and how to solve it?

    回复
    • 德扬

      嘿,听起来你有蓝牙通信有问题。尝试更改波特率,您的HC-05模块可能具有9600的默认波特率。尝试将来自蓝牙的传入数据打印到串行监视器上,并查看您获得了什么样的值。

      回复
  12. 达西哈兰

    你好,
    我做了你的arduino小车,非常喜欢。我试图让应用程序连接到蓝牙模块,但它有问题。我与我创建的汽车有一个不同之处,我使用了HM-10 BLE蓝牙4.0 (MLT-TB05)而不是HC05,因为我有它可用。除此之外,我使用了和你完全一样的应用包括你在MIT app inventor 2上创建的应用。

    我已经能够将手机与蓝牙模块配对,可以在MIT AI2伴侣中打开应用程序。但是我无法连接到应用程序内的模块,我继续接收“错误507:无法连接。设备是否已打开?“当我尝试连接它时。

    我尝试过将通信频带更改为115200,我理解这是MLT-TB05的通信频率,但它似乎在9600、38400或115200上都不起作用。这可能是一个固件问题,但我不确定如何检查或更新。

    您是否有任何关于如何获得两个连接的想法?

    附注:我是你的一个大粉丝,希望教我的高中学生如何做任何和所有的项目。bet188me你的电子工程知识和你做的东西让我很吃惊。我想让这个项目我10年的但我需要确保所有组件的价格在10美元的澳大利亚,我需要购买变速箱,汽车司机和蓝牙模块至少做项目(我们可以激光打印已经休息,他们有一个arduino和电池)。

    回复
    • 德扬

      嘿,谢谢,我很高兴听到你发现我的项目有趣,并希望教学学生与他们一起教学。bet188me
      我没有使用HC-10 BLE模块,既不尝试一下,看看它是如何工作的。betway所以在这一刻,我无法帮助你,抱歉。

      回复
  13. Ganesh.

    通用ARD-A000067 Arduino Mega 2560 Rev3 - 意大利制造
    我可以用这个Arduino板做这个应用吗?还是你在链接里提到的那个?

    回复
  14. 阿一

    亲爱的呵呵,

    谢谢你的这篇有用的文章。HC-12部分的所有步骤我都遵循了,但是我有一个奇怪的问题,关于电机a,如果把操纵杆向上拉,它只能朝一个方向移动,而当你把操纵杆放下时,电机没有朝其他方向移动。我猜这可能与有问题的操纵杆有关,所以我改变了它,但问题仍然存在。就连我也换了发动机。当你快速移动操纵杆时,当操纵杆向下时,A电机的方向会发生变化,仍然没有运动,出现了奇怪的部分。可能与PMW功能有关,我不知道。

    回复
    • 德扬

      好的,移动电源有5V输出,而这个直流电机驱动器工作在12V。如果使用不同的驱动或直流电机,也许你可以让它与移动电源一起工作。

      回复
  15. 皮特

    我可以使用更高转速的直流电机吗?pwm数与什么相关?如果我的电机转速是550转,我就得换了,对吗?

    回复
    • 德扬

      当然,你可以使用更高转速的直流电动机。PWM值是用来控制电机的速度从0到100%的能力。Arduino接受从0到255的PWM值,对应从0到100功率或rpm。

      回复
      • 皮特

        谢谢你!我很快就要开始这个项目了。我计划添加2个更多的直流电机后,使它四轮驱动。希望我能做到。再一次感谢您!

  16. 克里斯

    德扬先生你好,

    我是你的超级粉丝。非常感谢你的文章。

    我在蓝牙方面有一点困难。我的HC-05的默认波特率是9600。我修改了代码并上传了。这种配对也可以。然而,它似乎没有值正在从应用程序发送到蓝牙。我想拍连续剧。Println里面的串行。可用循环-没有值。

    有什么建议么?我花了很多时间试图弄清楚这一点。

    再次感谢,
    克里斯

    回复
  17. Sanjay Pratap Singh.

    非常感谢您的教程,我通过基于您的代码和原理图来使用HC-12模块进行了RC汽车,它一次性工作得很好,谢谢,
    但问题很少 -
    1.要左转或右转,只有一侧电机运行,另一侧电机应以相反的方向运行,但保持静止。请建议如何修改代码,我想当它向左转动时,电机向前和向后。
    2.当汽车远离HC-12模块范围时,它保持跑步,不会停止,保持移动,不得不抓住它来阻止它或者必须靠近遥远的汽车。
    3.我的HC-12模块信号质量比NRF24好得多,但也只有10-20mtrs范围,请建议如何做。
    4.需要增加一些可以远程控制的灯,请建议修改代码

    提前谢谢。

    桑杰

    回复
    • 德扬

      嘿,很高兴听到你的项目成功了。
      好吧,如果你想在向左或向右转时两个轮子都向相反方向转,你需要修改“move left”和“move right”“if”语句部分的代码。例如,要向右移动,你需要使用“in1”和“in2”引脚设置/改变左电机的旋转方向,反之亦然。
      为了在失去信号时防止汽车运行,可以添加一个代码,如果模块之间没有通信,则告诉所有动作停止。检查我的Arduino RC发射器项目,我在那里使用了这个方法,所以你会发现你可以如何做那个解释。
      至于HC-12模块的范围,对于获得最远的通信距离,您需要将模块的波特率设置为最低级别。
      向项目添加一些LED应该很容易。控制它们是光线打开和关闭单个引脚。
      干杯!

      回复
      • Sanjay Pratap Singh.

        谢谢德詹,

        请问您是否可以给我发一个代码,以便在信号丢失时停车,我尝试了很多方法,但都没有成功。

  18. 斯特凡•西格尔

    你好,德扬
    我真的很喜欢您的教程,并且已经成功构建了许多这样的项目。bet188me也许你能帮我解决我的无线NRF24L01机器人车的一个小问题。每隔一段时间,x轴和y轴就会互换——也就是说,向前移动操纵杆,然后倒车,让汽车左右转弯,以此类推。我得把发射机关掉再打开来校正。知道怎么纠正这个错误吗?
    很多谢谢!
    史蒂夫斯。

    回复
    • 德扬

      很高兴听到你这么说。我建议你检查一下我的DIY Arduino RC Transmitter项目。我有一个控制NRF24L01机器人汽车的相同的例子,但在无线电通信或发送和接收日期方面有一点不同的代码。

      回复

留下一个回复

您的电子邮件地址不会被公开。

受到推崇的

2019年最佳入门级示波器初学者和爱好者

初学者和爱好者最好的示波器

受到推崇的

2019年最佳Arduino入门套件

8个最好的arduino初学者工具包

受到推崇的

用于初学者和爱好者的最佳3D打印机 -  3D打印

初学者和爱好者的最佳3D打印机