I set a value of 255 for analogWrite to get max speed, but in turn my motor rotate very slowly-compared to when I connect the motor directly to 5v + ground that it rotate fast.
...what can be happening? do I need more power?
all the connections and code are the same as the project in the link above..
As usual for Instructables, there are issues. A 9V transistor battery does not have the current capability to run a motor for long, if at all. The Arduino 5V regulator does not either. On top of that the ancient and very inefficient L293 motor driver's bipolar Darlington output stage drops 2 to over 4 volts of the motor supply current dumping it off as heat.
So, let's do a bit of engineering. What motor do you have? What is the motors rated voltage? What is the motors stall current? When we start from those facts, we can choose a proper motor driver and power source.
According to the L293 Datasheet, the typical low voltage at the outputs of the circuit is 1.2 V (at a load of 0.6 A), and the typical high voltage is Vcc2 - 1.4 V. That is, the voltage applied to the motor is about 2.6-3 V less than the Vcc2 supply voltage of the chip.
If your motor is on 6V, supply Vcc2 about 9V to the chip.
There are more powerful motor drivers, for example L298N (but with similar voltage drops), or as a last resort MOSFET module with high current and very low voltage drop. You may see next link IRF520 MOSFET Driver Module with detailed explanations and code examples.
cool, so you think that with that Mosfet module I could successfully obtain satisfactory results ?. Namely, to write a code in arduino so that the air blower motor varies speed randomly for long periods of time.
Or should I first try with the L298N?
You need first know the current drawn by the motor. If the current of the L293 is sufficient, you can use it, but apply a voltage 3 volts higher than the motor voltage (about 9V). If the current is not enough, you can take the L298N, but it also has a large voltage drop.
I would take a MOSFET transistor. For example, the IRF520 has a current of up to 5A and a minimum voltage drop, that is, you can power the pump from a 6V source. Moreover, if you just need to change the motor speed (without reverse), one transistor is enough.
Well, my idea is to connect it to the wall electricity through the arduino, so as not to run the risk that the batteries will run out, because the art installation will be open for 3 weeks, (although the devices will not be on all the time, only when the visitor activates the ignition sensors). Does it make sense to power the motor through the Arduino uno?
You must not power the motor through the arduino, you need supply power from the AC-DC adapter (6-9V) to the motor driver and to the arduino board. Arduino only needs to control the voltage supply to the motor by PWM. See link in post #11.
Some motor drivers have a built-in 5V voltage regulator that can be fed to the Vin of the arduino board.