التحكم في المحرك الخطوى باستخدام الاردوينو

إذا كنت تريد التحكم في محرك بدقة فإن أحد أفضل الحلول هو استخدام المحرك الخطوى. هذا النوع من المحركات يوفر لك تحكمًا دقيقًا في موضع عمود المحرك وسرعته وتسارعه واتجاهه، ولهذا السبب يسمي بالمحرك الخطوى.



مقدمة


في هذا الدرس سوف نستخدم الاردوينو مع وحدة تشغيل المحرك للتحكم في المحرك الخطوى حيث سنجعله يتحرك في اتجاه معين وبسرعة محددة.


يستخدم هذا النوع من المحركات في العديد من الأجهزة التي قد تستخدمها في حياتك اليومية، مثل الماسحات الضوئية والطابعات ثلاثية الأبعاد وحتى الروبوتات.


الحصول علي القطع


ستحتاج إلى المكونات التالية لهذا المشروع، يمكنك شراؤها من متجر ڤولتات.

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat 5V DC Stepper Motor & Drive Module
25 QAR
Sale Off
Voltaat Jumper Wires - Male to Female (40 Pack)
10 QAR

التوصيل


توضح الصورة التالية كيفية توصيل الأسلاك بين المحرك الخطوى والاردوينو. بمجرد توصيل المحرك الخطوى ووحدة تشغيل المحرك والاردوينو ببعضهما البعض، قم بتوصيل الاردوينو بجهاز الكمبيوتر الخاص بك باستخدام وصلة USB.



التوصيلات من سائق المحرك إلي الاردوينو:

• Arduino GND pin ← Motor driver GND pin (- pin)

• Arduino 5V pin ← Motor driver VCC pin (+ pin)

• Arduino pin 11 ← Motor driver IN1 pin

• Arduino pin 10 ← Motor driver IN2 pin

• Arduino pin 9 ← Motor driver IN3 pin

• Arduino pin 8 ← Motor driver IN4 pin


تأكد من توصيل الـ Jumper pin بسائق المحرك لتشغيله كما هو موضح في الصورة، ثم قم بتوصيل كابل المحرك.


برمجة الاردوينو


وظيفة نص البرمجة هذا هي التحكم في المحرك الخطوى لكي يتحرك في اتجاه واحد بسرعة 1000 خطوة في الثانية وبتسارع 200. سيتحرك تسع دورات كاملة، ثم يعكس اتجاهه ويكرر الحركة مرة اخري.


حتى تتمكن من تحميل نص البرمجة بدون أخطاء، تحتاج إلى تنزيل بعض المكتبات. المكتبات عبارة عن ملفات يمكنك تنزيلها ونسخها إلى ملفات برنامج Arduino IDE حتى يتمكن الاردوينو من التعرف على أجهزة الاستشعار المختلفة. يمكنك تنزيل ملفات المكتبة من قسم المصادر ثم تثبيتها باتباع هذا الدرس التعليمي.


Stepper library

AccelStepper library


يمكنك تغيير بعض القيم المحددة في نص البرمجة بنفسك واختبار سلوك المحرك.


ما رأيك في أفضل تطبيق لهذا البرنامج؟


دعونا نختبره معًا!


/*
/*ttp://learn.voltaat.com)
Link for full tutorial: https://bit.ly/3Vg0div
Stepper library: https://bit.ly/3fmyAoG
AccelStepper library: https://bit.ly/3UeaR97

Tutorial: Control stepper motor with Arduino

This sketch function is to control the stepper motor
to move in one direction at a speed of 1000 steps per second
and an acceleration of 200 steps per second square for 9 revolutions,
then reverse its direction and repeat the movement

Connections from the motor driver to the Arduino:
• Motor driver GND pin (- pin) → Arduino GND pin
• Motor driver VCC pin (+ pin) → Arduino 5V pin
• Motor driver IN1 pin → Arduino pin 11
• Motor driver IN2 pin → Arduino pin 10
• Motor driver IN3 pin → Arduino pin 9
• Motor driver IN4 pin → Arduino pin 8
*/

//Include the Arduino Stepper.h library
#include < Stepper.h >
//Include the AccelStepper library
#include < AccelStepper.h >

//Define the motor pins
//IN1 on the motor driver
#define MP1  11
//IN2 on the motor driver
#define MP2  10
//IN3 on the motor driver
#define MP3  9
//IN4 on the motor driver
#define MP4  8

//Define the interface type
#define MotorInterfaceType 8
//Define the pin sequence (IN1-IN3-IN2-IN4)
AccelStepper stepper = AccelStepper(MotorInterfaceType, MP1, MP3, MP2, MP4);
constint SPR = 2048;//Steps per revolution

//Commands inside void setup run once
void setup(){
  //Set the maximum motor speed in steps per second
  stepper.setMaxSpeed(1000);
  //Set the maximum acceleration in steps per second^2
  stepper.setAcceleration(200);
}

//Commands inside void loop run forever
void loop(){
  //Set the target motor position (9 full revolutions)
  stepper.moveTo(9 * SPR);
  //Run the motor to the target position
  stepper.runToPosition();
  //delay for 1 sec
  delay(1000);
  //Set the target motor position (9 full revolutions but in opposite direction)
  stepper.moveTo(-9 * SPR);
  // Run the motor to the target position
  stepper.runToPosition();
  //delay for 1 sec
  delay(1000);
}

قم باختباره



بعد تحميل نص البرمجة على لوحة الاردوينو الخاصة بك، ستلاحظ أن المحرك الخطوى يدور ببطء ويقوم بتسع دورات في اتجاه معين قبل أن يغير الاتجاه ويقوم بتكرار الحركة.


ستومض مصابيح الـ LED الخاصة بمشغل المحرك أيضًا في استجابة للإشارات المرسلة منه إلى المحرك.


يمكنك تغيير عدد الدورات وقيمة التسارع والسرعة في الكود بالقيمة التي تحتاجها وتناسب مشروعك.


المصادر


Arduino Code

Stepper Library

AccelStepper Library

Fritzing Wiring file

دروس أخري


A servo motor is just a simple DC motor with certain modifications. When you look at it, you'll notice that it has several gears and an electronic circuit.


In this tutorial, we will learn how to use a PNP transistor to operate a DC motor. It will provide the motor with the necessary power.


In this tutorial, we will learn more about bush buttons and how to use them. We'll use the push button in a simple project to control the Arduino's internal LED and print the current state of the button directly on your commuter.