Power supply problems with esp32

I am trying to build a car with a robotic arm. I am powering the esp32 with 5 volts from a buck converter and the motor driver -l298n with the 7.4 volts directly. It works fine but the batteries get exhausted quickly. When I try to switch the battery voltage to 11.1 volts by adding another lithium ion battery, the esp gets reset as soon as the motor starts. Can anyone tell me why this is happening?

the servo works fine in both cases

Schematics please...
Check the datasheet for the ESP input voltage range.

If your esp is resetting it is most likely due to a power loss. The pull of a motor is VERY high when it first starts up. Probably too much for the buck converter powering the ESP32. As soon as the voltage drops too low, it will reset the ESP32. Try powering the ESP32 and the motor off separate batteries, rather than sharing them. Or, to try it out, power the ESP32 with a simple wall-wart and a USB cable, just as a proof of concept.

Probably because by increasing the battery voltage you are increasingly the stall current beyond what the batteries can supply, resulting in a drop in voltage when the motor starts, resetting the ESP32.

I tried to power them with separate batteries but again the same problem occured

could you recommend a free software where i can make a schematic? also i dont know a lot about how to make it proper

Post an image of the project, post the code in code tags.

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

Thanks.. Tom... :smiley: :+1: :coffee: :australia: :australia:

1 Like



#include <WiFi.h>
#include <WiFiManager.h>
#include <ESP32Servo.h>
Servo Gripper;
Servo Shoulder;
Servo Elbow;
Servo Base;
WiFiServer server(80);
String GripperString = String(5);
String ElbowString = String(5);
String ShoulderString = String(5);
String BaseString = String(5);
String comand = String(5);
int pos1 = 0;
int pos2 = 0;
int pos3 = 0;
int pos4 = 0;
int pos5 = 0;
int pos6 = 0;
int pos7 = 0;
int pos8 = 0;
int pos9 = 0;
unsigned long currentTime = millis();
unsigned long previousTime = 0;
const long timeoutTime = 2000;
String header;
char command;
int speedCar = 800;  // 400 - 1023.
#define ENA 22
#define IN_1 21
#define IN_2 19
#define IN_3 18
#define IN_4 5
#define ENB 4

void setup() {
  pinMode(2, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN_1, OUTPUT);
  pinMode(IN_2, OUTPUT);
  pinMode(IN_3, OUTPUT);
  pinMode(IN_4, OUTPUT);

  Serial.begin(115200);
  WiFiManager wifiManager;
  wifiManager.autoConnect("carm", "dsthebest");
  Serial.println("WiFi connected");
  server.begin();  // Start the server
  Serial.println("Server started");
  Serial.print("Use this URL to connect: ");  // Print the IP address
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Gripper.attach(27);
  Shoulder.attach(25);
  Elbow.attach(26);
  Base.attach(33);
  Gripper.write(90);
  Shoulder.write(90);
  Elbow.write(90);
  Base.write(90);
}


