I am trying to make a small 2 wheel car but one of the wheels is only turning one way. The other motor is connected to a different channel on my L298N motor driver and works fine both ways, i tried connecting another motor to the potentially faulty channel and it does the same thing - only turns when i send the letter N through the serial terminal. Should i replace the motor driver or is the issue in my code or wiring?
#include "Arduino.h"
#include <SoftwareSerial.h>
const byte rxPin = 9;
const byte txPin = 8;
int in1 = 5;
int in2 = 4;
int in3 = 12;
int in4 = 6;
SoftwareSerial BTSerial(rxPin, txPin); // RX TX
void setup() {
// define pin modes for tx, rx:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
BTSerial.begin(9600);
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(7, OUTPUT);
}
String messageBuffer = "";
String message = "";
void loop() {
while (BTSerial.available() > 0) {
char data = (char) BTSerial.read();
messageBuffer += data;
if (data == 'n'){
message = messageBuffer;
messageBuffer = "";
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
} if (data == 'b'){
message = messageBuffer;
messageBuffer = "";
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
}
}
}








