Arduino: L293D for a DC motor
来源:互联网 发布:知乎 张汶祥 编辑:程序博客网 时间:2024/06/05 14:33
L293D for a DC motor
A L293D motor controller chip 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.
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.
Green - connected to arduino.
Blue - connect to motor
Pink - connect to a battery +ve, eg 12 volt.
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 Pin1:32:53(DC motor +5V) 4(GND)5(GND)6(DC motor GND)7:48(+5V)9:610:811(DC motor #2 +5V)12(GND)13(GND)14(DC motor #2 GND)15:716(+5V)
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.
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 usingthe L293 chip************************/#define ENABLE 3#define DIRB 4#define DIRA 5int i; void setup() { //---set pin direction pinMode(ENABLE,OUTPUT); pinMode(DIRA,OUTPUT); pinMode(DIRB,OUTPUT); Serial.begin(9600);}void loop() { //---back and forth exampleSerial.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
Green - connected to arduino.
Blue - connect to motor
Pink - connect to a battery +ve, eg 12 volt.
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 for a DC motor
- 使用L293D驱动板(for Arduino)对电动机进行驱动
- DC Motor 参数的理解
- Arduino: Ultrasonic Sensor & Motor Car
- arduino L293D电机扩展模块入门 Reference
- Brushless DC electric motor(无刷直流电机)
- L293D电机驱动版在Arduino上使用笔记
- Inductor for DC-DC
- motor
- Motor Drive Forum Top FAQs Part 1: How to read a motor driver datasheet
- 用WIZwiki-W7500 和 Arduino Motor Shield 进行网页电机控制
- Arduino IDE for ESP8266
- 3A DC/DC 降压芯片电路,开关电源
- motor joint
- UAV Motor
- L293/L293d使用总结
- DMX512 for Arduino 例子详解
- Arduino IDE for ESP8266教程
- javascript--继承&多态
- 第一个博客
- Android小知识清单(二)
- html调试研究(二)-样式修改的一些规范
- VB中调用VC++开发的DLL
- Arduino: L293D for a DC motor
- 最新Eclipse SVN插件地址
- leetcode刷题系列C++-rotate image
- 原html标签分类
- Intent 传递对象
- 设计模式之——工厂模式(FactoryMethodPattern)
- html调试研究(三)-样式修改的需要了解的几个方面
- [Python学习]Python中的with语法
- java集合深度复制