This circuit is designed to control a Nema 17 stepper motor using a DRV8825 stepper motor driver, with an Arduino UNO as the controlling microcontroller. Additionally, the circuit includes a DC motor controlled via a 5V 8-channel relay module, which is also interfaced with the Arduino UNO. A power supply unit provides the necessary power to the components.
// Pin assignments
const int stepPin = 3; // Stepper motor step
const int dirPin = 4; // Stepper motor direction
const int relayPin = 6; // Relay for DC motor
void setup() {
// Initialize stepper motor pins
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
// Initialize relay pin
pinMode(relayPin, OUTPUT);
// Set initial direction for the stepper
digitalWrite(dirPin, HIGH);
}
void loop() {
// Stepper motor control
for (int i = 0; i < 200; i++) { // 200 steps for one revolution (depends on your motor/driver)
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000); // Control speed by changing delay
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}
delay(1000); // Wait between revolutions
// DC motor control via relay
digitalWrite(relayPin, HIGH); // Turn on DC motor
delay(5000); // Run for 5 seconds
digitalWrite(relayPin, LOW); // Turn off DC motor
delay(1000); // Wait before next cycle
}
This code is designed to control the stepper motor and DC motor using the Arduino UNO. The stepPin
and dirPin
control the stepper motor's steps and direction, while the relayPin
controls the on/off state of the DC motor through the relay. The stepper motor makes one revolution by stepping 200 times, and the DC motor is turned on for 5 seconds and then turned off.