Arduino output

Every time I try to program to give a 5V output from a pin it does not spin a motor at full speed. But when connected the the 5V output directly in the Arduino it spins at full speed. This means that the volt or current (I really don't know what is affecting the motor speed) is low. I tried giving analog 255 output, digital HIGH output, connected a 8V battery, but nothing works. Before when I bought it it worked well.
Please can someone tell me how to rectify this mistake ?

Thank you in advance.

Please can someone tell me how to rectify this mistake ?

Don't drive the motor directly from the pin as it very likely cannot provide enough current and the Arduino circuitry could be damaged by taking excess current.

Instead, drive a MOSFET from the pin and the motor from that using an external power supply with a common GND connection to the Arduino.

I tried giving analog 255 output, digital HIGH output, connected a 8V battery, but nothing works.

It sounds like you have already damaged the Arduino.

Do you have any understanding of basic electrical circuits ?
Voltage ?
Current ?
Resistance ?
Ohms Law ?

UKHeliBob:
Don't drive the motor directly from the pin as it very likely cannot provide enough current and the Arduino circuitry could be damaged by taking excess current.

Instead, drive a MOSFET from the pin and the motor from that using an external power supply with a common GND connection to the Arduino.
It sounds like you have already damaged the Arduino.

Do you have any understanding of basic electrical circuits ?
Voltage ?
Current ?
Resistance ?
Ohms Law ?

Yhea I have basic understanding and some practical knowledge of using it those electrical terms.

And i dont understand by what mean you say i have damaged the arduino by giving analog values, but i am pretty sure that has not happened as i am still able to use those pins for my gyroscope and other things.

Thanks.

And i dont understand by what mean you say i have damaged the arduino by giving analog values,

It wasn’t the output values that worried me it was the 8V. How exactly did you have it connected ? A circuit diagram would help

UKHeliBob:
It wasn't the output values that worried me it was the 8V. How exactly did you have it connected ? A circuit diagram would help

When i told 8v i actually meant connecting 7.8v battey to the arduino for power. I told this because when i asked somewhere else (at a time when i was using just usb power) it might not be enough and i would need to use a battery.

Anyway thanks for your reply...really helped me.

If you just used the 8V to power the Arduino then you are probably OK, but you will have still only got a maximum of 5V on an output pin (actually slightly less)

What sort of motor are you trying to control ?