CODE | L293D Motor Driver IC - Arduino Project 016

RonWang2 years ago (2023-09-27)电子编程 COD4

In the previous project, you used a transistor to control the motor. In this project, you are going to use a very popular motor driver IC called an L293D. The advantage of using this chip is that you can control two motors at the same time, plus you can control their direction. The chip can also be used to control a stepper motor, as you will find out in Project 28. (You can also use a pin-for-pin compatible chip known as the SN754410, which has a higher current rating.) Notice anything missing from the parts list  Diodes, perhaps? Not to worry; the IC has its own internal diodes, so you do not need one for this project.

项目Project 16  Using an L293D Motor Driver IC 

/* Coding Ron Wang
   Sep.3rd 2024
   Autaba support for coding hardware
 */
// Project 16 - Using an L293D Motor Driver IC
#define switchPin 2 // switch input
#define motorPin1 3 // L293D Input 1
#define motorPin2 4 // L293D Input 2
#define speedPin 9 // L293D enable Pin 1
#define potPin 0 // Potentiometer on Analog Pin 0
int Mspeed = 0; // a variable to hold the current speed value

void setup() {
//set switch pin as INPUT
pinMode(switchPin, INPUT);
// set remaining pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(speedPin, OUTPUT);
}

void loop() {
 Mspeed = analogRead(potPin)/4; // read the speed value from the potentiometer
 analogWrite(speedPin, Mspeed); // write speed to Enable 1 pin
 if (digitalRead(switchPin)) { // If the switch is HIGH, rotate motor clockwise
 digitalWrite(motorPin1, LOW); // set Input 1 of the L293D low
 digitalWrite(motorPin2, HIGH); // set Input 2 of the L293D high
 }
 else { // if the switch is LOW, rotate motor anti-clockwise
 digitalWrite(motorPin1, HIGH); // set Input 1 of the L293D low
 digitalWrite(motorPin2, LOW); // set Input 2 of the L293D high
 }
}

Arduino L293D Motor Driver IC Circuit

Arduino L293D Motor Driver IC Schematic

Share with Friends:

Related Articles

CODE | Shift Register 8-Bit Binary Counter - Arduino Project 017

CODE | Shift Register 8-Bit Binary Counter - Arduino Project 017

In this project, you’re going to use additional ICs (Integrated Circuits) in the form of shift regis…

CODE | LED Dot Matrix Display Scrolling Message - Arduino Project 021

CODE | LED Dot Matrix Display Scrolling Message - Arduino Project 021

There are many different ways to drive LEDs. Using shift registers is one way and they have their a…

Arduino software Download

Arduino software Download

Arduino Web EditorStart coding online and save your sketches in the cloud. The most up-to-date versi…

Python Programming Languages Suitable for Children

Python Programming Languages Suitable for Children

Python 适合儿童的编程语言Scratch图形编程优点在于图形化拖拽的方式简化了编程的理解,而C,JAVA,JAVASCRIPT,PYTHON等编程语言相对枯燥复杂,涉及复杂编程语法,变量规则,函…

Electric Maker Beginner Tools Kit

Electric Maker Beginner Tools Kit

This assortment of tools has everything you need to get started tinkering with Sparkfun products and…

Series and Parallel resistors

Series and Parallel resistors

Two-terminal components and electrical networks can be connected in series or parallel. The resultin…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.