I'd like to use the Power Supply Unit (PSU) instead of battery to control the BLDC motor through ESC with the below configurations:
- ESP8266 NodeMCU 1.0
- PSU (Model S-60-12; AC Input: 220V; DC Input: 12V 5A)
- BLCD: 2212/10T/1400KV
- ESC 30A
Connections like the photo (Servo connector: GND to ESP8266 GND, Throttle Input Pin to ESP8266 D1)
And this is my code:
#include <Servo.h>
Servo m1;
void setup(){
m1.attach(D1); // D1
m1.write(180);
delay(2000);
m1.write(0);
delay(2000);
}
void loop(){
int pos;
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
m1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
m1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
When i plug the AC power connector, the motor can run as expected. However, if i repeatedly plug and unplug it, sometimes the motor doesn't work.
Could anybody support me to solve the above issue so that the motor always runs when i plug/unplug the power connector multiple times?
Thanks