15浏览
查看: 15|回复: 2

[项目] 【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制

[复制链接]
在本教程中,我们将学习如何制作一个 Arduino 机械臂,该机械臂可以使用定制的 Android 应用程序进行无线控制和编程。我将向您展示构建它的整个过程,从设计和 3D 打印机器人部件、连接电子元件和 Arduino 编程开始,到开发我们自己的 Android 应用程序来控制机器人手臂。

概述
Arduino 机械臂 3D 模型
3D 打印机械臂
组装机械臂
Arduino 机械臂电路图
Arduino 机械臂代码
控制 Android 应用程序
Arduino 机械臂控制 MIT App Inventor 项目文件
您可以观看以下视频或阅读下面的书面教程。

使用 App 中的滑块,我们可以手动控制机器人手臂的每个伺服或轴的运动。此外,使用 “Save” 按钮,我们可以记录每个位置或步骤,然后机器人手臂可以自动运行并重复这些步骤。使用相同的按钮,我们可以暂停自动作以及重置或删除所有步骤,以便我们可以记录新的步骤。

Arduino 机械臂 3D 模型
首先,我使用 Solidworks 3D 建模软件设计了机械臂。机械臂有 5 个自由度。

Arduino 机械臂 3D 模型
对于前 3 个轴,腰部、肩部和肘部,我使用了 MG996R 伺服器,对于另外 2 个轴,手腕滚动和手腕俯仰,以及夹持器,我使用了较小的 SG90 微型伺服器。

您可以从 Cults3D 获取此 3D 模型以及用于 3D 打印的 STL 文件。

3D 打印机械臂
使用我的新 3D 打印机 Creality CR-10,我 3D 打印了 Arduino 机械臂的所有部件。


我在短短几个小时内就准备好了 Arduino 机械臂的所有部件。


阅读更多: 15 大必备 3D 打印机配件和工具

组装机械臂
好了,现在我们已经准备好组装机器人手臂了。我从连接第一个伺服电机的底座开始,使用包装中包含的螺钉。然后在伺服器的输出轴上,我固定了一个圆角,一个螺栓。


在它上面,我放置了上部并用两个螺丝固定它。

Arduino 机械臂底座组件
在这里,首先进行伺服,然后将圆角连接到下一个零件上,然后使用输出轴上的螺栓将它们相互固定。


我们可以在这里注意到,在肩轴上,最好包含某种弹簧,或者就我而言,我使用橡皮筋为伺服器提供一些帮助,因为该伺服器承载了手臂其余部分的全部重量以及有效载荷。


以类似的方式,我继续组装机器人手臂的其余部分。至于夹持机构,我使用了大约 4 毫米的螺栓和螺母来组装它。

3D 打印机机械臂
最后,我将夹爪机构连接到最后一个伺服器上,Arduino 机械臂就完成了。

Arduino 机械臂 - 3D 打印
Arduino 机械臂电路图
下一阶段是连接电子设备。这个项目的电路图其实很简单。我们只需要一个 Arduino 板和一个 HC-05 蓝牙模块,用于与智能手机通信。六个伺服电机的控制引脚连接到 Arduino 板的六个数字引脚。

Arduino 机械臂原理图电路图
为了给伺服系统供电,我们需要 5V,但这必须来自外部电源,因为 Arduino 无法处理它们都可以吸收的电流量。电源必须能够处理至少 2A 的电流。因此,一旦我们将所有内容连接在一起,我们就可以继续对 Arduino 进行编程并制作 Android 应用程序。

您可以从以下链接获取此示例所需的组件:

MG996R 伺服电机................................亚马逊 / Banggood / 全球速卖通
SG90 微型伺服电机 ..........................亚马逊 / Banggood / 全球速卖通
HC-05 蓝牙模块 .........................亚马逊 / Banggood / 全球速卖通
Arduino 板 ...........................................亚马逊 / Banggood / 全球速卖通
5V 2A 直流电源 ...........................亚马逊 / Banggood / 全球速卖通
披露:这些是附属链接。作为 Amazon Associate,我从符合条件的购买中赚取收入。

Arduino 机械臂代码
由于代码较长,为了更好地理解,我将把程序的源代码分成几个部分发布,并为每个部分提供说明。在本文的最后,我将发布完整的源代码。

因此,首先我们需要包括用于蓝牙模块串行通信的 SoftwareSerial 库以及伺服库。这两个库都包含在 Arduino IDE 中,因此您不必从外部安装它们。然后我们需要定义六个舵机、HC-05 蓝牙模块和一些用于存储舵机当前和之前位置的变量,以及用于存储自动模式的位置或步骤的数组。

