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.
5V
connected to the VCC Logic of SN754410 and leg2 of Rotary Potentiometer.GND
connected to the GND of SN754410, leg1 of Rotary Potentiometer, and NEG of the Barrel Jack.A0
connected to the wiper of the Rotary Potentiometer.D8
connected to 1 In of SN754410.D9
connected to 2 In of SN754410.D10
connected to 3 In of SN754410.D11
connected to 4 In of SN754410.A
connected to 1 Out of SN754410.B
connected to 3 Out of SN754410.C
connected to 2 Out of SN754410.D
connected to 4 Out of SN754410.1,2 Enable
, 3,4 Enable
, and VCC Logic
connected to 5V of Arduino UNO.GND
connected to GND of Arduino UNO.VCC Motor
connected to POS of the Barrel Jack.1 In
, 2 In
, 3 In
, 4 In
connected to corresponding pins D8, D9, D10, D11 on Arduino UNO.1 Out
, 2 Out
, 3 Out
, 4 Out
connected to corresponding leads A, B, C, D on Stepper Motor.leg1
connected to GND of Arduino UNO.wiper
connected to A0 of Arduino UNO.leg2
connected to 5V of Arduino UNO.POS
connected to VCC Motor of SN754410.NEG
connected to GND of Arduino UNO./*
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.