Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Controlled Stepper Motor with Potentiometer Feedback

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Stepper Motor with Potentiometer Feedback

Circuit Documentation

Summary

This circuit is designed to control a bipolar stepper motor using an Arduino UNO microcontroller. The motor's rotation is determined by the position of a rotary potentiometer. The Arduino reads the potentiometer's value and translates it into motor steps. A motor driver IC, the SN754410, is used to amplify the Arduino's control signals to drive the stepper motor. Power is supplied through a 2.1mm Barrel Jack with Terminal Block.

Component List

Arduino UNO

Stepper Motor (Bipolar)

SN754410

Rotary Potentiometer

2.1mm Barrel Jack with Terminal Block

Wiring Details

Arduino UNO

Stepper Motor (Bipolar)

SN754410

Rotary Potentiometer

2.1mm Barrel Jack with Terminal Block

Documented Code

/*
  Sketch to control a stepper motor with a potentiometer.
  A stepper motor follows the turns of a potentiometer (or other sensor) on analog input 0.
*/

#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(30);
}

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;
}

This code is designed to run on the Arduino UNO. It initializes the stepper motor with the specified number of steps and sets the motor speed. In the loop, it reads the analog value from the potentiometer connected to A0, calculates the difference from the previous reading, and moves the stepper motor accordingly. The previous sensor value is updated at the end of each loop iteration.