How to use Mini (DC) Motor in Blynk via NodeMCU

Hello, I’m still new in Arduino IDE. Pls tell me if there are things that I say maybe wrong or not following any procedure.
I already studied several videos in youtube regarding the Blynk app. I already tried the Servo motor and it works. Now I want to use the mini brushed motor by using the Blynk app via Nodemcu.
I just can’t find any reference in using the Motor Brushed by blynk in youtube (all of them are servo). All I know is that I need a motor driver and use a slider within the Blynk App. But I got no clue what is the programming code if I want to use a motor. I tried to do the same thing as Servo motor (which worked) but it doesn’t for Brushed motor. Can someone educate me from the programming and also the wiring pin.
This is for my school project Smart Home (Mini Fan using mini brushed motor)

Here’s what I learned by far

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

Servo servo;

char auth [] = "";

char ssid [] = "";
char pass [] = "";

void setup()

{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  servo.attach(15); //Pin D8 dkat NodeMCU
  
  
}

void loop ()
{
  Blynk.run();
}

BLYNK_WRITE(V1)
{
  servo.write(param.asInt());
}

BLYNK_WRITE(V2)
{
  servo.write(0);
}

BLYNK_WRITE(V3)
{
  servo.write(90);
}

Blynk is not your primary issue, it (or someone else’s work with their own code) will not make your project work magicly, doing some basic research into the hardware you want to use comes first.

You need to learn what is and how to control a brushless motor, then use whatever hardware (ESC) and code does that “controlling” within your Blynkified sketch. It seems most hobbest ESCs use PWM for controlling the motor, so with a basic brushless motor and ESC combo, Blynk and a slider widget essentially takes the place of a “throttle” or potentiometer :stuck_out_tongue:

PS, you should properly format all code you post here… as per the instructions you would have deleted when initially posting :stuck_out_tongue_winking_eye:

Blynk - FTFC

Haha :smile: thank you so much for the notes! I’ll be studying it right now. Is there any reference related the motor driver connectivity that I can study too? Sorry for the inconvenience.

Probably tons of it on the internet that is specific to whatever motor driver hardware you happen to be using.

Using the Wemos D1 Mini/Pro and one of the Wemos motor shields is a combination that I can recommend…
https://docs.wemos.cc/en/latest/d1_mini_shiled/motor.html

Pete.

Hello, I’ve made an update regarding the program. The App is connected and show the slider value in the serial monitor. But my motor doesn’t to move. Here’s my progress. Did I miss anything?

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <Servo.h>
#include <BlynkSimpleEsp8266.h>

int EnA = D1;
int In1 = D2;
int In2 = D3;
Servo esc;
  
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "nWScQ9PgkBSIuePfW7dtL3XPR3j9UAHJ";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Jacko_Blacko";
char pass[] = "12345678a";


Servo servo;
BLYNK_WRITE(V0)
{

  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble(); 
  pinValue= map(pinValue, 0, 255, 0, 180);
  esc.write(pinValue);
  esc.writeMicroseconds(pinValue);
  Blynk.virtualWrite(V1, pinValue);
  Serial.print("V0 Slider value is: ");
  Serial.println(pinValue);
}

void setup()
{
  // Debug console
  Serial.begin(115200);
  esc.attach(D1, 1000, 2000);
  esc.writeMicroseconds(1000);
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

void loop()
{
  
  
  Blynk.run();
}

So exactly what motor driver hardware are you actually using with your NodeMCU, and how is it wired to your board, and how is your motor wired to the motor driver?
What is the specification of the motor, and how is it being powered?

You’re continuing to use the servo library, despite not using a servo.

Also, the pinMode statements belong in the void setup, as they should be executed only once, at startup.

Pete.

Hello, Im using L298N Motor Driver. I wired the EnA to D1, IN1 to D2 and IN2 to D3. The motor GND is connected to the OUT2 and VCC to the OUT1. I’m using 3V Miniature Brush Motor. I used a usb wire which I cut it and connect it to the 5V and GND

So if you’re using an L298N, why are you using the servo library?

Pete.

I’m sorry, I’m still learning regarding Arduino and programming today. Instead of using servo library. What library should I be using then? Thank you

Maybe you should look at some L298N tutorials to understand how to use the controller properly.
Get it working without Blynk, then add-in the Blynk functionality.

Pete.

That is for DC motors, not brushless motors. Those require a special controller (basically and ESC is one with it’s own built in MCU running the three-wire timed process)… you might want to keep reading, before wiring/programming :smiley:

EDIT - a bit of rereading on my own… and perhaps it wasn’t your misspellings like I thought :innocent: … are you using a THREE-wire BrushLESS or a TWO-wire BRUSHED motor?

If the Brushless, then you are doing it all wrong :laughing:

If just a simple standard DC motor, then there is no library needed, just a matter of properly wiring up the motor (most L298N boards can run two motors) to the proper location… supplying it with it’s OWN power supply (sharing the ground with the NodeMCU) and feeding in the correct signals to the INT pins on the L298N. Careful not to short out your motor by enabling the wrong two INT pins at the same time) as that can hurt it and possibly overheat the power source

Google for all that hardware setup and then search this forum for topics like Rover, RC Car, L298N, etc.

Thank you so much for the info. My mistake, misleading info. I’m actually using DC and not brushed motor as my wires are only two. I really appreciate for the reply :grinning:

Then all you need to do is Google on how to control a motor like that with your controller and MCU type (which BTW has nothing to do with Blynk :wink: ) … Then once you understand how that works, you use that code with a Blynkified sketch to issue the speed/direction commands to your code.

There are many DC motor involved projects in this forum that you can see Blynkified programming examples from, but most probably refer to a car/rover type thing with dual motors, stearing, etc, so your fan code would be relatively simpler to develop from such examples.

Aside from Googleing on how to properly use your motor and controller you can also search this forum for keyworks like DC motor and L289N.