Controlar Motores DC com L293D

Estou iniciando a pesquisa para saber como utilizar o H-BRIDGE L293D.

Esquema de portas do L293D:













Notice that the L293D supports two DC motors. Pin 16 is the +5 voltage for the chip, while pin 8 is the voltage for the motors. The first motor gets hooked directly to pins 3 and 6. The motor is turned on by sending a high signal to both the enable (pin 1) and one of the two direction pins, lets say pin 2, while keeping pin 7 low. To go the other direction keep the enable pin and pin 7 high while pin 2 goes low. To stop enable pin is high while both 2 and 7 are low.
The same goes for the other side of the chip. When driving two or more motors I like to hook pins 2 and 15 together and pins 7 and 10. Sorry to say I don’t remember what the specs are for this chip, I usually send about 6 volts through it with a 0.7-volt drop for the L293D internal transistors, and I expect a 200 to 300 milli-amps total for both motors.

Diferença ente driver e controler

•Motor drivers are the simplest modules in the sense that all they do is provide power amplification for low-level control signals (e.g. PWM and direction) supplied by the user; on the other hand, that means that the master device to which the motor driver is connected must take care of the low-level, resource-consuming signal generation.


•Motor controllers are motor drivers with additional intelligence: an on-board microcontroller generates the low-level signals and presents the user with higher-level interfaces and commands. For example, our dual serial motor controllers allow two DC motors to be controlled by a single serial line, and the master controller simply issues commands only when the speeds of the motors should be changed. Other motor controllers are even more complex, incorporating advanced acceleration commands, current sensing, feedback-based control, and more


Abaixo os links iniciais de referencia:

Descrição completa da montagem e programação com duemilenove

http://luckylarry.co.uk/2009/07/control-a-dc-motor-with-arduino-and-l293d-chip/

http://www.seattlerobotics.org/Encoder/sep97/motors.html

http://letsmakerobots.com/node/2074

http://arduino.cc/en/Main/ArduinoMotorShield

http://robot-overlord.blogspot.com/2009/06/controlling-dc-motor-using-arduino-usb.html

http://www.pololu.com/catalog/product/1112

Muito Bom:





int motor1 = 2; //declares the first pin for the motor




int motor2 = 4; //declares the other pin for the motor



int motorpmw = 9; // this is the pmw that will set how much battery power the motor is getting (speed)



void setup()

{

pinMode(motor1, OUTPUT); //

pinMode(motor2, OUTPUT); // these simply are declaring them as outputs

pinMode(motorpmw, OUTPUT); //

}



void loop()

{

analogWrite(motorpmw, 255): // this is the analog speed value for the arduino (0-255)

digitalWrite(motor1, HIGH);

digitalWrite(motor2, LOW); //turns the motors on - forwards



delay(1000); // resets the coding sequence and refiles all the commands under the y-drive of the mainframe.

digitalWrite(morot1, LOW);

digitalWrite(motor2, HIGH); //makes motor go backwards



delay(1000); //summons demons to influence the creation of man into waiting for exactly 1 second.

---------------------------------------------------------------------------------------


https://sites.google.com/a/divinechildhighschool.org/electronics/Home/Arduino-Lessons/h-bridge











Program the Microcontroller


Program the microcontroller to run the motor through the H-bridge:

-------------------------------------------------------------------------------

const int switchPin = 2; // switch input

const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)

const int motor2Pin = 4; // H-bridge leg 2 (pin 7, 2A)

const int enablePin = 9; // H-bridge enable pin

const int ledPin = 13; // LED



void setup() {

// set the switch as an input:

pinMode(switchPin, INPUT);



// set all the other pins you're using as outputs:

pinMode(motor1Pin, OUTPUT);

pinMode(motor2Pin, OUTPUT);

pinMode(enablePin, OUTPUT);

pinMode(ledPin, OUTPUT);



// set enablePin high so that motor can turn on:

digitalWrite(enablePin, HIGH);



// blink the LED 3 times. This should happen only once.

// if you see the LED blink three times, it means that the module

// reset itself,. probably because the motor caused a brownout

// or a short.

blink(ledPin, 3, 100);

}



void loop() {

// if the switch is high, motor will turn on one direction:

if (digitalRead(switchPin) == HIGH) {

digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low

digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high

}

// if the switch is low, motor will turn in the other direction:

else {

digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high

digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low

}

}



/*

blinks an LED

*/

void blink(int whatPin, int howManyTimes, int milliSecs) {

int i = 0;

for ( i = 0; i < howManyTimes; i++) {

digitalWrite(whatPin, HIGH);

delay(milliSecs/2);

digitalWrite(whatPin, LOW);

delay(milliSecs/2);

}

}


-----------------------------------------------------------------------------------
Once you've seen this code working, try modifying the speed of the motor using the analogWrite() function, as explained in the Analog Lab. Use analogWrite() on pin 9, the enable pin of the motor, and see what happens as you change the value of the analogWrite().


http://itp.nyu.edu/physcomp/Labs/DCMotorControl

--------------------------------------------------------------------------------

http://fritzing.org/media/fritzing-repo/projects/a/arduino-motor-driver/fritzing/MotorDriver.fz

http://fritzing.org/projects/arduino-motor-driver/

-------------------------------------------------------------

adafruit motor driver com mega

http://www.adafruit.com/blog/2009/06/29/afmotor-library-for-arduino-mega-use-the-motorshield-with-the-mega/

-----------------------------------------------

http://luckylarry.co.uk/2009/08/obstacle-avoidance-robot-build-your-own-larrybot/

alternativa com chip Texas Instruments SN754410.

lista

10Kohm resistors

2x 220nF multilayer ceramic capacitor (Y5V)

2 x 50V 10uF Capacitor (although I’ve not used them here)


----------------------------------------------------------------------------------------------

http://akashxav.com/2009/04/18/arduino-l293d-dc-motor/


error: as some people have pointed out in the comments, the circuit diagram has an error, pins 6 & 7 on the L293D end have been exchanged in the diagram. L293D’s Pin-6 has to go to the motor while pin-7 has to go to Arduino’s pin-7











The datasheet for the L293D can be found everywhere on the net. The exact chip name is “L293DNE”. It’s a 16-pin chip used to drive motors (and hence called a motor driver chip). This chip is capable of driving one servo or two DC motors. My task was to connect and control one DC motor using the Arduino and rotate it in both the directions.



Pin-8 on the L293D chip is the pin to which power supply for the motor is to be provided. Since I’m using a 3V DC motor here, I’m only providing 3V via the external supply. This HowTo concentrates on controlling one DC motor. so it’s pretty straight forward. If you are connecting 2 DC motors of 3V each, you’ll be powering the chip with 6V (= 3V +3V). When you set one motor to off, then the 6V will be passed to the other 3V motor, therefore burning the motor. So when you control 2 DC motors make sure you have resistors of suitable value for both the motors. Thanks to Martin for pointing this out, when you run 2 DC motors simultaneously you’ll require the same 3V voltage input, just the current required will be double. So don’t pass 6V! And resistors don’t have to be used.



Pin-9 of the Arduino connected to pin-1 of the L293D, is used to control the state of the motor(on/off) and is referred to as the ‘enablePin’ or the ‘PWM pin’. This can be digital or analog. Pin-16 of the L293D is the Logical Power supply. It has to be powered with 5V via the Arduino’s 5V pin or via an external power supply. Here the Arduino’s 5V pin is being used.



Pin-9 of the Arduino connected to pin-1 of the L293D, is used to control the state of the motor(on/off). This can be digital or analog. Pin-16 of the L293D is the Logical Power supply. It has to be powered with 5V via the Arduino’s 5V pin or via an external power supply. Here the Arduino’s 5V pin is being used.



Analog pins of the Arduino have not been used in this HowTo. Pins 6,7 and 9 of the Arduino were chosen randomly with no particular reason. So if you wish to use some other pins, you are free to do so, but just make sure you change the pin numbers in the program also.





An LED connected to pin-13 blinks 3 times before changing the directions of the motor.



int enablePin = 9; //Motor's enable pin

int dPin_1 = 6;// Digital Pin to turn the motor on/off

int dPin_2 = 7;

int ledPin = 13; //LED pin



void setup()

{

pinMode(enablePin, OUTPUT);

pinMode(dPin_1, OUTPUT);

pinMode(dPin_2, OUTPUT);

pinMode(ledPin, OUTPUT);

}



void loop()

{

digitalWrite(enablePin, HIGH);

digitalWrite(dPin_1, HIGH); //turn on the motor

digitalWrite(dPin_2, LOW);



delay(5000); //delay for 5 seconds



//switch directions

digitalWrite(enablePin, LOW);

digitalWrite(enablePin, HIGH);



delay(3000);



digitalWrite(dPin_1, LOW);

digitalWrite(dPin_2, HIGH);



blink(ledPin, 3, 500);



digitalWrite(ledPin, LOW); // turn off LED

digitalWrite(dPin_1, LOW); //turn off motor

delay(2000); //delay for 2 seconds.

}



void blink(int whatPin, int howManyTimes, int howLong) {

int i = 0;

for ( i = 0; i < howManyTimes; i++) {

digitalWrite(whatPin, HIGH);

delay(howLong);

digitalWrite(whatPin, LOW);

delay(howLong);

}

}





Note: I noticed that the motor had problems when the directions were switched immediately. Therefore delay() is being used to give the motor sometime to come to a halt and switch directions.







Using PWM to control the motor

It is also possible to control the motor using Pulse Width Modulation (PWM). I noticed that it is almost useless to apply PWM to a non-geared DC motor. Applying it to a geared motor makes sense, since it’s speed is slow and a bit of precision is possible. Anyway, the motor used here is a non-geared DC motor.



The enablePin previously used is now used to apply PWM on the motor. Now instead of using the digitalWrite(), analogWrite() will be used to fake analog output and therefore apply PWM.



An LED connected to pin-13 of the Arduino turns on when the motor is on and turns off when the motor is off. This is just to show that the motor is on. After reaching to it’s max speed, there is a delay of one second before which the speed is being decreased by using analogWrite().



int pwmPin = 9; //Motor's PWM pin

int dPin_1 = 6;// Digital Pin to turn the motor on/off

int dPin_2 = 7;

int ledPin = 13; //LED pin



void setup()

{

pinMode(dPin_1, OUTPUT);

pinMode(dPin_2, OUTPUT);

pinMode(ledPin, OUTPUT);

}



void loop()

{

digitalWrite(ledPin, HIGH); // turn on LED

digitalWrite(dPin_1, HIGH); //turn on the motor

digitalWrite(dPin_2, LOW);



//Apply PWM to the motor

for(int i=0; i<=255; i++)

{

analogWrite(pwmPin, i);

delay(100);

}



delay(1000); //delay for a second



//switch directions

digitalWrite(dPin_1, LOW);

digitalWrite(dPin_2, HIGH);



for(int i=255; i>=0; i--)

{

analogWrite(pwmPin, i);

delay(100);

}



digitalWrite(ledPin, LOW); // turn off LED

digitalWrite(dPin_1, LOW); //turn off motor



delay(2000); //delay for 2 seconds.




importante:

hi,


I tested the programs in arduino 0017 soft, and when compiling show me this mistakes:

1 example)for ( i = 0; i < howManyTimes; i++) {

In function ‘void blink(int, int, int)’:

error: ‘lt’ was not declared in this scope

2 example)

for(int i=0; i<=255; i++)

error: “it” was not declared in this scope

In function ‘void loop()’:

error: ‘lt’ was not declared in this scope

I has suprimed the led definition and works well, regards.


-------------------------------------------------------------------

nova pesquisa em 20/12/2009

http://www.doc.ic.ac.uk/~ih/doc/stepper/control2/flpystpr/flpystpr.txt

http://www.lima.com.tr/BasicTiger/Applications/PDF/appn_061e_Control%20bipolar%20stepper%20motors%20with%20SN754410.PDF

http://www.circuit-projects.com/control-circuits/bipolar-stepper-motor-driver.html

http://itp.nyu.edu/physcomp/Tutorials/StepperL293HBridge

http://www.ladyada.net/make/mshield/use.html

http://www.acroname.com/examples/10047/10047.html

http://www.kronosrobotics.com/an106/SMAN106.htm

Nenhum comentário:

Postar um comentário

Faça seu comentário.

Internet of Things

LUX com arduino GPRS shield e sensor LDR.

/*
Graph: Feed 38642, Datastream lux
*/

Laboratórios, Lojas e Produtos

Blogs, Comunidades e Revistas