CIPAD 26 Comment utiliser le L293D pour contrôler 2 moteurs à courant continu depuis L'arduino Uno.

3 min read 4 hours ago
Published on Oct 02, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, you will learn how to use the L293D motor driver to control two DC motors with an Arduino Uno. This guide is designed for beginners and will walk you through the necessary components, wiring, and coding. By the end, you’ll be able to operate motors effectively in your Arduino projects.

Step 1: Gather Your Components

Before you start, make sure you have the following components:

  • Arduino Uno board
  • L293D motor driver IC
  • Two DC motors
  • Power supply for motors (battery or adapter)
  • Jumper wires
  • Breadboard (optional for organization)

Practical Tip: Ensure your power supply matches the voltage requirements of your motors.

Step 2: Connect the L293D to the Arduino

Follow these wiring instructions to connect the L293D to the Arduino and motors:

  1. Connect the L293D:

    • Pin 1 (Enable 1,2) to Arduino digital pin 9 (for motor control)
    • Pin 2 (Input 1) to Arduino digital pin 10
    • Pin 7 (Input 2) to Arduino digital pin 11
    • Pin 3 (Output 1) to the first motor terminal
    • Pin 6 (Output 2) to the second motor terminal
    • Pin 4 and 5 (Ground) to GND on the Arduino
    • Pin 8 (Vcc2) to the motor power supply (e.g., battery)
  2. Connect the Motors:

    • Connect one terminal of each motor to the corresponding outputs on the L293D (pins 3 and 6).
    • Connect the other terminal of both motors to the ground.

Common Pitfall: Double-check all connections to avoid damaging components. Ensure that the L293D is oriented correctly.

Step 3: Write the Arduino Code

You will need to upload a sketch to the Arduino to control the motors. Here’s a simple example code:

// Motor control pins
const int motorPin1 = 10; // Input 1
const int motorPin2 = 11; // Input 2
const int enablePin = 9;   // Enable pin

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);
  
  // Start with motors off
  digitalWrite(enablePin, LOW);
}

void loop() {
  // Forward motion
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(enablePin, HIGH);
  delay(2000); // run for 2 seconds
  
  // Stop motion
  digitalWrite(enablePin, LOW);
  delay(1000); // stop for 1 second
  
  // Backward motion
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(enablePin, HIGH);
  delay(2000); // run for 2 seconds
  
  // Stop motion
  digitalWrite(enablePin, LOW);
  delay(1000); // stop for 1 second
}

Practical Tip: Adjust the delay times to change how long the motors run in each direction.

Step 4: Upload the Code and Test

  1. Connect your Arduino Uno to the computer using a USB cable.
  2. Open the Arduino IDE and paste the provided code.
  3. Select the correct board and port from the Tools menu.
  4. Click on the upload button.

Once uploaded, observe the motors. They should run forward for 2 seconds, stop for 1 second, run backward for 2 seconds, and stop again.

Conclusion

You have successfully learned how to control two DC motors using an L293D motor driver with an Arduino Uno. Experiment with the code to modify the motor speeds and directions, or integrate additional sensors for more complex projects. Consider exploring other motor control techniques or expanding your setup with more motors. Happy coding!