Arduino: L293D for a DC motor

L293D for a DC motor


A L293D motor controller chip and a DC motor. L293D and a DC motor

I got fed up with indecipherable pinout diagrams within datasheets, so have designed my own that I think gives more pertinent information.

There are 3 wires connected to the arduino, 2 wires connected to the motor, and 1 wire connected to a battery.

A L293D motor controller chip - pinout diagram.
Green - connected to arduino.
Blue - connect to motor
Pink - connect to a battery +ve, eg 12 volt.
L293D and a DC motor

To use this pinout:
The left hand side deals with the first motor, the right hand side deals with a second motor.
Yes, you can run it with only one motor connected.

Arduino Connections
M1 PWM - connect this to a PWM pin on the arduino. They're labelled on the Uno, pin 3 is an example. Output any integer between 0 and 255, where 0 will be off, 128 is half speed and 255 is max speed.

M1 direction 0/1 and M1 direction 1/0 - Connect these two to two digital arduino pins. Output one pin as HIGH and the other pin as LOW, and the motor will spin in one direction. 
Reverse the outputs to LOW and HIGH, and the motor will spin in the other direction.

A L293D motor controller chip - pinout diagram.
Green - connected to arduino.
Blue - connect to motor
Pink - connect to a battery +ve, eg 12 volt.
L293D and a DC motor

To use this pinout:
The left hand side deals with the first motor, the right hand side deals with a second motor.
Yes, you can run it with only one motor connected.

Arduino Connections
M1 PWM - connect this to a PWM pin on the arduino. They're labelled on the Uno, pin 3 is an example. Output any integer between 0 and 255, where 0 will be off, 128 is half speed and 255 is max speed.

M1 direction 0/1 and M1 direction 1/0 - Connect these two to two digital arduino pins. Output one pin as HIGH and the other pin as LOW, and the motor will spin in one direction. 
Reverse the outputs to LOW and HIGH, and the motor will spin in the other direction.


The code below does not use a separate power supply (ie a battery), it uses instead the 5v power from the arduino. Note that this would be risky without the L293D controlling it. 
You should _never_ connect a motor directly to the arduino, because when you switch a motor off you get an electrical feedback. With a small motor, this will damage your arduino, and with a large motor, you can watch an interesting flame and sparks effect.

Wired up.
L293D Pin : Arduino Pin
1	:	3
2	:	5
3	(DC motor +5V) 
4	(GND)
5	(GND)
6	(DC motor GND)
7	:	4
8	(+5V)

9	:	6
10	:	8
11	(DC motor #2 +5V)
12	(GND)
13	(GND)
14	(DC motor #2 GND)
15	:	7
16	(+5V)
joystick

This is the code that I used.

A L293D motor controller chip - pinout diagram.
Green - connected to arduino.
Blue - connect to motor
Pink - connect to a battery +ve, eg 12 volt.
L293D and a DC motor

To use this pinout:
The left hand side deals with the first motor, the right hand side deals with a second motor.
Yes, you can run it with only one motor connected.

Arduino Connections
M1 PWM - connect this to a PWM pin on the arduino. They're labelled on the Uno, pin 3 is an example. Output any integer between 0 and 255, where 0 will be off, 128 is half speed and 255 is max speed.

M1 direction 0/1 and M1 direction 1/0 - Connect these two to two digital arduino pins. Output one pin as HIGH and the other pin as LOW, and the motor will spin in one direction. 
Reverse the outputs to LOW and HIGH, and the motor will spin in the other direction.


/************************
Exercise the motor using
the L293 chip
************************/

#define ENABLE 3
#define DIRB 4
#define DIRA 5


int i;
 
void setup() {
  //---set pin direction
  pinMode(ENABLE,OUTPUT);
  pinMode(DIRA,OUTPUT);
  pinMode(DIRB,OUTPUT);

 
Serial.begin(9600);

}

void loop() {
  //---back and forth example

Serial.println("One way, then reverse");
  digitalWrite(ENABLE,HIGH); // enable on
  for (i=0;i<5;i++) {
    digitalWrite(DIRA,HIGH); //one way
    digitalWrite(DIRB,LOW);
    delay(500);
    digitalWrite(DIRA,LOW);  //reverse
    digitalWrite(DIRB,HIGH);
    delay(500);
  }
  digitalWrite(ENABLE,LOW); // disable
  delay(4000);

Serial.println("fast Slow example");
  //---fast/slow stop example
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(1000);
  digitalWrite(ENABLE,LOW); //slow stop
  delay(3000);
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(1000);
  digitalWrite(DIRA,LOW); //fast stop
  delay(3000);

//Serial.println("PWM full then slow");
  //---PWM example, full speed then slow
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(2000);
  analogWrite(ENABLE,128); //half speed
  delay(2000);
  digitalWrite(ENABLE,LOW); //all done
  delay(10000);
}
   

All the above is in the public domain. It's included here to show which PIN settings work with which code.



原文链接:
http://www.goodliffe.org.uk/arduino/dcmotor.php


A L293D motor controller chip - pinout diagram.
Green - connected to arduino.
Blue - connect to motor
Pink - connect to a battery +ve, eg 12 volt.
L293D and a DC motor

To use this pinout:
The left hand side deals with the first motor, the right hand side deals with a second motor.
Yes, you can run it with only one motor connected.

Arduino Connections
M1 PWM - connect this to a PWM pin on the arduino. They're labelled on the Uno, pin 3 is an example. Output any integer between 0 and 255, where 0 will be off, 128 is half speed and 255 is max speed.

M1 direction 0/1 and M1 direction 1/0 - Connect these two to two digital arduino pins. Output one pin as HIGH and the other pin as LOW, and the motor will spin in one direction. 
Reverse the outputs to LOW and HIGH, and the motor will spin in the other direction.

前言: Arduino是一款很好的电子制作入门,有了电机扩展板可以很好的成为机器人开发平台。这里介绍一款能驱动各种简单到稍复杂项目的全功能的电机扩展板。这是一款常用的直流电机驱动模块,采用L293D芯片小电流直流电机驱动芯片。管脚被做成了Arduino兼容的,也方便了爱好者快速的基于Arduino的开发。 L293D电机驱动板概述: 该电机驱动板功能多,操作方便,有强大的驱动库支持及功能更新。适用于Arduino初学者,Arduino实验器材平台,Arduino互动电子,Arduino机器人等。可驱动4路直流电机或者2路步进电机的同时还能驱动2路舵机,支持最新Arduino UNO, Arduino Mega 2560 具体特性如下: 2个5V伺服电机(舵机)端口 联接到Arduino的高解析高精度的定时器-无抖动! 多达4个双向直流电机及4路PWM调速(大约0.5%的解析度) 多达2个步进电机正反转控制,单/双步控制,交错或微步及旋转角度控制。 4路H-桥:L293D 芯片每路桥提供.0.6A(峰值1.2A)电流并且带有热断电保护,4.5V to 36V。 下拉电阻保证在上电时电机保持停止状态。 大终端接线端子使接线更容易(10 - 22AWG)和电源。 带有Arduino复位按钮。 2个大终端外部电源接线端子 保证逻辑和电机驱动电源分离。 兼容Mega, Diecimila, & Duemilanove。 实物连接图如截图: L293D电机驱动板/马达板电路截图: L293D电机驱动板源码截图: 类似实物购买链接:https://s.taobao.com/search?q=motor+shield&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.7724922.8452-taobao-item.1&ie=utf8&initiative_id=tbindexz_20151127
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值