I made a watchwinder with using 28 BYJ-48 Geared Step Motor and ULN2003A Step Motor Driver Board and aurdino nano card.
code working well but when it's working step motor heats so much and melting my 3D printed arm.
do you have any suggestion to solve heating problem?
please find my code and wiring at below.
thanks in advance,
//-----Button variables
const int ledPin = 5; // LED pin number
const int buttonPin = 4; // Button NO pin number
int buttonState = 0; // Button state
// Step motor variables
#define IN1 11 // Motor
#define IN2 10 // Driver
#define IN3 9 // Pin
#define IN4 8 // Connections
unsigned long startTime = 0; // Motor start time
unsigned long motorDuration = 7200000; // 2-hour operation duration
unsigned long waitTime = 5000; // Wait time after turning left or right (5 seconds)
int currentStep = 0; // Current step of the motor
bool motorRunning = false; // Variable to track if the motor is running
bool clockwise = true; // Rotation direction (clockwise or counterclockwise)
void setup() {
Serial.begin(9600);
Serial.println("Connection Established");
// Button pin configuration
pinMode(ledPin, OUTPUT); // Set LED pin as output
pinMode(buttonPin, INPUT_PULLUP); // Set button pin as input with internal pull-up resistor
// Step motor pin configuration
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// Initially disable the motor
DisableMotor();
}
void loop() {
buttonState = digitalRead(buttonPin); // Read from button pin
// Start or stop the motor when the button is pressed
if (buttonState == LOW && !motorRunning) { // If button is pressed and motor is not running
motorRunning = true;
startTime = millis(); // Start the timer
currentStep = 0; // Reset steps
clockwise = true; // Initially rotate clockwise
digitalWrite(ledPin, LOW); // Turn off the LED
} else if (buttonState == HIGH && motorRunning) {
motorRunning = false;
DisableMotor(); // Disable the motor
digitalWrite(ledPin, HIGH); // Turn on the LED
}
if (motorRunning) {
unsigned long currentTime = millis();
if (currentTime - startTime < motorDuration) { // If motor operation time has not expired
RotateMotor360(clockwise); // Rotate 360 degrees
delay(waitTime); // Wait for 1 second
DisableMotor(); // Disable the motor during waiting
clockwise = !clockwise; // Change the direction
} else { // If motor operation time has expired
motorRunning = false;
DisableMotor(); // Disable the motor
digitalWrite(ledPin, HIGH); // Turn on the LED
Serial.println("Motor stopped");
}
}
}
// Function to rotate the step motor 360 degrees
void RotateMotor360(bool clockwise) {
int stepsPerRevolution = 4096; // 512 steps for 360 degrees
for (int i = 0; i < stepsPerRevolution; i++) {
StepMotor(clockwise); // Perform a single step
delay(2); // Short delay between each step
}
}
// Function for a single step of the step motor
void StepMotor(bool clockwise) {
if (clockwise) {
switch (currentStep) {
case 0: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break;
case 1: digitalWrite(IN1, HIGH); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break;
case 2: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break;
case 3: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break;
case 4: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break;
case 5: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, HIGH); break;
case 6: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break;
case 7: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break;
}
} else { // Counterclockwise rotation
switch (currentStep) {
case 0: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break;
case 1: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break;
case 2: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, HIGH); break;
case 3: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break;
case 4: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break;
case 5: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break;
case 6: digitalWrite(IN1, HIGH); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break;
case 7: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break;
}
}
currentStep = (currentStep + 1) % 8; // Cycle through steps from zero
}
// Function to disable the motor
void DisableMotor() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
