Motor connected with port1 (M1 and M2) Then we will create an object of the library called motor and specify the steps per revolution of the motor as the first parameter and the port number with which we have connected the stepper motor as the second parameter. If using 28BYJ-48 instead set the value to 48. This is the number of steps our motor requires to move one complete revolution. The next step is to define the steps per revolution. This library provides useful functions that make it easy to control the motors using Arduino. Motor connected with port1 (M1 and M2)įirstly, we will include the AFMotor.h library. void loop()Ĭonst int steps_per_rev = 200 //Set to 200 for NIMA 17 and set to 48 for 28BYJ-48 Then the motor stops and after a delay of 1 second the loop starts again. Then the motor will rotate in the opposite direction by first speeding up and then slowing down. Inside the loop() function we will first rotate the motor in forward direction where it will first speed up and then speed down using a for loop. It can take in three arguments: RELEASE (stops the motor), FORWARD (motor moves in the forward direction), BACKWARD (motor moves in the backward direction). The run() method is used to set the mode of the motor. This is because initially the motor will not move. Additionally, we will use the run() method on the motor instance with ‘RELEASE’ as an argument inside it to stop the motor. The speed of the motor can take values from 0-255. Inside the setup() function, we will use the setSpeed() method on the motor instance and pass the speed of the motor as an argument inside it. In our case we connected the dc motor with M3 hence ‘3’ is specified as the parameter inside it. Next we will create an instance of AF_DCMotor called motor and specify the motor port we are connecting our motor with. This basic sketch will show us how to control a DC motor’s speed and direction of rotation using the L293D motor driver shield with the AFMotor.h library. Copy the code given below in that file and save it. Open your Arduino IDE and go to File > New. There are different ways we cam power both the driver shield and the motors. Now let us discuss another important aspect which is the power supply connections and considerations. One important point to note here is that this driver shield supports motors with voltages between 4.5-25V only. If using a unipolar stepper motor the GND terminals will be connected to the centre taps of the stepper motors. The M1,M2 terminals will connect stepper motor 1 and M3,M4 will connect stepper motor 2. Additionally, we can also connect two unipolar/bipolar stepper motors at these terminals instead. We will be able to connect four DC motors rated at 4.5-25 V at these terminals. At both the left and right sides you can view five pin terminals. You will be able to connect two servo motors at these terminals as a single servo motor comes with three wires that need to be connected. At the top left corner you can view two three pin headers. ![]() Two servo motors, Four DC Motors and Two stepper motor connections can be found on this motor driver shield.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |