Attempting to build a bluetooth controller to operate a dump trailer

I had an idea to practice programming and Arduino by building a controller unit to operate my dump trailer via Bluetooth with an app on my tablet.

I built an app using an MIT app building site that seems to work and I wrote a program on the Arduino site that seems to work. The Arduino Uno I am using connects to my tablet with the Bluetooth module but when I push any button on the tablet app the dump trailer goes up and only up.

I worked the issue out to be that when I hit a button on my tablet, it activates all the relays at once instead of relays only operating certain components. From what I can tell, the Arduino is sending a signal out of all ports no matter what button I hit on my tablet.

I am not well versed in this as this is my first project starting from "scratch". I used some code on youtube as a starting point and built from there. I just need someone to look at my Arduino code and help me understand if my issue is more likely in the code or somewhere else so I know where to start.

int Dump_Trailer_Up=11;
int Dump_Trailer_Down=12;
int Dump_Trailer_Power=13;
int Tailgate_Latch_Unlock=8;
int Tailgate_Latch_Lock=7;

//Variables
int Received = 0;
int Dump_Trailer_Up_State = 0;
int Dump_Trailer_Down_State = 0;
int Dump_Trailer_Power_State = 0;
int Tailgate_Latch_Unlock_State = 0;
int Tailgate_Latch_Lock_State = 0;

void setup(){
  
  Serial.begin(9600);
  pinMode(Dump_Trailer_Up,OUTPUT);
  pinMode(Dump_Trailer_Down,OUTPUT);
  pinMode(Dump_Trailer_Power,OUTPUT);
  pinMode(Tailgate_Latch_Unlock,OUTPUT);
  pinMode(Tailgate_Latch_Lock,OUTPUT);
}

void loop(){
  
  if (Serial.available() > 0)
  {
    Received = Serial.read();
  }

////////////////Dump Trailer Up/////////////////////
 if (Received =='1'){
   digitalWrite(Dump_Trailer_Up,HIGH);   
  }  
 if (Received =='2'){
 digitalWrite(Dump_Trailer_Up,LOW);
 }
 ///////////////////////////////////////////

 ////////////////Dump Trailer Down/////////////////////
 if (Received =='3'){
   digitalWrite(Dump_Trailer_Down,HIGH);   
  }  
 if (Received =='4'){
 digitalWrite(Dump_Trailer_Down,LOW);
 }
 ///////////////////////////////////////////
 
 ////////////////Dump Trailer Power/////////////////////
 if (Received =='1'){
   digitalWrite(Dump_Trailer_Power,HIGH);   
  }  
 if (Received =='2'){
 digitalWrite(Dump_Trailer_Power,LOW);
 }
 ///////////////////////////////////////////
 
 ////////////////Tailgate Latch Unlock/////////////////////
 if (Received =='5'){
   digitalWrite(Tailgate_Latch_Unlock,HIGH);   
  }  
 if (Received =='6'){
 digitalWrite(Tailgate_Latch_Unlock,LOW);
 }
 ///////////////////////////////////////////
 
 ////////////////Tailgate Latch Lock/////////////////////
 if (Received =='7'){
   digitalWrite(Tailgate_Latch_Lock,HIGH);   
  }  
 if (Received =='8'){
 digitalWrite(Tailgate_Latch_Lock,LOW);
 }
 ///////////////////////////////////////////
 
}

My advice is to connect the Bluetooth module to your Uno using a software serial port, then add Serial.println() calls to print debug output to Serial Monitor so you can get some idea of what is actually happening.

https://www.arduino.cc/en/Reference/SoftwareSerial

It looks to me like that code will do the same action over and over after receiving a command because the Received variable is never reset, so even if no new command is read it retains its value. Try resetting the value at the top of loop()

  Received = 0;
  if (Serial.available() > 0)
  {
    Received = Serial.read();
  }

I'll one up pert's advice and recommend that you pull the Bluetooth module out and enter commands via the serial monitor to isolate the Arduino code from the mobile app.

When you turn the Arduino on, the relays are all off...
Then when you press a single button they ALL turn ON?

I can’t see how that code is doing that, sorry.

I could see how all relays start ON (energised) when you power on the Arduino (before pressing any buttons at all).

Sounds like a wiring issue to me. Post a circuit diagram of how you have those relays wired, and what type of relays/relay module you are using. Double check all your connections.

Also most relay modules work on inverse logic: LOW is relay energised, HIGH is relay de-energised. This makes me wonder if the OP is attempting to power the relay coils directly from the Arduino without a driver board or transistor.

Also it would be good practice to do a digitalWrite to all your output pins in setup. Not just rely on them being LOW. Never a good idea to rely on initial startup conditions...

Thanks for the tips. I will work on these items and see what happens. Appreciate it.