Not taking input properly and printing boxes instead

Hi, I'm really new into Arduino so maybe you could see some gross mistakes.
I'm trying to make a mini windows wich glasses moves by a switch, trying to test if the code works how it supose to do I used a serial input, but when I run the code it starts printing boxes, and I actually don't know why. I tried with the Bluethooth input but didn't do nothing either. I would really appreciate some help. Thanks. Here is my code:

#include <SoftwareSerial.h>

int pinPolo1Motor1 = 9;     // Pin de motor 1
int pinPolo2Motor1 = 10;     // Pin de dirección del motor 1
int pinHabilitacionMotor1 = 8;      // Pin de habilitación del motor 1

int pinPolo1Motor2 = 11;       // Pin de motor 2 
int pinPolo2Motor2 = 12;    // Pin de dirección del motor 2
int pinHabilitacionMotor2 = 13;    // Pin de habilitación del motor 2

SoftwareSerial BT (3, 2); // Setteo de los pines de transmisión bluethooth

bool moverDireccionMotor1 = false; // Estado del switch del motor 1, cerrado
bool moverDireccionMotor2 = false; // Estado del switch del motor 2, cerrado
char valor;



void setup()
{

  // Seteo del comportamiento de los pines del motor 1

  pinMode(pinPolo1Motor1,OUTPUT); // Polo 1
  pinMode(pinPolo2Motor1,OUTPUT); // Polo 2
  pinMode(pinHabilitacionMotor1,OUTPUT);

  // Seteo del comportamiento de los pines del motor 2

  pinMode(pinPolo1Motor1,OUTPUT); // Polo 1
  pinMode(pinPolo2Motor2,OUTPUT); // Polo 2
  pinMode(pinHabilitacionMotor2,OUTPUT);

  // Se apagan ambos motores, poniendo los polos en LOW

  digitalWrite(pinPolo1Motor1,LOW);
  digitalWrite(pinPolo2Motor1,LOW);

  digitalWrite(pinPolo1Motor2,LOW);
  digitalWrite(pinPolo2Motor2,LOW);

  // Preseteo el giro

  analogWrite(pinHabilitacionMotor1,200);
  analogWrite(pinHabilitacionMotor2,200);

  Serial.begin(9600); // Habilitación del puerto USB
  BT.begin(9600); // Habilitación del puerto Bluethooth

}

void loop() {

  // Lectura del input por bluethooth

  if (BT.available()) valor = BT.read();

  // Instrucción de movimiento según el input

  if ( valor == 'B') { 
    if (moverDireccionMotor1 == true) {
      digitalWrite(pinPolo1Motor1,LOW);
      digitalWrite(pinPolo2Motor1,HIGH);
      delay(500);
      digitalWrite(pinPolo1Motor1,LOW);
      digitalWrite(pinPolo2Motor1,LOW);
    } else {
      digitalWrite(pinPolo1Motor1,HIGH);
      digitalWrite(pinPolo2Motor1,LOW);
      delay(500);
      digitalWrite(pinPolo1Motor1,LOW);
      digitalWrite(pinPolo2Motor1,LOW);
    }

    moverDireccionMotor1 = !moverDireccionMotor1; // Invierte la dirección de movimiento para la próxima instrucción

  } else {
    if (moverDireccionMotor2 == true) {
      digitalWrite(pinPolo1Motor2,LOW);
      digitalWrite(pinPolo2Motor2,HIGH);
      delay(500);
      digitalWrite(pinPolo1Motor2,LOW);
      digitalWrite(pinPolo2Motor2,LOW);
    } else {
      digitalWrite(pinPolo1Motor2,HIGH);
      digitalWrite(pinPolo2Motor2,LOW);
      delay(500);
      digitalWrite(pinPolo1Motor2,LOW);
      digitalWrite(pinPolo2Motor2,LOW);
    }

    moverDireccionMotor1 = !moverDireccionMotor1; // Invierte la dirección de movimiento para la próxima instrucción

  }
}

shouldn't the code only process valor when it is read?

try

void loop () {
  if ( !  BT.available())
       return;
 
   valor = BT.read();

which skips when there's nothing to read

Sorry I am getting old and my eyes are not what they use to be. I cannot see your project or how it is wired. Posting a schematic, not a frizzy picture of how you have it wired including Power, Ground, power supplies, etc along with links to "Technical information" on each of the hardware items will help. I do not do well with word problems. Schematics generally transcend the language barrier.

Does this match the setting in the serial monitor window?

a7

I will try that, thanks! Also the baud rate matches with the serial monitor.
I will post a schematic asap, btw

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.