#include <Stepper.h>
// Define the number of steps per revolution for your motor
const int stepsPerRevolution = 2048; // For 28BYJ-48 stepper motor
// Create an instance of the Stepper class
Stepper myStepper(stepsPerRevolution, 27, 26, 25, 33); // IN1, IN2, IN3, IN4
// Define the relay pin
const int relayPin = 14;
void setup() {
// Set up the relay pin as an output
pinMode(relayPin, OUTPUT);
// Initialize the stepper motor speed
myStepper.setSpeed(10); // Set speed to 10 RPM
// Begin serial communication
Serial.begin(115200);
}
void loop() {
// Example: Turn the relay ON for 5 seconds, then OFF for 5 seconds
Serial.println("Relay ON");
digitalWrite(relayPin, HIGH); // Turn the relay on
delay(5000); // Wait for 5 seconds
Serial.println("Relay OFF");
digitalWrite(relayPin, LOW); // Turn the relay off
delay(5000); // Wait for 5 seconds
// Example: Rotate the stepper motor clockwise for one revolution
Serial.println("Stepper Motor: Clockwise");
myStepper.step(stepsPerRevolution); // Move one full revolution clockwise
delay(2000); // Wait for 2 seconds
// Example: Rotate the stepper motor counterclockwise for one revolution
Serial.println("Stepper Motor: Counterclockwise");
myStepper.step(-stepsPerRevolution); // Move one full revolution counterclockwise
delay(2000); // Wait for 2 seconds
}