HC08, Uno, L298N, Servo, unresponsiveness and lag

What I’m using:

  • Arduino Uno
  • HC08 bluetooth module
  • L298N dual h bridge motor controller
  • MG996R Servo
  • Rc car
  • App version 2.27.29
  • Samsung S10+ (Android 11)

Goal:
I want to convert an rc car into being bluetooth controlled as well as having a fork on the front that can move up and down. I am using the HC08 module for ble communication between the blynk app and an arduino uno. the uno controls the motors via the L298N, and it also controls the servo motor.

In app these functions are being controlled by a joystick and a slider, the former for the motors, the latter for the servo.

The Issue:
the issue I’m having is whilst using the app (blynk), sometimes when controlling the car it just locks up or loses connection, and in turn ignores all input, sometimes saying lost connection to server or something along those lines. sometimes it works after waiting like 2 minutes and other times i had to turn it on and off again. i’ve tried swapping it out with an arduino nano (also swapping the settings in the blynk app), that just ignores input all together (i googled it briefly and i thought they used the same chip). I also tried using the hc05 module (also swapping the settings in the blynk app) to no avail, it ignores input as well. I have no clue it this is caused by hardware, software or both.

Note, the servos and motors do work normally, they are not the issue

I’ve tried finding this issue elsewhere, i’ve had similar issues as this post: (Servo jittering and PWM issues) Arduino UNO + Bluetooth + Servo + H-bridge, however they’re major issue is different altogether. I’ve also had an issue where moving the joystick causes the servo to jitter, despite the two having nothing to do with each other.

I hope this post has all the necessary details for you to understand my issue.

The Code:




/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  Note: This only works on Android!
        iOS does not support Bluetooth 2.0 Serial Port Profile
        You may need to pair the module with your smartphone
        via Bluetooth settings. Default pairing password is 1234

  Feel free to apply it to any other example. It's simple!

  NOTE: Bluetooth support is in beta!

  You can receive x and y coords for joystick movement within App.

  App project setup:
    Two Axis Joystick on V1 in MERGE output mode.
    MERGE mode means device will receive both x and y within 1 message
 *************************************************************/

/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT Serial

#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX

#include <BlynkSimpleSerialBLE.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "VLyx61Lg7WncZmtluGAwvZPT-reFAjDI";

Servo servo;

#define enA 5
#define enB 6
#define int1 7
#define int2 4
#define int3 12
#define int4 13
#define SERVOPIN 9

BLYNK_WRITE(V1) {
  int x = param[0].asInt();
  int y = param[1].asInt();

  if(x > 0)
  {
    digitalWrite(int1, HIGH);
    digitalWrite(int2, LOW);
    analogWrite(enA, x);
  } else if(x < 0)
  {
    digitalWrite(int1, LOW);
    digitalWrite(int2, HIGH);
    analogWrite(enA, abs(x));
  }
  else
  {
    analogWrite(enA, LOW);
  }

  if(y > 0)
  {
    digitalWrite(int3, HIGH);
    digitalWrite(int4, LOW);
    analogWrite(enB, y);
  } else if(y < 0)
  {
    digitalWrite(int3, LOW);
    digitalWrite(int4, HIGH);
    analogWrite(enB, abs(y));
  }
  else
  {
    analogWrite(enB, LOW);
  }
}

BLYNK_WRITE(V0)
{
  int x = param.asInt();
  servo.write(x);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  SwSerial.begin(9600);
  Blynk.begin(SwSerial, auth);
  Serial.println("Waiting for connections...");

  servo.attach(SERVOPIN);

  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(int1, OUTPUT);
  pinMode(int2, OUTPUT);
  pinMode(int3, OUTPUT);
  pinMode(int4, OUTPUT);
}

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