digitalWrite not giving pin 5v?

I built a little tamiya kit and hooked my gearbox to the 5v it runs fast, I hooked it to the 3.3v it runs a bit slower, I wanted to do this with some code to so it would run around on the floor but I can't get it to send 5v power to any of the pins - it sends power enough to run an LED but when I add the motor to it doens't power it ( and if the LED is still part of the circuit it turns off completely )

what am I doing wrong?

void setup()
{
  pinMode(2, OUTPUT);          // sets the digital pin 2 as output
}
 
void loop()
{
  digitalWrite(2, HIGH);       // sets the digital pin 2 on

}

just to be clear when I connect the ground and power to the 5V and GRN it powers up no problem, when physically change the positive connection to the 3.3v it runs slower, but when I put it on pin 2(or any other pin I setup like this) it doesn't power the motor..

Any ideas on what I am doing wrong?

I'll post a Video this evening..

Thanks in advance for any help !

Dont try drive motors directly from the Arduino as there is a good chance you may damage it.
Motors can give off reverse spikes when stopping

Instead use a DRIVER shield or board of some description.
Almost any type of robot with motors uses the DRIVER approach.

Also avoid trying to drive motors directly from the Arduinos 5V and 3.3V pins but give them thier own PSU with a common ground.

Ok, I was planning on getting a motor driver shield but just wanted to see how far I could get without one..

It should still work in theory shouldn't it ? I wonder maybe my arduino board is broken

In theory a pin should instantly fry if you draw more than 40mA from it.
Practically, I have seen a pin survive a short for several minutes.
Russian roulette though.

Test the pins you have used with a LED with 220ohm resistor in series, and the blink example from the IDE.
Leo..

zodsrc:
what am I doing wrong?

Possibly not reading enough information and tutorials on the internet. That is, if you read enough tutorials starting from basics, then it might be possible to find out that there are no tutorials that involve driving a motor with a raw arduino pin directly.

@Op

You may try the following circuit using a Bc327 as a swich and DPin-2 as a control pin. Now, you have to execute digitalWrite(2, LOW); to activate the circuit so as to connect ~5V to the Motor Circuit.
bc327-1.png

bc327-1.png

That circuit could fry the transistor as well as the pin.
The pin is directly connected (shorted) to 5volt with only a BE diode in between.

Must use a resistor between base and pin (same as you do with an NPN transistor, low-side).
Leo..

Wawa:
That circuit could fry the transistor as well as the pin.
The pin is directly connected (shorted) to 5volt with only a BE diode in between.

Must use a resistor between base and pin (same as you do with an NPN transistor, low-side).
Leo..

bc327-1.png
Figure-1: PNP transistor based switch

1. When DPin-2 assumes LL-state, the gain (alpha) of Q1 is very close to unity (~0.9); 5V of the E-point immediately appears at the C-point. Most of the currents due to majority carrier (the holes) crosses the C-junction and then goes to the load. I don't see any safety threat neither for Q1 nor for 5V tolerant/20 mA Dpin-2. Edit: in view of Post#8. (A resistor is needed between base and Dpin-2 (Fig-3) to protect the transistor.)


Figure-2: Current distribution in PNP transistor

2. If a resistor (R2 in Fig-3) is placed between the Base and Dpin-2 of Fig-1, the Q1 could not be made ON due to base voltage > 0.7V coming from the voltage divider. The base voltage of Q1 must be very close to 0V for the transistor to enter into saturation zone. Edit: in view of Post#8.
bc327-3.png
Figure-3

bc327-1.png

bc327-3.png

Time to review how a PNP transistor works.
The EB junction is a diode, and base can't be less than "VCC - 0.7volt".
Leo..

Wawa:
Time to review how a PNP transistor works.
The EB junction is a diode, and base can't be less than "VCC - 0.7volt".

Really, getting old; yes, the transistor will become fully ON for VEB = 0.7V; therefore, a voltage divider circuit is indeed needed at the base to consume the 4.3V drop and thus protecting the transistor.

A BJT is current driven, so only a current limiting resistor between pin and base is needed here.

A resistor between emitter and base is only sometimes used to make sure the transistor is fully 'off'.
Not needed here, because the Arduino pin can pull the base fully to emitter level.
Leo..

Thanks for the insight , I will continue studying more tutorials and learn more..

@GolamMostafa thanks for posting that alternative solution !

zodsrc:
Ok, I was planning on getting a motor driver shield but just wanted to see how far I could get without one..

You can easily get totally fried Arduino.

Any inductive load can put killer voltage pulses onto pins if connected directly - never connect
an inductive load to any output not specifically designed to handle one.

It should still work in theory shouldn't it ? I wonder maybe my arduino board is broken

It cannot possibly work, motors need current measured in amps, not milliamps, and see above too.