Issue controlling two DC motors independently with transistors and arduino.

Sorry if I'm posting this in the wrong place, redirect me elsewhere if need be.

I'm using transistors as a switch to power my motors when supplied with a base current from the arduino. I need to turn two motors independently and I'm using two transistors, one for each motor. This almost works perfectly. However, when a base current is supplied to one transistor, both motors are turning instead of one. It seems to be something to do with both collector-emitter currents coming from the same power source as, when I use two separate battery packs, it works perfectly. However I'd much prefer to use one battery pack for both motors and still have them control independently.

I'll give my code just in case it helps, but I'm pretty sure it's an electronic's issue, not a software issue. I can update this post with a circuit diagram later, if need be.

void setup() {
 
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
}

void loop() {
 
  digitalWrite(10, HIGH);
  Serial.println("9HI");
  delay(1000);
  
  digitalWrite(10, LOW);
  Serial.println("9LO");
  delay(1000);
  
  digitalWrite(9, HIGH);
  Serial.println("10HI");
  delay(1000);
  
  digitalWrite(9, LOW);
  Serial.println("10LO");
  delay(1000);
}

If you can link an answer to a similar question, that would also be very helpful.

Hello JacobHerd,
Welcome to the forum.

++Karma for posting your code correctly on your first post.

It would be a lot easier to help you if you posted a circuit diagram too, a photo of a hand drawn diagram is fine.

In general I suggest that MOSFETs are a better choice for driving things, rather than bipolar transistors.

JacobHerd:
I can update this post with a circuit diagram later, if need be.

Its essential to have the circuit diagram to diagnose this. Perhaps you are lacking free-wheel diodes and have thus
blown up your transistors?