In realword ESP32 not responding very well

Hello Blynkers!
I need your advice.
Code is running very well through wifi when device is connected to USB cable,
but if I connect from power 5v to VIN, device is not responding well.
Especially Virtual buttons V3,V4,V5,V6.
What do thing is it promlem of code or scheme

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial

//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD

#include "BlynkEdgent.h"
#include <Robojax_L298N_DC_motor.h>
#include <ESP32Servo.h>
#include <HCSR04.h>

int ENA = 13;
int IN1 = 12;
int IN2 = 14;

int IN3 = 27;
int IN4 = 26;
int ENB = 25;


const byte triggerPin = 18;
const byte echoPin = 19;
UltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);

int led1 = 2;
int led2 = 15;
int led3 = 22;
int led4 = 23;

int myServo = 5;
float distance;
int startDevice;

BLYNK_WRITE(V0) {
  startDevice = param.asInt();
  digitalWrite(led1, startDevice);
  if (startDevice == 1) {
    Serial.println("DEVICE ON");
  }
  else {
    Serial.println("DEVICE OFF");
  }
}
void hcsr04() {


  // int pinValue=BLYNK_WRITE(V0); //START IF DEVICE is ON, GET VALUE FROM V0

  if (startDevice == 1) {

    float distance = distanceSensor.measureDistanceCm();
    //Serial.println(distance);
    Blynk.virtualWrite(V2, distance);
    if (distance < 200) {
      digitalWrite(led2, HIGH);
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
    }
    else {
      digitalWrite(led3, HIGH);
      digitalWrite(led4, HIGH);
      digitalWrite(led2, LOW);
    }
  }
  else {
    Blynk.virtualWrite(V2, 0.00);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
  }
}

BLYNK_WRITE(V3)  {
  
  if (startDevice == 1) {
  int forwardButton = param.asInt();
  if (forwardButton ==1)
  {
    goForward();
    //open valve
  }
  else if (forwardButton ==0){
    StopM();
  }
}else {
    StopM();
  }
}
BLYNK_WRITE(V4)  {
  
  if (startDevice == 1) {
  int backwardButton = param.asInt();
  if (backwardButton ==1)
  {
    goBackward();
    //open valve
  }
  else if (backwardButton ==0) {
    StopM();
  }
}else {
    StopM();
  }
}

BLYNK_WRITE(V5)  {
  
  if (startDevice == 1) {
  int leftButton = param.asInt();
  if (leftButton ==1)
  {
    turnLeft();
    //open valve
  }
  else if (leftButton ==0) {
    StopM();
  }
}else {
    StopM();
  }
}

BLYNK_WRITE(V6)  {
  
  if (startDevice == 1) {
  int rightButton = param.asInt();
  if (rightButton ==1)
  {
    turnRight();
    //open valve
  }
  else  if (rightButton ==0) {
    StopM();
  }
}else {
    StopM();
  }
}

void goForward()                       //forward with speed val
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(ENA, 255);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  digitalWrite(ENB, 255);
  Serial.println("Forward");
}

void goBackward()                     // secont function
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(ENA, 255);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  digitalWrite(ENB, 255);
  Serial.println("Backward");

}
void turnRight()                       //forward with speed val
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(ENA, 255);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  digitalWrite(ENB, 255);
  Serial.println("Right");
}

void turnLeft()                     // secont function
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(ENA, 255);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  digitalWrite(ENB, 255);
  Serial.println("Left");
}

void StopM()                     //third function
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  Serial.println("Stoped");
}


BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V0);
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
  Blynk.syncVirtual(V4);
  Blynk.syncVirtual(V5);
  Blynk.syncVirtual(V6);
}

void setup()
{
  Serial.begin(115200);
  delay(100);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);

  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENB, OUTPUT);

  BlynkEdgent.begin();
  timer.setInterval(500L, hcsr04);
  //timer.setInterval(500L, hcsr04);
}
void loop() {
  BlynkEdgent.run();
  timer.run();
}

here is scheme of my connection (pins of esp32 are different).

my esp32 pins structure aslo uploaded

Sounds like the 5v output from your motor driver board is not very well regulated.

Pete.

The l298n 5v is not an output, it’s an input that used to Supply power for the switching logic circuitry inside L298N IC.

Thanks for quick respond,.
Pete, how can I regulate it?

If you have the 5v jumper in place then the 5v terminal can be used as a 5v 0.5A supply, but I’m guessing that there is a fair bit of noise on that supply.

The module has an on-board 78M05 5V regulator from STMicroelectronics. It can be enabled or disabled through a jumper.

When this jumper is in place, the 5V regulator is enabled, supplying logic power supply(Vss) from the motor power supply(Vs). In this case, 5V input terminal acts as an output pin and delivers 5V 0.5A. You can use it to power up the Arduino or other circuitry that requires 5V power supply.

When the jumper is removed, the 5V regulator gets disabled and we have to supply 5 Volts separately through 5 Volt input terminal.

Pete.

You could try a suitable capacitor as close as possible to the ESP32’s supply pins.

Pete.

here they say:
5V pin supplies power for the switching logic circuitry inside L298N IC. If the 5V-EN jumper is in place, this pin acts as an output and can be used to power up your Arduino. If the 5V-EN jumper is removed, you need to connect it to the 5V pin on Arduino.

Pete, as capacitor you mean power suply. I have 2 bettaries (18650 with 3.7V) it is vey close about 15 cm

I said capacitor because I meant capacitor.
If I’d meant power supply or battery then I would have said that.

Pete,

Pete sorry for my English :pray:
I will ask google what is capacitor and how it looks

Have you tried to power the esp32 using a separate power supply ?

Something like this

No I have not tried yet.

Pete, I got what is capacitor it self, thanks for google.


I used this one for my motors, because some russian guy on youtube told that if I attach it to motor it will not give a sound when there is low volt.
and I used it like this:

The wiring on those motors looks very dodgy to me!

Pete.

Guys problem is solved,
thanks to John93,

1 Like

I’m so glad your problem has been solved :+1:

1 Like