UNO R4 Bluetooth remote car using L298N giving command is not moving at all

Hi

I am using a Dabble application on my iPhone UNO R4 Wifi has built-in Bluetooth Have tried a looked in many places but no luck pls help.

I like to make it move forward and back right and left,

On top of that when I finished another two Dc motors on the same H bridge and 2 servo on PCA9685k go back

Ideally, I like to

assign DC motors 1 and 2 is to go forward and back and right so you can assign the 4 arrows to it

DC Motor 3 and 4 need to go forward and back,

Assign dc 3 to square and forward arrow to go forward and square and backwards arrow to go back

Assign DC 4 to the x button and forward arrow to go forward and c button and backwards arrow to go back

assign servo 1 to the triangle and the forward arrow to go forward and the triangle plus backwards arrow to go back

assign servo 2 to the circle and forward arrow to go forward and circle plus backwards arrow to go back

On top of that when I finished another two Dc motors on the same H bridge and 2 servo on PCA9685k go back

#include "Arduino_LED_Matrix.h"
#include <ArduinoBLE.h>
#include <Servo.h>

// Motor A connections
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B connections
int enB = 3;
int in3 = 5;
int in4 = 4;


// For the LED Matrix
ArduinoLEDMatrix matrix;

const uint32_t happy[] = {
    0x19819,
    0x80000001,
    0x81f8000
};
const uint32_t heart[] = {
    0x3184a444,
    0x44042081,
    0x100a0040
};

// For the Servo
Servo myServo;
int prevAngle = -1;

// UUIDs for BLE service and characteristics
const char* deviceServiceUuid = "19b10000-e8f2-537e-4f6c-d104768a1214";
const char* deviceServiceRequestCharacteristicUuid = "19b10001-e8f2-537e-4f6c-d104768a1215";
const char* deviceServiceResponseCharacteristicUuid = "19b10001-e8f2-537e-4f6c-d104768a1216";

BLEService servoService(deviceServiceUuid);
BLEStringCharacteristic servoRequestCharacteristic(deviceServiceRequestCharacteristicUuid, BLEWrite, 4);
BLEStringCharacteristic servoResponseCharacteristic(deviceServiceResponseCharacteristicUuid, BLENotify, 4);

void mainDCcontrol();

void setup() {
  // Initialize Serial
  Serial.begin(9600);

  // Initialize the LED Matrix
  matrix.begin();

  // Initialize the Servo
  myServo.attach(9);

  // Initialize BLE
  BLE.begin();
  BLE.setDeviceName("OCOne");
  BLE.setLocalName("OCOne");
  BLE.setAdvertisedService(servoService);

  servoService.addCharacteristic(servoRequestCharacteristic);
  servoService.addCharacteristic(servoResponseCharacteristic);
  BLE.addService(servoService);
  servoResponseCharacteristic.writeValue("0");

  BLE.advertise();

	// Set all the motor control pins to outputs
	pinMode(enA, OUTPUT);
	pinMode(enB, OUTPUT);
	pinMode(in1, OUTPUT);
	pinMode(in2, OUTPUT);
	pinMode(in3, OUTPUT);
	pinMode(in4, OUTPUT);
	
	// Turn off motors - Initial state
	digitalWrite(in1, LOW);
	digitalWrite(in2, LOW);
	digitalWrite(in3, LOW);
	digitalWrite(in4, LOW);
}

void loop() {
  // Handle BLE connections
  BLEDevice central = BLE.central();

  if (central) {
    Serial.print("Connected to central: ");
    Serial.println(central.address());

    while (central.connected()) {
      if (servoRequestCharacteristic.written()) {
        String newAngleStr = servoRequestCharacteristic.value();
        int newAngle = newAngleStr.toInt();

        if (prevAngle != newAngle) {
          myServo.write(newAngle);
          prevAngle = newAngle;
          servoResponseCharacteristic.setValue(newAngleStr);
        }
      }
    }

    Serial.println("Disconnected from central");
  }

  mainDCcontrol();

  // Display patterns on the LED matrix
  matrix.loadFrame(happy);
  delay(500);
  matrix.loadFrame(heart);
  delay(500);
}

void mainDCcontrol() {
directionControl();
	delay(1000);
	speedControl();
	delay(1000);
}

// This function lets you control spinning direction of motors
void directionControl() {
	// Set motors to maximum speed
	// For PWM maximum possible values are 0 to 255
	analogWrite(enA, 255);
	analogWrite(enB, 255);

	// Turn on motor A & B
	digitalWrite(in1, HIGH);
	digitalWrite(in2, LOW);
	digitalWrite(in3, HIGH);
	digitalWrite(in4, LOW);
	delay(2000);
	
	// Now change motor directions
	digitalWrite(in1, LOW);
	digitalWrite(in2, HIGH);
	digitalWrite(in3, LOW);
	digitalWrite(in4, HIGH);
	delay(2000);
	
	// Turn off motors
	digitalWrite(in1, LOW);
	digitalWrite(in2, LOW);
	digitalWrite(in3, LOW);
	digitalWrite(in4, LOW);
}

// This function lets you control speed of the motors
void speedControl() {
	// Turn on motors
	digitalWrite(in1, LOW);
	digitalWrite(in2, HIGH);
	digitalWrite(in3, LOW);
	digitalWrite(in4, HIGH);
	
	// Accelerate from zero to maximum speed
	for (int i = 0; i < 256; i++) {
		analogWrite(enA, i);
		analogWrite(enB, i);
		delay(20);
	}
	
	// Decelerate from maximum speed to zero
	for (int i = 255; i >= 0; --i) {
		analogWrite(enA, i);
		analogWrite(enB, i);
		delay(20);
	}
	
	// Now turn off motors
	digitalWrite(in1, LOW);
	digitalWrite(in2, LOW);
	digitalWrite(in3, LOW);
	digitalWrite(in4, LOW);
}







The Arduino comes up as a Bluetooth device. on the app
Also, see the hearth as I needed it

what I really need to be able to move forward back left and right now

later I can sweat through the arm, grip and the spin.

TBH

this is a salvaged code what I found and most likely that is why is not working

the trouble is that I connect the uno to my phone and press the arrow moving forward and nothing happens neither backwards right or left

Is there a way to have a print out of how the Arduino interprets the Bluetooth remote controller buttons so I can assign tasks for those functions?

Make a new sketch that just connects to the phone. Remove anything that goes to the servos and motors. Then use the Serial Monitor to see exactly what you are receiving from the phone.

1 Like

The Serial.print() command can be used to print anything you like, such as values received from Bluetooth.

Do you have an example code pls?

Jeez I need help with this that is whyI asked help
I understand if is tooo hard for someone

I don't have anything you are using so I am literally just guessing here. Try this, if it doesn't work then break it down piece by piece. Look up tutorials and other examples, we can only do so much on our end.

#include <ArduinoBLE.h>

// UUIDs for BLE service and characteristics
const char* deviceServiceUuid = "19b10000-e8f2-537e-4f6c-d104768a1214";
const char* deviceServiceRequestCharacteristicUuid = "19b10001-e8f2-537e-4f6c-d104768a1215";
const char* deviceServiceResponseCharacteristicUuid = "19b10001-e8f2-537e-4f6c-d104768a1216";

BLEService servoService(deviceServiceUuid);
BLEStringCharacteristic servoRequestCharacteristic(deviceServiceRequestCharacteristicUuid, BLEWrite, 4);
BLEStringCharacteristic servoResponseCharacteristic(deviceServiceResponseCharacteristicUuid, BLENotify, 4);

void setup() {
  // Initialize Serial
  Serial.begin(9600);

  // Initialize BLE
  BLE.begin();
  BLE.setDeviceName("OCOne");
  BLE.setLocalName("OCOne");
  BLE.setAdvertisedService(servoService);

  servoService.addCharacteristic(servoRequestCharacteristic);
  servoService.addCharacteristic(servoResponseCharacteristic);
  BLE.addService(servoService);
  servoResponseCharacteristic.writeValue("0");

  BLE.advertise();
}

void loop() {
  // Handle BLE connections
  BLEDevice central = BLE.central();

  if (central) {
    Serial.print("Connected to central: ");
    Serial.println(central.address());

    while (central.connected()) {
      if (servoRequestCharacteristic.written()) {
        String newAngleStr = servoRequestCharacteristic.value();
        int newAngle = newAngleStr.toInt();
        Serial.print("Servo Angle: ");
        Serial.println(newAngle);
      }
    }

    Serial.println("Disconnected from central");
  }
}

One problem is that you just copied someone else's code, without much, if any understanding. Forum members tend not to be impressed by such low levels of motivation.

If you want someone to write code for you, post on the Jobs & Paid Collaborations forum section.

1 Like

Sorry I thought it is open source and we help each other.

Thank you are amazing, I will try it out when I get home. I am on the train from uni where I will have this as an assignment. Sorry for the questions.

My friend your contribution so far was not delta but minus -10.

There is no info out there for uno r4 wifi as most of the info is regarding older devices instead making it a useful thread people will have to read through all of this mouth karate… thx

I happy to read up on staff u have at hand and work out next steps but again just being negative-11
Mate I am married already don’t need more drama

So reading is hard in -12

I was saying I will do it when I get home atm I am in a train station….

At least time goes faster

It has connected on but not displaying anything atm I need to dive in a bit more still on the train will see if I can make it work tonight thank you for your help so far