Mengontrol DC Motor Menggunakan Arduino Uno dan Adafruit MotorShield

Arduino is a great starting point for electronics, and with a motor shield it can also be a nice tidy platform for robotics and mechatronics. Here is a design for a full-featured adafruit motor shield that will be able to power many simple to medium-complexity projects.

Check that inside AFMotor is AFMotor.cpp and AFMotor.h files. If not, check the steps above

Place the AFMotor folder into your arduinosketchfolder/libraries folder. For Windows, this will probably be something like MY Documents/Arduino/libraries for Mac it will be something likeDocuments/arduino/libraries. If this is the first time you are installing a library, you’ll need to create the libraries folder. Make sure to call it librariesexactly, no caps, no other name.

Check that inside the libraries folder there is the AFMotor folder, and insideAFMotor isAFMotor.cppAFMotor.h and some other files

Quit and restart the IDE. You should now have a submenu called File->Examples->AFMotor->MotorParty

Second Step

The motor shield can drive up to 4 DC motors bi-directionally. That means they can be driven forwards and backwards. The speed can also be varied at 0.5% increments using the high-quality built in PWM. This means the speed is very smooth and won’t vary!

Note that the H-bridge chip is not meant for driving loads over 0.6A or that peak over 1.2A so this is for small motors. Check the datasheet for information about the motor to verify its OK.

To connect a motor, simply solder two wires to the terminals and then connect them to either the M1, M2, M3, or M4. Then follow these steps in your sketch

Make sure you #include <AFMotor.h>

Create the AF_DCMotor object with AF_DCMotor(motor#, frequency), to setup the motor H-bridge and latches. The constructor takes two arguments.
The first is which port the motor is connected to, 1, 2, 3 or 4.frequency is how fast the speed controlling signal is.
For motors 1 and 2 you can choose MOTOR12_64KHZ, MOTOR12_8KHZ,MOTOR12_2KHZ, orMOTOR12_1KHZ. A high speed like 64KHz wont be audible but a low speed like 1KHz will use less power. Motors 3 & 4 are only possible to run at 1KHz and will ignore any setting given

Then you can set the speed of the motor using setSpeed(speed) where thespeed ranges from 0 (stopped) to 255 (full speed). You can set the speed whenever you want.

To run the motor, call run(direction) where direction is FORWARD,BACKWARD or RELEASE. Of course, the Arduino doesn’t actually know if the motor is ‘forward’ or ‘backward’, so if you want to change which way it thinks is forward, simply swap the two wires from the motor to the shield.

If your step is correct, your motor in channel 1 will be running for 3 second and stop for 1 second. After that the motor will running again for 3 second but in reversed direction and stop for next 1 second. This condition will be looping as long as you give power to the board and motor.