Arduino uno can't control 2 PWM pins at the same time?? HELP!

Hi,

I am doing this project that is due in the next few hours. Basically, I have a photoresistor to detect the light level, and two motors that are controlled by two external 4-battery power supplies that are supposed to turn if the light goes below a certain level. The two motors are being controlled by using a 2n3904 transistor with its base connected to a PWM pin on the Arduino. Using analogWrite(), I am varying the speed of the motor.

I have a common ground between all of the power supplies. Not sure if the problem is the fact that I have a buck upconverter between one of the batteries and the powersupply. But the negative is connected to the common ground.

So basically, only PWN 6 works. None of the other PWN pins are working.

int photo_resistor = A0;
int motor_1 = 6;
int motor_2 = 3;
int val =0;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(motor_1,OUTPUT);
pinMode(motor_2,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  val=analogRead(photo_resistor);
  Serial.println(val);
  if(val<600)
  {
    analogWrite(motor_1,255);
    analogWrite(motor_2,255);
  }
  else
  analogWrite(motor_1,0);
  analogWrite(motor_2,0);
  

  }

Please help!

Hi,

Really need a diagram to understand your problem.

How much current do your motors use? a 2N3904 can't take much current; probably 200 mA at most.

Do both motors run the same? Same 2N3904?

More details!

(I just realized how nice it is to NOT know when Mid-Terms are...)

Autoformatting your code:

void loop()
{
  // put your main code here, to run repeatedly:

  val=analogRead(photo_resistor);
  Serial.println(val);
  if(val<600)
    {
      analogWrite(motor_1,255);
      analogWrite(motor_2,255);
    }
  else
    analogWrite(motor_1,0);
  analogWrite(motor_2,0);
 

}

Spot an issue perhaps?