Disconnecting with servos and 9V

Hi, everyone.

New here and begginer at Blynk. I wish I could have some help.

I’m trying to control two hacked servos with a Wemos D1 board and Blynk. The code seems not to be the problem but the power supply.

Since the idea is to control it via Wifi, I’m using a 9V battery but the device gets disconnected every time I press something in the app. But when I power it via USB to my computer, the app works with no problem. So I guess it’s the battery.

Is there any solution to this? I’m not familiar with the power supply at all.

Here’s the code too:

#define BLYNK_PRINT Serial

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

Servo myservo2;                
Servo myservo1;

BlynkTimer timer;

char auth[] = "xxx";

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

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  myservo1.attach(14);
  myservo2.attach(15);
}

BLYNK_WRITE(V1){
   if(param.asInt() < 30){
    servo1atras();
  }
  if(param.asInt() > 150){
    servo1adelante();
  }  
}

BLYNK_WRITE(V2){
   if(param.asInt() < 30){
    servo2atras();
  }
  if(param.asInt() > 150){
    servo2adelante();
  }  
}

void servo1adelante(){
myservo1.write(150);
delay(15);
}

void servo1atras(){
myservo1.write(30);
delay(15);
}

void servo2adelante(){
myservo2.write(150);
delay(15);
}

void servo2atras(){
myservo1.write(30);
delay(15);
}

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

Sorry if the answer was in other topic but I tried to search for it and I couldn’t find the answer ):

GND issues?

This is beyond this forums purpose (teaching how Blynk works) :wink: but your issue is most likely current related… 9v batteries are very low current power sources, even a AA battery 4 pack (6v) would run margenably better, but still not for very long.

I recommend a couple of 4.2v 18650 batteries in series instead. But you will need to have a proper charging option.

Google will be your best option to learn some basics about power supply options for microcontrollers and servos as there are may ways to go. But 9v batteries is not recommended as one of them :smiley: