Code working but stepper motor getting hot

Hello guys,

I’ve hacked my coffee machine to be voice activated using IR and Snips, it works well but I have a small issue that I can’t seem to understand.

My stepper motor (that select the coffee intensity) is during the setup going both way just to make sure it is at the right position. Then it gets hot. It means that two or more motor magnet must remain powered by the power supply. Should I add something on my code to put the stepper at 0 when it isn’t received a command?

Thanks a lot

#include <ir_Lego_PF_BitStreamEncoder.h>
#include <boarddefs.h>
#include <IRremoteInt.h>
#include <IRremote.h>


#include <Wire.h>
#include <Stepper.h>

#define STEPS 64

int in1 = 6;
int in2 = 7; // x2_l
int in3 = A5; // x1_l
int in4 = A4; // vape
int in5 = A3; // clean
int in6 = A2; // x2_s
int in7 = A1; //x1_s
int in8 = A0; // on off
Stepper stepper(STEPS, 5, 3, 4, 2);

long vape = 0xFFBA45;
long clean = 0xFF827D;
long onoff = 0xFF02FD;

long x1_short = 0xFF22DD;
long x2_short = 0xFF12ED;
long x1_long = 0xFF32CD;
long x2_long = 0xFFF807;

long x1_short_m = 0xFFA25D;
long x2_short_m = 0xFF926D;
long x1_long_m = 0xFFB24D;
long x2_long_m = 0xFF7887;

long x1_short_l = 0xFF9A65;
long x2_short_l = 0xFFAA55;
long x1_long_l = 0xFF8A75;
long x2_long_l = 0xFFB847;

int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results result;

void turn_left(int v) {
  Serial.println("turn left\n");
  if (v == 0)
    return;
  if (v == 1)
    return;
  if (v == 2)
    stepper.step(-300);

  if (v == 3)
    stepper.step(-500);

  delay(1000);
}
void turn_right(int v) {
  Serial.println("turn right\n");
  if (v == 0)
    return;
  if (v == 1)
    return;

  if (v == 2)
    stepper.step(300);
  if (v == 3)
    stepper.step(500);

  delay(1000);

}

void touch_button(int pin) {
  digitalWrite(pin, LOW);
  Serial.print(" touchdown\n");
  delay(1000);
  digitalWrite(pin, HIGH);
}

