VNH2SP30 Motor Drive with using WIFI HTTP or Blynk

Hi Everyone ,

I am a beginner about software developer so I don’t have much experience these issues (Ardunio IDE languages and other software languages)

I need some help. I want to control my dc motor with wifi (html button or bylnk). I use 12V DC motor, VNH2SP30 motor driver and Nodemcu (ESP8266-12E). I found same code in " https://www.instructables.com/id/Tutorial-for-VNH2SP30-Monster-Motor-Module-Single-/" . It works with ardunio but I would like use nodemcu because controlling my motor speed and start/stop with my mobile phone. I know that I have to use logical converter from 3.3V to 5V for motor driver.

How can I control my dc motor html code or blynk ?

This example uses Serial.println and I can control dc motor with serial monitor as below,

Serial.begin(9600); // Initiates the serial to do the monitoring
Serial.println(“Begin motor control”);
Serial.println(); //Print function list for user selection
Serial.println(“Enter number for control option:”);
Serial.println(“1. STOP”);
Serial.println(“2. FORWARD”);
Serial.println(“3. REVERSE”);
Serial.println("+. INCREASE SPEED");
Serial.println("-. DECREASE SPEED");
Serial.println();

I would like to control dc motor web page instead of serial monitor.

This code like this ,

#define BRAKE 0
#define CW 1
#define CCW 2
#define CS_THRESHOLD 15 // Definition of safety current (Check: “1.3 Monster Shield Example”).

//MOTOR 1
#define MOTOR_A1_PIN 7
#define MOTOR_B1_PIN 8

#define PWM_MOTOR_1 5

#define CURRENT_SEN_1 A2

#define EN_PIN_1 A0

#define MOTOR_1 0

short usSpeed = 150; //default motor speed
unsigned short usMotor_Status = BRAKE;

void setup()
{
pinMode(MOTOR_A1_PIN, OUTPUT);
pinMode(MOTOR_B1_PIN, OUTPUT);

pinMode(PWM_MOTOR_1, OUTPUT);

pinMode(CURRENT_SEN_1, OUTPUT);

pinMode(EN_PIN_1, OUTPUT);

Serial.begin(9600); // Initiates the serial to do the monitoring
Serial.println(“Begin motor control”);
Serial.println(); //Print function list for user selection
Serial.println(“Enter number for control option:”);
Serial.println(“1. STOP”);
Serial.println(“2. FORWARD”);
Serial.println(“3. REVERSE”);
Serial.println("+. INCREASE SPEED");
Serial.println("-. DECREASE SPEED");
Serial.println();

}

void loop()
{
char user_input;

while(Serial.available())
{
user_input = Serial.read(); //Read user input and trigger appropriate function
digitalWrite(EN_PIN_1, HIGH);

if (user_input ==‘1’)
{
Stop();
}
else if(user_input ==‘2’)
{
Forward();
}
else if(user_input ==‘3’)
{
Reverse();
}
else if(user_input ==’+’)
{
IncreaseSpeed();
}
else if(user_input ==’-’)
{
DecreaseSpeed();
}
else
{
Serial.println(“Invalid option entered.”);
}

}
}

void Stop()
{
Serial.println(“Stop”);
usMotor_Status = BRAKE;
motorGo(MOTOR_1, usMotor_Status, 0);
}

void Forward()
{
Serial.println(“Forward”);
usMotor_Status = CW;
motorGo(MOTOR_1, usMotor_Status, usSpeed);
}

void Reverse()
{
Serial.println(“Reverse”);
usMotor_Status = CCW;
motorGo(MOTOR_1, usMotor_Status, usSpeed);
}

void IncreaseSpeed()
{
usSpeed = usSpeed + 10;
if(usSpeed > 255)
{
usSpeed = 255;
}

Serial.print("Speed +: ");
Serial.println(usSpeed);

motorGo(MOTOR_1, usMotor_Status, usSpeed);
}

void DecreaseSpeed()
{
usSpeed = usSpeed - 10;
if(usSpeed < 0)
{
usSpeed = 0;
}

Serial.print("Speed -: ");
Serial.println(usSpeed);

motorGo(MOTOR_1, usMotor_Status, usSpeed);
}

void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm) //Function that controls the variables: motor(0 ou 1), direction (cw ou ccw) e pwm (entra 0 e 255);
{
if(motor == MOTOR_1)
{
if(direct == CW)
{
digitalWrite(MOTOR_A1_PIN, LOW);
digitalWrite(MOTOR_B1_PIN, HIGH);
}
else if(direct == CCW)
{
digitalWrite(MOTOR_A1_PIN, HIGH);
digitalWrite(MOTOR_B1_PIN, LOW);
}
else
{
digitalWrite(MOTOR_A1_PIN, LOW);
digitalWrite(MOTOR_B1_PIN, LOW);
}

analogWrite(PWM_MOTOR_1, pwm);
}
}

I have already tried to mix two code that one of them my wifi connection and motor control code but it didn’t work. (Attachment name is Wifi_Control_03.ino)

Best Regards.

Wifi_Control_03.ino (4.66 KB)