Controlling two Gear motors (3V-6V) with Arduino Uno

Hi everyone.
I need to control the gear motor's velocity with muy Arduino Uno. I know Arduino can supply 5V and I think it's enough to move the motor.

I made this diagram:

My intention is just move two motors. The diagram has 4.

I connected all this things and the potientiometer works well. The screen shows the correct values but the motor doesn't work.

The transistor is bc547 b

And my code is:

int cntrl = 5;
int pot = 0;

void setup() {
  pinMode(cntrl, OUTPUT);
 Serial.begin(9600);
}

void loop() {
  float lvl = map(analogRead(pot), 0, 1023, 40, 255);
   analogWrite(cntrl, lvl);
  Serial.println(lvl);
}

Could you help me please?

Thanks :slight_smile:

  1. Bad idea to power a motor from Arduino's 5volt rail.

  2. You did not use a base current limiting resistor. Hopefully it will kill the transistor before it kills the Arduino pin.

  3. You did not use back EMF diodes across the motor.

  4. You used a tiny 100mA transistor for FOUR motors.

4x bad.
Leo..

Edit: Diagram shows the base connected to pin3. Code is pin5.
AnalogWrite can be 0-255.
Why use a float. AFAIK float won't work with map.