понедельник, 13 января 2014 г.

Управление моторчиком 28BYJ-48

Схема включения нарисована тут. А тут - ближе к реальности.

Если посмотреть распайку платы, на которой установлена микросхема ULN2003AN, то становится понятно, что к Arduino подключаем так:
ArduinoDriver board
8IN1
9IN2
10IN3
11IN4
GND-
5V+


Пример взял стандартный из IDE (MotorKnob), добавил только секундную задержку, иначе из-за нестабильности сигнала на аналоговом входе плохо прослеживается зависимость.
/*
 * MotorKnob
 *
 * A stepper motor follows the turns of a potentiometer
 * (or other sensor) on analog input 0.
 *
 * http://www.arduino.cc/en/Reference/Stepper
 * This example code is in the public domain.
 */

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

// the previous reading from the analog input
int previous = 0;

void setup()
{
  // set the speed of the motor to 30 RPMs
  stepper.setSpeed(60);
}

void loop()
{
  // get the sensor value
  int val = analogRead(0);

  // move a number of steps equal to the change in the
  // sensor reading
  stepper.step(val - previous);

  // remember the previous value of the sensor
  previous = val;
  delay(1000);
}

Вот что получилось.

Тут видно, что скорость вращения низкая. Видимо, питание надо давать не с платы, а от другого источника. Ещё, когда разбирал схему, обратил внимание, что моторчик прилично нагрелся, хотя он у меня почти не крутился.

Комментариев нет:

Отправить комментарий