void loop() {
  WiFiClient client = server.available();
  if (WiFi.status() == WL_CONNECTED) {
    digitalWrite(2, HIGH);
  } else {
    digitalWrite(2, LOW);
  }
  if (client) {  // If a new client connects,
    currentTime = millis();
    previousTime = currentTime;
    Serial.println("New Client.");                                             // print a message out in the serial port
    String currentLine = "";                                                   // make a String to hold incoming data from the client
    while (client.connected() && currentTime - previousTime <= timeoutTime) {  // loop while the client's connected
      currentTime = millis();
      if (client.available()) {  // if there's bytes to read from the client,
        char c = client.read();  // read a byte, then
        //Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {  // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();

            if (header.indexOf("GET /?Gripper=") >= 0) {
              pos1 = header.indexOf('=');
              pos2 = header.indexOf('&');
              GripperString = header.substring(pos1 + 1, pos2);

              //Rotate the servo
              Gripper.write(GripperString.toInt());
              Serial.println(GripperString);
            }
            if (header.indexOf("GET /?Elbow=") >= 0) {
              pos3 = header.indexOf('=');
              pos4 = header.indexOf('&');
              ElbowString = header.substring(pos3 + 1, pos4);

              //Rotate the servo
              Elbow.write(ElbowString.toInt());
              //Serial.println(valueString);
            }
            if (header.indexOf("GET /?Shoulder=") >= 0) {
              pos5 = header.indexOf('=');
              pos6 = header.indexOf('&');
              ShoulderString = header.substring(pos5 + 1, pos6);

              //Rotate the servo
              Shoulder.write(ShoulderString.toInt());
              //Serial.println(valueString);
            }
            if (header.indexOf("GET /?Base=") >= 0) {
              pos7 = header.indexOf('=');
              pos8 = header.indexOf('&');
              BaseString = header.substring(pos7 + 1, pos8);
              Base.write(BaseString.toInt());
              Serial.println(BaseString);
            }
            if (header.indexOf("GET /?car=") >= 0) {
              command = header.indexOf('=');
              pos9 = header.indexOf('&');
              comand = header.substring(command + 1, pos9);
              if (comand == "F") goAhead();
              else if (comand == "B") goBack();
              else if (comand == "L") goLeft();
              else if (comand == "R") goRight();
              else if (comand == "0") speedCar = 400;
              else if (comand == "1") speedCar = 470;
              else if (comand == "2") speedCar = 540;
              else if (comand == "3") speedCar = 610;
              else if (comand == "4") speedCar = 680;
              else if (comand == "5") speedCar = 750;
              else if (comand == "6") speedCar = 820;
              else if (comand == "7") speedCar = 890;
              else if (comand == "8") speedCar = 960;
              else if (comand == "9") speedCar = 1023;
              else if (comand == "S") stopRobot();
              Serial.println(comand);
              Serial.println(speedCar);
            }
            client.println();
            break;
          } else {  // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    header = "";
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  }
}
void goAhead() {
  Serial.println("forward");
  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, HIGH);
  analogWrite(ENA, speedCar);

  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, HIGH);
  analogWrite(ENB, speedCar);
}

void goBack() {

  digitalWrite(IN_1, HIGH);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);

  digitalWrite(IN_3, HIGH);
  digitalWrite(IN_4, LOW);
  analogWrite(ENB, speedCar);
}

void goLeft() {

  digitalWrite(IN_1, HIGH);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);

  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, HIGH);
  analogWrite(ENB, speedCar);
}

void goRight() {

  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, HIGH);
  analogWrite(ENA, speedCar);

  digitalWrite(IN_3, HIGH);
  digitalWrite(IN_4, LOW);
  analogWrite(ENB, speedCar);
}

void stopRobot() {

  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);

  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, LOW);
  analogWrite(ENB, speedCar);
}

I have tried to make a schematic and I know it is not too good. I have also uploaded the code.

1 Like

Please excuse me for my bad handwriting and I hope the schematic is understandable. The esp 32-cam has only the camera webserver example code uploaded and it just streams the live footage.

4S Lipo is 14.8V. What's the input thingies of the buck converter? What's the current rating of the buck?

The LiPo's show in the image are most likely 1C, 4 servos and 2 motors may want more than 1amp.

6 motors estimated at 1 amp per motors, would warrant something like this


A bit overkill but it has the ability to supply more than 1 amp without burning up the battery. At 6 amps you'd get about 12 minutes or so of operation.

What Does “C” Rating Mean on a LiPo Battery

Simply put, the “C” rating is the cell’s maximum safe continuous discharge rate. Let’s put some numbers down from a LiPo pack for reference: 5000mAh 20C 7.4V (2S).

I am powering it through 2 lithium ion batteries each of 3000 mah and 3.7 volt. The output current of buck converter is 3 amps max

4 servos need 4 amps, 2 unknown motors which need at least an amp each, for a total of at least 6 amps, you don't see a problem with that?

But the project works when I supply power with 2 lithium ion batteries. When I power it with 3 lithium ion batteries ie: 11.1 volt then it doesnt work.

Also the 4 servos dont work simultaneously so will they still take an amp?

Hi,
Have you got a DMM?

If so what is the output voltage of the Buck converter with each battery set?
In working and fault condition.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

I dont have a multimeter but I have a digital voltmeter.
image

according to its readings, with 2 li-ion batteries it shows 5 volt constantly and the same with three batteries