NEMA 17 digital switch (MOSFET ?)

Hi,

I have a 12v NEMA 17 motor controlled with a A4988 driver and a NodeMCU esp8266. I noticed that when the power is on, the motor always produces noise and presumably consumes energy. So I think the right thing to do would be to power the motor only when I need it.

I have some N-channel Mosfet transistors (IRFZ44N if that's useful) that I used to control a 12v light strip, could I use one of those as a switch for my motor ? Thanks.

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post links to spec/data of your stepper NEMA17 give very little information.

Thanks.. Tom.. :slight_smile:

Why not use the enable input to the A4988?

When set to a logic high, the outputs are disabled.

Page 10 of the A4988 data sheet.

Thanks for you replies. I've never drew schematics so I've downloaded Fritzing, it's not great but it took me an hour so I'll post it :smiley:

groundFungus, if I understand correctly I need to connect the Enable input to a GPIO pin and write in the code something like:

digitalWrite(enablePin,HIGH);

and then LOW when I need to use the motor ?

Here is my full code, it's work in progress.

Thanks.

Edit: the motor I'm using is a 17HS4401S

#include <ESP8266WiFi.h>


// NEMA17 Pins
const int stepPin = 0; 
const int dirPin = 4; 
 
const char* ssid = "SSID";
const char* password = "password";

// LED Pin
int ledPin = 2; // GPIO2---D4 of NodeMCU
WiFiServer server(80);
 
void setup() {
  Serial.begin(115200);
  delay(10);

  //Stepper
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);

  //LED
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1)  {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
    OpenDoor();
    delay(3000);
    CloseDoor();
    digitalWrite(ledPin, LOW);
    value = LOW;
  }
  if (request.indexOf("/LED=OFF") != -1)  {
    digitalWrite(ledPin, LOW);
    value = LOW;
  }
 
// Set ledPin according to the request
//digitalWrite(ledPin, value);
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
 
  client.print("Led is now: ");
 
  if(value == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }
  client.println("

");
  client.println("<a href=\"/LED=ON\"\"><button>On </button></a>");
  client.println("<a href=\"/LED=OFF\"\"><button>Off </button></a>
");  
  client.println("</html>");
 
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
 
}

void OpenDoor() 
{
  digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x < 300; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(500); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(500); 
  }
}

void CloseDoor() 
{
  digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x < 300; x++) {
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(500); 
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(500); 
  }
}

Hi,
A fritzy picture is not a circuit diagram unfortunately.
It does not label pin names or show the real symbols for the components used.

For example,
What is your power supply (spec)?
What is your stepper(spec)?
What connections are made to the stepper control PCB?

Tom.. :slight_smile:

Note that if you power down a stepper other than at a multiple of 4 full steps it will lose position on reapplying power. You'll need to check if the enable pin to the A4988 clears the step count internally or not.

Also a stepper powered off won't have very much torque to keep it in position if the load is trying to turn it.

Its a very common strategy with steppers to drop the current to about half when its stationary and idle, as
that reduces power consumption in the motor by a factor of 4. However to do this you need a breakout board
that allows the current setpoint to be dynamically changed.