void pour(int number, int size_c, int intensity) {

  if (number == 0)
    return;

  turn_left(intensity);
  delay(1000);
  if (number == 1)
  {
    if (size_c == 1)
      touch_button(in7);
    else
      touch_button(in3);
  } else {
    if (size_c == 1)
      touch_button(in6);
    else {
      touch_button(in2);
    }
  }
  delay(200);
  turn_right(intensity);
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  stepper.setSpeed(200);
  stepper.step(0);
  pinMode(in1, OUTPUT);
  digitalWrite(in1, HIGH);
  pinMode(in2, OUTPUT);
  digitalWrite(in2, HIGH);
  pinMode(in3, OUTPUT);
  digitalWrite(in3, HIGH);
  pinMode(in4, OUTPUT);
  digitalWrite(in4, HIGH);
  pinMode(in5, OUTPUT);
  digitalWrite(in5, HIGH);
  pinMode(in6, OUTPUT);
  digitalWrite(in6, HIGH);
  pinMode(in7, OUTPUT);
  digitalWrite(in7, HIGH);
  pinMode(in8, OUTPUT);
  digitalWrite(in8, HIGH);
  Serial.println("Ready!");
  turn_left(2);
  turn_right(2);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (irrecv.decode(&result))
  {
    Serial.println(result.value, HEX);
    if (result.value == onoff) {
      Serial.print("toto");
      touch_button(in8);
      irrecv.resume();
      return;
    }
    if (result.value == vape) {
      touch_button(in4);
      irrecv.resume();
      return;
    }
    if (result.value == clean) {
      touch_button(in5);
      irrecv.resume();
      return;
    }
    int number = 0;
    int size_c = 0;
    int intensity = 0;
    if (result.value == x1_short)
    {
      number = 1;
      size_c = 1;
      intensity = 1;
    }
    if (result.value == x2_short)
    {
      number = 2;
      size_c = 1;
      intensity = 1;
    }
    if (result.value == x1_long)
    {
      number = 1;
      size_c = 2;
      intensity = 1;
    }
    if (result.value == x2_long)
    {
      number = 2;
      size_c = 2;
      intensity = 1;
    }

    if (result.value == x1_short_m)
    {
      number = 1;
      size_c = 1;
      intensity = 2;
    }
    if (result.value == x2_short_m)
    {
      number = 2;
      size_c = 1;
      intensity = 2;
    }
    if (result.value == x1_long_m)
    {
      number = 1;
      size_c = 2;
      intensity = 2;
    }
    if (result.value == x2_long_m)
    {
      number = 2;
      size_c = 2;
      intensity = 2;
    }

    if (result.value == x1_short_l)
    {
      number = 1;
      size_c = 1;
      intensity = 3;
    }
    if (result.value == x2_short_l)
    {
      number = 2;
      size_c = 1;
      intensity = 3;
    }
    if (result.value == x1_long_l)
    {
      number = 1;
      size_c = 2;
      intensity = 3;
    }
    if (result.value == x2_long_l)
    {
      number = 2;
      size_c = 2;
      intensity = 3;
    }
    //coffee setup
    pour(number, size_c, intensity);
    irrecv.resume(); // Receive the next value
  }
}

It is normal for stepper motors to be hot - often uncomfortable to touch.

Post a link to the datasheet for your motor and tell us what stepper motor driver you are using and what power supply you are using.

...R

Thanks for your response,

hmm Yes and no, IMO it shouldn’t be hot when it’s not running. I mean its just waiting for its order so its shouldn’t be receiving any voltage.

I’m using a basic stepper: Small Reduction Stepper Motor - 5VDC 32-Step 1/64 Gearing : ID 858 : $4.95 : Adafruit Industries, Unique & fun DIY electronics and kits
and a 5V 2.5A power supply (the same than for a Raspberry pi), for the driver I’m using this library: #include <Stepper.h>

The + of the power supply is powering both the PI nano, the 8 relay boards and the stepper. The GND are common.

I think the issue is coming from my code, I should put the stepper OFF while waiting for a new command but I’m not sure on how to do that.

thanks

noxxsound:
I mean its just waiting for its order so its shouldn't be receiving any voltage.

That's not how stepper motors work. They must draw the full current even when stationary if they are not to lose their position.

Of course if you don't care about the position you can write all the outputs as LOW and de-power the motor. However don't assume it will be in the exact same position next time it powers up. Even if you don't physically touch the motor shaft it may re-start at the next or previous step position when the coils are re-energized.

...R

Oh I see, that makes more sense, thanks for your clarification.

Well on my case, it shouldn't be an issue if it start one step before or after since one step is almost negligible for the coffee intensity, I'd rather have it start +/- 1 step than getting too hot and leaving my coffee machine powered on for days and nights ...

I'll put all those concerned outputs LOW.

thanks

noxxsound:
Well on my case, it shouldn’t be an issue if it start one step before or after

Just keep an eye on things to ensure that you don’t get an accumulation of errors that would have a significant effect.

If the motors are homed every time the Arduino starts that will go a long way to eliminating that risk.

…R

I used a P-channel MOSFET to do it.
http://ww1.microchip.com/downloads/en/DeviceDoc/VP2206%20E082313.pdf
vp2206.png

What kind of motor driver are you using? If you use a stepper motor driver, you can often adjust the maximum current, and, therefore, the temperature of the motor.

He's using the modified Adafruit 28BYJ-48 that has about 513 full steps per rev (and I assume a ULN2803).