风筝
发表于: 2020-4-13 17:34:03 | 显示全部楼层

在本篇文章中,我们将学习如何使用摇杆和Arduino开发板控制步进电机的知识。在这里,我们将使用Arduino UNO开发板和PS2游戏杆控制步进电机的速度和旋转方向。


我们使用带有内部驱动器的单极5V DC步进电机28BYJ-48。因此,不需要任何步进电机驱动。相反,我们将使用ULN2003A达林顿双电机驱动器IC。 PS2游戏杆由两个10k欧姆的电位器组成,即一个用于X轴,另一个用于Y轴。它还包括一个按钮。但是我们将仅使用X轴来控制步进电机的运动。

Controlling-Stepper-Motor-with-Joystick-and-Arduino.jpg


所需的组件

●    Arduino UNO开发板

●    28BYJ-48 5V DC步进电机

●    ULN2003芯片

●    PS2游戏杆

●    5V DC电源


什么是步进电机


步进电动机(stepper motor)是一种无刷直流电动机,它将完整的全周长分为多个相等的步长。然后可以命令电机的位置移动并保持在其中一个步进,而无需任何位置传感器进行反馈(开环控制器),只要在转矩和速度方面仔细选择适合电动机尺寸的电动机即可。


步进电机28-BYJ48的连接方式

步进电动机28-BYJ48是一个具有5引线线圈布置的单极电动机。必须按特定顺序为四个线圈通电。红线连接到+ 5V电压,其余四根线将被拉到接地以触发相应的线圈。我们使用Arduino开发板以特定顺序为这些线圈通电,并使电动机执行所需的步数。


步进电机需要借助驱动器芯片才能进行操作。原因是控制器需要较高的电流才能运行,但是仅步进电机将无法从其I / O引脚提供足够的电流来使电机运行。因此使用ULN2003作为驱动模块,电流被放大了。


连接电路图

要使用摇杆和Arduino控制步进电机,请如下图所示组装电路。

Circuit-Diagram-2.png


步数计算

在将代码上传到Arduino板上之前需要进行步数计算


在Arduino中,我们将以4步顺序操作电机,因此需要计算步幅角(Stride Angle)。

步幅角= 5.625°

Arduino步骤顺序= 4

所需步骤顺序= 8

步数角度= 5.625 * 2 = 11.25

每转的步数= 360 /步角= 360 / 11.25 =每转32步。


源代码/程序:

  1. #include <Stepper.h>

  2. #define STEPS 32

  3. // define stepper motor control pins
  4. #define IN1 7
  5. #define IN2 6
  6. #define IN3 5
  7. #define IN4 4

  8. // initialize stepper library
  9. Stepper stepper(STEPS, IN4, IN2, IN3, IN1);

  10. // joystick pot output is connected to Arduino A0
  11. #define joystick A0

  12. void setup()
  13. {

  14. }

  15. void loop()
  16. {
  17. // read analog value from the potentiometer
  18. int val = analogRead(joystick);

  19. // if the joystic is in the middle ===> stop the motor
  20. if( (val > 500) && (val < 523) )
  21. {
  22. digitalWrite(IN1, LOW);
  23. digitalWrite(IN2, LOW);
  24. digitalWrite(IN3, LOW);
  25. digitalWrite(IN4, LOW);
  26. }

  27. else
  28. {
  29. // move the motor in the first direction
  30. while (val >= 523)
  31. {
  32. // map the speed between 5 and 500 rpm
  33. int speed_ = map(val, 523, 1023, 5, 500);
  34. // set motor speed
  35. stepper.setSpeed(speed_);

  36. // move the motor (1 step)
  37. stepper.step(1);

  38. val = analogRead(joystick);
  39. }

  40. // move the motor in the other direction
  41. while (val <= 500)
  42. {
  43. // map the speed between 5 and 500 rpm
  44. int speed_ = map(val, 500, 0, 5, 500);
  45. // set motor speed
  46. stepper.setSpeed(speed_);

  47. // move the motor (1 step)
  48. stepper.step(-1);

  49. val = analogRead(joystick);
  50. }

  51. }

  52. }
复制代码
跳转到指定楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题 700 | 回复: 1482



手机版|

GMT+8, 2024-4-29 11:01 , Processed in 0.042346 second(s), 6 queries , Gzip On, MemCache On. Powered by Discuz! X3.5

YiBoard一板网 © 2015-2022 地址:河北省石家庄市长安区高营大街 ( 冀ICP备18020117号 )

快速回复 返回顶部 返回列表