Circuit Documentation
Summary
This circuit involves an Arduino UNO microcontroller controlling a stepper motor and a micro servo. The Arduino UNO provides the necessary control signals to drive the stepper motor and the servo motor, enabling precise movement control.
Component List
Stepper Motor One
- Description: A stepper motor used for precise rotational control.
- Pins: IN1, IN2, IN3, IN4, +, -
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
Micro Servo 9G
- Description: A small servo motor used for precise angular control.
- Pins: GND, +5V, PWM
Wiring Details
Stepper Motor One
- Pin IN1: Connected to Arduino UNO pin D4
- Pin IN2: Connected to Arduino UNO pin D5
- Pin IN3: Connected to Arduino UNO pin D6
- Pin IN4: Connected to Arduino UNO pin D7
- Pin +: Connected to Arduino UNO pin 5V
- Pin -: Connected to Arduino UNO pin GND
Arduino UNO
- Pin 5V: Connected to Stepper Motor One pin + and Micro Servo 9G pin +5V
- Pin GND: Connected to Stepper Motor One pin - and Micro Servo 9G pin GND
- Pin D4: Connected to Stepper Motor One pin IN1
- Pin D5: Connected to Stepper Motor One pin IN2
- Pin D6: Connected to Stepper Motor One pin IN3
- Pin D7: Connected to Stepper Motor One pin IN4
- Pin D8: Connected to Micro Servo 9G pin PWM
Micro Servo 9G
- Pin GND: Connected to Arduino UNO pin GND
- Pin +5V: Connected to Arduino UNO pin 5V
- Pin PWM: Connected to Arduino UNO pin D8
Documented Code
#include <Stepper.h>
#include <Servo.h>
#define OUTPUT1 4
#define OUTPUT2 5
#define OUTPUT3 6
#define OUTPUT4 7
Servo servo;
const int stepsPerRotation = 2048; //
Stepper myStepper(stepsPerRotation, OUTPUT1, OUTPUT3, OUTPUT2, OUTPUT4);
void setup() {
servo.attach(8);
servo.write(90);
myStepper.setSpeed(15); // RPM (Round Per Minute)
}
void loop() {
myStepper.step(stepsPerRotation);
delay(500);
servo.write(0);
delay(500);
myStepper.step(-stepsPerRotation);
delay(500);
servo.write(180);
delay(500);
}
This code initializes the stepper motor and the servo motor. In the setup function, the servo is attached to pin 8 and set to a neutral position (90 degrees). The stepper motor speed is set to 15 RPM. In the loop function, the stepper motor rotates one full rotation in one direction, pauses, then rotates one full rotation in the opposite direction, with the servo moving between 0 and 180 degrees in between each stepper motor movement.
