-->
Page 1 of 1

NodeMCU automated blinds project problem

PostPosted: Mon May 17, 2021 5:26 am
by drharvey
Hi!

I am trying to build automated motorized blinds using NodeMCU and NEMA17 motor, however, something's definitely not right since I've burned two NodeMCU boards so far. The circuit would work for some time (losing wifi connection quite often) and then after running it for several hours it would get hot and I'm not able to connect to it using my computer anymore.

Below is a diagram showing my setup and a code I've used to control it. Can someone please help me out and tell me if they see any mistakes in my setup?

Image

Code: Select all/*****************************************************
 * Date: 9 july 2018
 * Written by: Usman Ali Butt
 * Property off: microcontroller-project.com
 * ***************************************************/
#include <ESP8266WiFi.h>
 
const char* ssid = "MissionControl";
const char* password = "Apollo11";

int Step = 5; //D1 of Nodemcu--Step of stepper motor driver
int Dir  = 4; //D2---D4 of Nodemcu--Direction of stepper motor driver
#define sleepPin 14 //D5
#define M2 12 //D6
#define M1 13 //D7
WiFiServer server(80);
 
void setup() {
  Serial.begin(115200);
  delay(10);
 pinMode(Step, OUTPUT); //Step pin as output
 pinMode(Dir,  OUTPUT); //Direcction pin as output
 pinMode(sleepPin, OUTPUT);
 pinMode(M2, OUTPUT);
 pinMode(M1, OUTPUT);
 digitalWrite(Step, LOW); // Currently no stepper motor movement
 digitalWrite(Dir, LOW); 
  digitalWrite(sleepPin, LOW);
  digitalWrite(M2, HIGH);
  digitalWrite(M1, HIGH);
 
 
  //digitalWrite(enablePin, 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 on serial monitor
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");    //URL IP to be typed in mobile/desktop browser
  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 i=0;
  int value = LOW;
 
  if (request.indexOf("/Command=forward") != -1)  { //Move 50 steps forward
    digitalWrite(sleepPin, HIGH);
    digitalWrite(Dir, HIGH); //Rotate stepper motor in clock wise direction
          for( i=1;i<=89600;i++){
          digitalWrite(Step, HIGH);
          delay(1);
          digitalWrite(Step, LOW);
          delay(1);}
    value = HIGH;
    digitalWrite(sleepPin, LOW);
  }
 
  if (request.indexOf("/Command=backward") != -1)  { //Move 50 steps backwards
   digitalWrite(sleepPin, HIGH);
    digitalWrite(Dir, LOW); //Rotate stepper motor in anti clock wise direction
          for( i=1;i<=96000;i++){
          digitalWrite(Step, HIGH);
          delay(1);
          digitalWrite(Step, LOW);
          delay(1);}
    value = LOW;
    digitalWrite(sleepPin, LOW);
  }

  // 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.println("<h1 align=center>Stepper motor controlled over WiFi</h1><br><br>");
  client.print("Stepper motor moving= ");
 
  if(value == HIGH) {
    client.print("Forward");
  } else {
    client.print("Backward");
  }
  client.println("<br><br>");
  client.println("<a href=\"/Command=forward\"\"><button>Forward </button></a>");
  client.println("<a href=\"/Command=backward\"\"><button>Backward </button></a><br />"); 
  client.println("</html>");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
 
}