我使用 MIT App Inventor 在线应用程序制作了该应用程序,以下是它的工作原理。在顶部,我们有两个按钮用于将智能手机连接到 HC-05 蓝牙模块。然后在左侧我们有机器人手臂的图像,在右侧我们有六个用于控制伺服系统的滑块和一个用于速度控制的滑块。

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制图2

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制图1

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制图3

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制图6

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制图5

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制图4

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制图7


驴友花雕  中级技神
 楼主|

发表于 5 小时前

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制

项目代码

  1. /*        
  2.        DIY Arduino Robot Arm Smartphone Control  
  3.         by Dejan, www.HowToMechatronics.com  
  4. */
  5. #include <SoftwareSerial.h>
  6. #include <Servo.h>
  7. Servo servo01;
  8. Servo servo02;
  9. Servo servo03;
  10. Servo servo04;
  11. Servo servo05;
  12. Servo servo06;
  13. SoftwareSerial Bluetooth(3, 4); // Arduino(RX, TX) - HC-05 Bluetooth (TX, RX)
  14. int servo1Pos, servo2Pos, servo3Pos, servo4Pos, servo5Pos, servo6Pos; // current position
  15. int servo1PPos, servo2PPos, servo3PPos, servo4PPos, servo5PPos, servo6PPos; // previous position
  16. int servo01SP[50], servo02SP[50], servo03SP[50], servo04SP[50], servo05SP[50], servo06SP[50]; // for storing positions/steps
  17. int speedDelay = 20;
  18. int index = 0;
  19. String dataIn = "";
  20. void setup() {
  21.   servo01.attach(5);
  22.   servo02.attach(6);
  23.   servo03.attach(7);
  24.   servo04.attach(8);
  25.   servo05.attach(9);
  26.   servo06.attach(10);
  27.   Bluetooth.begin(38400); // Default baud rate of the Bluetooth module
  28.   Bluetooth.setTimeout(1);
  29.   delay(20);
  30.   // Robot arm initial position
  31.   servo1PPos = 90;
  32.   servo01.write(servo1PPos);
  33.   servo2PPos = 150;
  34.   servo02.write(servo2PPos);
  35.   servo3PPos = 35;
  36.   servo03.write(servo3PPos);
  37.   servo4PPos = 140;
  38.   servo04.write(servo4PPos);
  39.   servo5PPos = 85;
  40.   servo05.write(servo5PPos);
  41.   servo6PPos = 80;
  42.   servo06.write(servo6PPos);
  43. }
  44. void loop() {
  45.   // Check for incoming data
  46.   if (Bluetooth.available() > 0) {
  47.     dataIn = Bluetooth.readString();  // Read the data as string
  48.    
  49.     // If "Waist" slider has changed value - Move Servo 1 to position
  50.     if (dataIn.startsWith("s1")) {
  51.       String dataInS = dataIn.substring(2, dataIn.length()); // Extract only the number. E.g. from "s1120" to "120"
  52.       servo1Pos = dataInS.toInt();  // Convert the string into integer
  53.       // We use for loops so we can control the speed of the servo
  54.       // If previous position is bigger then current position
  55.       if (servo1PPos > servo1Pos) {
  56.         for ( int j = servo1PPos; j >= servo1Pos; j--) {   // Run servo down
  57.           servo01.write(j);
  58.           delay(20);    // defines the speed at which the servo rotates
  59.         }
  60.       }
  61.       // If previous position is smaller then current position
  62.       if (servo1PPos < servo1Pos) {
  63.         for ( int j = servo1PPos; j <= servo1Pos; j++) {   // Run servo up
  64.           servo01.write(j);
  65.           delay(20);
  66.         }
  67.       }
  68.       servo1PPos = servo1Pos;   // set current position as previous position
  69.     }
  70.    
  71.     // Move Servo 2
  72.     if (dataIn.startsWith("s2")) {
  73.       String dataInS = dataIn.substring(2, dataIn.length());
  74.       servo2Pos = dataInS.toInt();
  75.       if (servo2PPos > servo2Pos) {
  76.         for ( int j = servo2PPos; j >= servo2Pos; j--) {
  77.           servo02.write(j);
  78.           delay(50);
  79.         }
  80.       }
  81.       if (servo2PPos < servo2Pos) {
  82.         for ( int j = servo2PPos; j <= servo2Pos; j++) {
  83.           servo02.write(j);
  84.           delay(50);
  85.         }
  86.       }
  87.       servo2PPos = servo2Pos;
  88.     }
  89.     // Move Servo 3
  90.     if (dataIn.startsWith("s3")) {
  91.       String dataInS = dataIn.substring(2, dataIn.length());
  92.       servo3Pos = dataInS.toInt();
  93.       if (servo3PPos > servo3Pos) {
  94.         for ( int j = servo3PPos; j >= servo3Pos; j--) {
  95.           servo03.write(j);
  96.           delay(30);
  97.         }
  98.       }
  99.       if (servo3PPos < servo3Pos) {
  100.         for ( int j = servo3PPos; j <= servo3Pos; j++) {
  101.           servo03.write(j);
  102.           delay(30);
  103.         }
  104.       }
  105.       servo3PPos = servo3Pos;
  106.     }
  107.     // Move Servo 4
  108.     if (dataIn.startsWith("s4")) {
  109.       String dataInS = dataIn.substring(2, dataIn.length());
  110.       servo4Pos = dataInS.toInt();
  111.       if (servo4PPos > servo4Pos) {
  112.         for ( int j = servo4PPos; j >= servo4Pos; j--) {
  113.           servo04.write(j);
  114.           delay(30);
  115.         }
  116.       }
  117.       if (servo4PPos < servo4Pos) {
  118.         for ( int j = servo4PPos; j <= servo4Pos; j++) {
  119.           servo04.write(j);
  120.           delay(30);
  121.         }
  122.       }
  123.       servo4PPos = servo4Pos;
  124.     }
  125.     // Move Servo 5
  126.     if (dataIn.startsWith("s5")) {
  127.       String dataInS = dataIn.substring(2, dataIn.length());
  128.       servo5Pos = dataInS.toInt();
  129.       if (servo5PPos > servo5Pos) {
  130.         for ( int j = servo5PPos; j >= servo5Pos; j--) {
  131.           servo05.write(j);
  132.           delay(30);
  133.         }
  134.       }
  135.       if (servo5PPos < servo5Pos) {
  136.         for ( int j = servo5PPos; j <= servo5Pos; j++) {
  137.           servo05.write(j);
  138.           delay(30);
  139.         }
  140.       }
  141.       servo5PPos = servo5Pos;
  142.     }
  143.     // Move Servo 6
  144.     if (dataIn.startsWith("s6")) {
  145.       String dataInS = dataIn.substring(2, dataIn.length());
  146.       servo6Pos = dataInS.toInt();
  147.       if (servo6PPos > servo6Pos) {
  148.         for ( int j = servo6PPos; j >= servo6Pos; j--) {
  149.           servo06.write(j);
  150.           delay(30);
  151.         }
  152.       }
  153.       if (servo6PPos < servo6Pos) {
  154.         for ( int j = servo6PPos; j <= servo6Pos; j++) {
  155.           servo06.write(j);
  156.           delay(30);
  157.         }
  158.       }
  159.       servo6PPos = servo6Pos;
  160.     }
  161.     // If button "SAVE" is pressed
  162.     if (dataIn.startsWith("SAVE")) {
  163.       servo01SP[index] = servo1PPos;  // save position into the array
  164.       servo02SP[index] = servo2PPos;
  165.       servo03SP[index] = servo3PPos;
  166.       servo04SP[index] = servo4PPos;
  167.       servo05SP[index] = servo5PPos;
  168.       servo06SP[index] = servo6PPos;
  169.       index++;                        // Increase the array index
  170.     }
  171.     // If button "RUN" is pressed
  172.     if (dataIn.startsWith("RUN")) {
  173.       runservo();  // Automatic mode - run the saved steps
  174.     }
  175.     // If button "RESET" is pressed
  176.     if ( dataIn == "RESET") {
  177.       memset(servo01SP, 0, sizeof(servo01SP)); // Clear the array data to 0
  178.       memset(servo02SP, 0, sizeof(servo02SP));
  179.       memset(servo03SP, 0, sizeof(servo03SP));
  180.       memset(servo04SP, 0, sizeof(servo04SP));
  181.       memset(servo05SP, 0, sizeof(servo05SP));
  182.       memset(servo06SP, 0, sizeof(servo06SP));
  183.       index = 0;  // Index to 0
  184.     }
  185.   }
  186. }
  187. // Automatic mode custom function - run the saved steps
  188. void runservo() {
  189.   while (dataIn != "RESET") {   // Run the steps over and over again until "RESET" button is pressed
  190.     for (int i = 0; i <= index - 2; i++) {  // Run through all steps(index)
  191.       if (Bluetooth.available() > 0) {      // Check for incomding data
  192.         dataIn = Bluetooth.readString();
  193.         if ( dataIn == "PAUSE") {           // If button "PAUSE" is pressed
  194.           while (dataIn != "RUN") {         // Wait until "RUN" is pressed again
  195.             if (Bluetooth.available() > 0) {
  196.               dataIn = Bluetooth.readString();
  197.               if ( dataIn == "RESET") {     
  198.                 break;
  199.               }
  200.             }
  201.           }
  202.         }
  203.         // If speed slider is changed
  204.         if (dataIn.startsWith("ss")) {
  205.           String dataInS = dataIn.substring(2, dataIn.length());
  206.           speedDelay = dataInS.toInt(); // Change servo speed (delay time)
  207.         }
  208.       }
  209.       // Servo 1
  210.       if (servo01SP[i] == servo01SP[i + 1]) {
  211.       }
  212.       if (servo01SP[i] > servo01SP[i + 1]) {
  213.         for ( int j = servo01SP[i]; j >= servo01SP[i + 1]; j--) {
  214.           servo01.write(j);
  215.           delay(speedDelay);
  216.         }
  217.       }
  218.       if (servo01SP[i] < servo01SP[i + 1]) {
  219.         for ( int j = servo01SP[i]; j <= servo01SP[i + 1]; j++) {
  220.           servo01.write(j);
  221.           delay(speedDelay);
  222.         }
  223.       }
  224.       // Servo 2
  225.       if (servo02SP[i] == servo02SP[i + 1]) {
  226.       }
  227.       if (servo02SP[i] > servo02SP[i + 1]) {
  228.         for ( int j = servo02SP[i]; j >= servo02SP[i + 1]; j--) {
  229.           servo02.write(j);
  230.           delay(speedDelay);
  231.         }
  232.       }
  233.       if (servo02SP[i] < servo02SP[i + 1]) {
  234.         for ( int j = servo02SP[i]; j <= servo02SP[i + 1]; j++) {
  235.           servo02.write(j);
  236.           delay(speedDelay);
  237.         }
  238.       }
  239.       // Servo 3
  240.       if (servo03SP[i] == servo03SP[i + 1]) {
  241.       }
  242.       if (servo03SP[i] > servo03SP[i + 1]) {
  243.         for ( int j = servo03SP[i]; j >= servo03SP[i + 1]; j--) {
  244.           servo03.write(j);
  245.           delay(speedDelay);
  246.         }
  247.       }
  248.       if (servo03SP[i] < servo03SP[i + 1]) {
  249.         for ( int j = servo03SP[i]; j <= servo03SP[i + 1]; j++) {
  250.           servo03.write(j);
  251.           delay(speedDelay);
  252.         }
  253.       }
  254.       // Servo 4
  255.       if (servo04SP[i] == servo04SP[i + 1]) {
  256.       }
  257.       if (servo04SP[i] > servo04SP[i + 1]) {
  258.         for ( int j = servo04SP[i]; j >= servo04SP[i + 1]; j--) {
  259.           servo04.write(j);
  260.           delay(speedDelay);
  261.         }
  262.       }
  263.       if (servo04SP[i] < servo04SP[i + 1]) {
  264.         for ( int j = servo04SP[i]; j <= servo04SP[i + 1]; j++) {
  265.           servo04.write(j);
  266.           delay(speedDelay);
  267.         }
  268.       }
  269.       // Servo 5
  270.       if (servo05SP[i] == servo05SP[i + 1]) {
  271.       }
  272.       if (servo05SP[i] > servo05SP[i + 1]) {
  273.         for ( int j = servo05SP[i]; j >= servo05SP[i + 1]; j--) {
  274.           servo05.write(j);
  275.           delay(speedDelay);
  276.         }
  277.       }
  278.       if (servo05SP[i] < servo05SP[i + 1]) {
  279.         for ( int j = servo05SP[i]; j <= servo05SP[i + 1]; j++) {
  280.           servo05.write(j);
  281.           delay(speedDelay);
  282.         }
  283.       }
  284.       // Servo 6
  285.       if (servo06SP[i] == servo06SP[i + 1]) {
  286.       }
  287.       if (servo06SP[i] > servo06SP[i + 1]) {
  288.         for ( int j = servo06SP[i]; j >= servo06SP[i + 1]; j--) {
  289.           servo06.write(j);
  290.           delay(speedDelay);
  291.         }
  292.       }
  293.       if (servo06SP[i] < servo06SP[i + 1]) {
  294.         for ( int j = servo06SP[i]; j <= servo06SP[i + 1]; j++) {
  295.           servo06.write(j);
  296.           delay(speedDelay);
  297.         }
  298.       }
  299.     }
  300.   }
  301. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 5 小时前

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制
项目链接:https://howtomechatronics.com/tu ... smartphone-control/
项目作者: Dejan

项目视频 :https://www.youtube.com/watch?v=_B3gWd3A_SI
Arduino 机械臂控制 MIT App Inventor 项目文件:
https://howtomechatronics.com/tu ... one-control/#unlock
3D 文件:https://cults3d.com/en/3d-model/ ... m-howtomechatronics

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制图1

【Arduino 动手做】DIY Arduino 机器人手臂,带智能手机控制图2

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail