Mostrando postagens com marcador H-bridge. Mostrar todas as postagens
Mostrando postagens com marcador H-bridge. Mostrar todas as postagens

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

H-Bridge

Pesquisa sobre H-brige, seu funcionamneto e aplicações.

Um robô (ou outra coisa qualquer que vc criar) pode movimentar-se com rodas,  pernas, esteiras, engrenagens  ou o que for. Em geral os motores mais simples para dar este movimento são os chamados Motores DC. Os motores DC são os mais simples e utilizados nos carrinhos de brinquedo. Existem diversos tipos de motores DC  ( brushed, brushless, stepper) mas básicamente seu funcionamento é o mesmo.


Mini Motor DC

Uma corrente cria campo magnético  e faz com que os imãs do rotor do motor girem para um lado ou para o outro. Ao aplicar-se corrente positiva no pólo positivo o motor gira para um lado, ao reverter aplicando corrente positiva no pólo negativo o motor gira para o outro lado, a sua velocidade também pode ser controlada pela intensidade da corrente aplicada ( acho que todo mundo sabe disso mas como a explicação é para mim mesmo.. vale a pena ser óbvio).

Você não vai querer ficar trocando os fios nos pólos dos motores do seu robô, todas as vezes que quizer que ele mude de direção, deve haver alguma forma de controlar isso a partir de comandos do microcontrolador e do software utilizado ( foi assim que eu pensei....).

No começo fiquei meio confuso, tentando entender como isso funciona, não sou um tecnico de eletrônica e demorei um pouco para juntar as peças. A primeira coisa que descobri é que existe um tipo especial de elemento eletrônico chamado de Transistor ( eu já sabia que existia isso ..assim como você...).


Transistor

Ao pesquisar entendi que este pequeno elemento tem a função de permitir a passagem ou bloquear a corrente elétrica. Uma boa explicação pode ser encontrada aqui não deixe de ler. Isto é feito pela mudança de estado dos eletrons dos materiais especiais dos quais ele é feito, é muito interessante e uma leitura muito útil para entender o mundo em que vivemos pois este pequeno componente está em todos os produtos que usamos no dia a dia.

Uma das muitas aplicações dos transistores é automatizar a troca de corrente nos pólos do motor para que ele gire para um lado ou para o outro dependendo da necessidade do seu projeto. Para evitar um obstáculo, para ir atrás da luz, para reagir a estímulos externos e tomar as direções desejadas. Existe também um outro elemento eletrônico chamado de MOSFET que tem a mesma função mas é controlado por pulsos lógicos do controlador ( 0/1), os dois podem ser usados com a mesma finalidade.

Juntando quatro transistores que funcionam como interruptores nas pontas de uma estrutura em H e no meio colocando o motor temos o que se chama de H-bridge. Dependendo da forma como a enegia é aplicada, o roteamento da corrente pode ser modificado, direcionando corrente positiva, negativa ou nenhuma corrente a cada um dos pólos do motor independentemente.



Esquema básico das formas de uso de uma H-BRIDGE , clique na imagem para carregar o .pdf com uma explicação ilustrada e completa.

Veja uma imagem de uma H-BRIDGE montada com quatro transistores para cada circuito, logo esta placa pode controlar 2 motores.


Existem também chips especiais que contém  todo este circuito internamente, eles podem fazer o trabalho de uma placa inteira como a que está acima dentro de um pequeno espaço ( mas não com a mesma carga). Um deles é o L293D, um chip H-brige muito usado para controlar motores em projetos de robótica




Conclusão:

Um circuito H-bridge serve para controlar a direção da movimentação de um motor. De acordo com a polaridade da corrente enviada a este circuito pelas portas do microprocessador existe a mudança de estado dos transistores e o roteamento da corrente de positivo para negativo ou de negativo para positivo em cada um dos pólos do motor.


Obs. Estas páginas são escritas para que eu mesmo possa entender, de forma alguma estão totalmente corretas e completas. Se você tem correções, comentários ou observações, serão muito bem vindas.

Motor de Passo Unipolar

Fazer funcionar um motor de passo UNIPOLAR com H-BRIDGE.



No vídeo acima aparece o motor funcionando com um script que gera movimentos aleatórios variando a velocidade e direção, este controle é feito pela placa arduino, a placa que se vê ao lado do motor é a placa com os transistores que controlam a força aplicada a cada bobina do motor na sequencia desejada.

Inicialmente o conceito do motor de passo é bastante confuso porque trata-se de um motor movido por várias bobinas que quando acionadas em séries fazem com que o motor mova-se em passos ou em rotação em qualquer direção.

MATERIAIS USADOS:


1. Motor de passo SM 1.8 NEMA 23











2. Placa CNC com 2 conjuntos de 4 Transistors Transistor darlington NPN, max 100V 5A. ( fabricação microgenius)


O TIP122 é um transistor NPN do tipo darlington (ou seja: são dois transistores dentro do mesmo invólucro, um excitando o outro, de maneira a se aumentar muito o ganho total). Ele foi desenvolvido para aplicações de chaveamento (tanto que já possui um diodo interno para a proteção da junção coletor/emissor do transistor). "clube do hardware"







3.
Arduino Duemilenove ( arduino.cc)

4. Bateria de 12 volts 7 amp ( First Power) - roubada de um alarme :-)


O site AZEGA.COM me ajudou muito a entender o processo, este site tem os equemas e o conhecimento necessário para fazer o trabalho (veja os links abaixo).

Este exemplo  é  igual ao esquema da placa acima e utiliza os mesmos transistores NPN para ser montado na breadboard:


















Para controlar o movimento do motor é utilizada a biblioteca stepper, esta biblioteca permite setar os seguintes parâmetros como comentado no exemplo abaixo:


//-----------------------------------------------------------------------------------

#include

// define os passos do  motor ( ângulo do passo % 360 =  passos para uma volta completa)
#define STEPS 200

// cria uma instancia da classe stepper com o número de passos e os pinos que vao atuar
Stepper stepper(STEPS, 2, 3, 4, 5);
void setup()

{

// define o numero de  RPM a ser aplicado ( o meu motor travou com 200, preciso descobrir porque)
stepper.setSpeed(100);

}
void loop()

{

// define o numero de passos a realizar
stepper.step(200);

// para dar uma parada antes de realizar outra volta
delay(1000);

}

//------------------------------------------------------------------------

Controlando Dois Motores de passo
























Para controlar dois motores de passo bastou criar outra instância do objeto stepper e definir os pinos, rpm e passo:

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

#include
// define os steps dos motores

#define STEPS 200

// cria os objetos , desta vez usei mais 4 pinos da duemilanove - 8, 9, 10, 11

Stepper stepper0(STEPS, 2, 3, 4, 5);

Stepper stepper1(STEPS, 8, 9, 10, 11);

void setup()

{

// define o RPM de cada motor

stepper0.setSpeed(100);

stepper1.setSpeed(100);

}

void loop()

{

// define o numero de passos, note que com valor negativo e controlada a direção.

stepper0.step(-200);

stepper1.step(200);

//delay(1000);

}

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

Visão da placa cnc com todos os fios conectados:

























Referencias Principais:
SITE AZEGA.COM ( LEIA AS DUAS PARTES  - O .PDE ESTÁ POSTADO Á)
TOM IGOE - Stepper Motor Control

Outras Pesquisas:

link para site com esquema de controle usando H-Bridge:

http://www.azega.com/controlling-a-stepper-motor-with-an-arduino-part-2/

Animação com motor de passo, muito bom para entender o funcionamento


Controlar motor de passo com L293D : H BRIDGE:

http://www.seattlerobotics.org/Encoder/may98/steppers.html   

http://www.8051projects.net/stepper-motor-interfacing/stepper-motor-connections.php

http://www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/

http://www.slscope.co.uk/electronics_projects/arduino/projects/dual_stepper_motor_controller/dual_stepper_motor_controller_2.html

http://dorkbotpdx.org/blog/feurig/scary_george_driving_a_floppy_drive_stepper_with_the_arduino_wiring_platform

Com detalhes para vários motores mas hardware montado:

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

http://s217877884.websitehome.co.uk/electronics_projects/arduino/projects/dual_stepper_motor_controller/dual_stepper_motor_controller_software.html

This project now provides for control of two bi-polar stepper motors via an Arduino either from instructions issued from a PC (personal computer) to the USB/Serial port, or by operating switches connected to the analogue input lines of the Arduino.
http://s217877884.websitehome.co.uk/electronics_projects/arduino/projects/dual_stepper_motor_controller/dual_stepper_motor_controller_software.html

Curiosidades com motor de passo:

http://www.urbanhonking.com/ideasfordozens/2009/10/real_pen_etchasketch_with_step.html

Site wiring:

http://www.wiring.org.co/learning/libraries/steppermove.html





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