![]() The following program will move the DC motor attached to motor channel 1 of the motor shield either in forward, backward, accelerate, deaccelerate or stop according to command we send to the Arduino via serial port. ![]() It can take the parameters- FORWARD, BACKWARD, RELEASE This run() method will set the direction of rotation of the motor. This setSpeed() method will set the speed of the DC motor which takes one parameter that ranges from 0(lowest speed) to maximum of 255(highest speed). These methods are explained briefly below. Once the DC object is created, we can use it's various methods. If we do not specify the frequency then the default frequency is 1KHz. It is optional to specify the frequency parameter while creating the DC motor object. The frequency setting for channel 1 and 2 are:Īnd the frequencies for channel 3 & 4 are: The motor object accepts two parameters which are the number(1, 2, 3 or 4) or the channel of the motor where the motor will be connected to. ![]() For example the following line create a DC motor object called motor. For DC motors we have to use the class AF_DCMotor to create a dc motor object. Open a sketch and type in the following at the top in order to use the library functions.Īfter including the header file we have to create an object with some alias name. A 9V power supply is connected to the external power supply terminal. We will use different power supply to drive the Arduino UNO and the motor so we will remove the power selection jumper. In this tutorial we are going to attach a DC motor to the Motor connection port M1. PWM allows us to control the average voltage applied to the motor, which in turn controls its speed. To control the speed of the motor, we can use pulse-width modulation (PWM) on one of the digital I/O pins. The sketch will use the digital I/O pins on the Arduino to control the motor. Once the shield is connected to the Arduino and the DC motor, we can write a sketch (program) to control the motor. The shield has two motor connections, each with its own set of power and control lines. ![]() After connecting the shield to the Arduino, we can connect the DC motor to the shield. The shield has headers that are compatible with the headers on an Arduino board, so connecting the two is straightforward. To control the DC motor using an L 293D motor shield and an Arduino, we need to connect the shield to the Arduino board. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |