مشروع فتح و اغلاق الباب الكراج او النافدة بمحرك | Stepper Motor | باستخدام |Joystick | Arduino UNO - DIY Channel3

DIY Channel3

Arduino│ESP8266│ESP32│Drone│Robot

مشروع فتح و اغلاق الباب الكراج او النافدة بمحرك | Stepper Motor | باستخدام |Joystick | Arduino UNO

مشاركة هذا

 



المكونات الاساسية :


- Arduino UNO

- 28BYJ-48 stepper motor (with ULN2003A driver board)

- Bread board

-  joystick 

- 5V power source

- Jumper wires





++ مخطط الرسم البياني :



++ الكود البرمجي هنا :

// include Arduino stepper motor library
#include <Stepper.h>
 
// define number of steps per revolution
#define STEPS 32
 
// define stepper motor control pins
#define IN1  11
#define IN2  10
#define IN3   9
#define IN4   8
 
// initialize stepper library
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
 
// joystick pot output is connected to Arduino A0
#define joystick  A0
 
void setup()
{
  
}
 
void loop()
{
  // read analog value from the potentiometer
  int val = analogRead(joystick);
 
  // if the joystic is in the middle ===> stop the motor
  if(  (val > 500) && (val < 523) )
  {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
  }
 
  else
  {
    // move the motor in the first direction
    while (val >= 523)
    {
      // map the speed between 5 and 500 rpm
      int speed_ = map(val, 523, 1023, 5, 500);
      // set motor speed
      stepper.setSpeed(speed_);
 
      // move the motor (1 step)
      stepper.step(1);
 
      val = analogRead(joystick);
    }
 
    // move the motor in the other direction
    while (val <= 500)
    {
      // map the speed between 5 and 500 rpm
      int speed_ = map(val, 500, 0, 5, 500);
      // set motor speed
      stepper.setSpeed(speed_);
 
      // move the motor (1 step)
      stepper.step(-1);
 
      val = analogRead(joystick);
    }
 
  }
 
}

#arduino #raspberrypi #electronics #arduinoproject #robotics #technology #engineering #arduinouno #robot #iot #diy #electrical #maker #programming #electronic #microcontroller #arduinoprojects #tech #esp #pcb #arduinomega #d #electricalengineering #robotica #diyelectronics #project #coding #arduinofun #sensor

No comments:

Post a Comment