CIPAD 25: Contrôle d'un moteur DC et L293D

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

This tutorial guides you through controlling a DC motor using the L293D H-Bridge driver. It is designed for beginners in Arduino programming and follows up on previous lessons. By the end of this tutorial, you will understand how to control both the direction and speed of a 24V DC motor.

Step 1: Gather Required Components

To get started, make sure you have the following components:

  • Arduino board (e.g., Arduino Uno)
  • L293D H-Bridge motor driver
  • 24V DC motor (27 Watts)
  • External power supply (24V)
  • Breadboard and jumper wires
  • Resistors (if necessary)
  • Optional: Diodes for protection

Practical Tips

  • Ensure all components are compatible.
  • Check voltage ratings to avoid damage.

Step 2: Circuit Setup

Follow these steps to set up your circuit:

  1. Connect the DC Motor:

    • Attach the two terminals of the motor to the output pins of the L293D (e.g., pins 3 and 6).
  2. Connect the L293D to Arduino:

    • Connect the input pins of the L293D (e.g., pins 1 and 2) to two digital pins on the Arduino (e.g., pins 9 and 10).
    • Connect the Enable pin (pin 1) to another digital pin on Arduino (e.g., pin 8).
  3. Power Connections:

    • Connect the Vcc1 pin (pin 16) of the L293D to the Arduino's 5V.
    • Connect the Vcc2 pin (pin 8) to the external 24V power supply.
    • Connect the ground pins (GND) of L293D, Arduino, and power supply together.

Common Pitfalls

  • Double-check connections before powering up to prevent short circuits.
  • Ensure the power supply is turned off when making connections.

Step 3: Arduino Code Implementation

Use the following code to control your motor. This code will enable you to set the direction and speed.

#define ENA 8
#define IN1 9
#define IN2 10

void setup() {
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
}

void loop() {
  // Rotate motor clockwise
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  analogWrite(ENA, 255); // Full speed
  delay(2000); // Run for 2 seconds

  // Rotate motor counterclockwise
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  analogWrite(ENA, 128); // Half speed
  delay(2000); // Run for 2 seconds

  // Stop motor
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  analogWrite(ENA, 0); // Stop
  delay(2000); // Wait for 2 seconds
}

Explanation of Code

  • pinMode: Initializes the pins as output.
  • digitalWrite: Sets the direction of the motor.
  • analogWrite: Controls the speed of the motor using PWM (Pulse Width Modulation).

Step 4: Testing the Setup

After uploading the code to your Arduino, follow these steps to test your setup:

  1. Power the Arduino and Motor:

    • Ensure the external power supply is connected and turned on.
  2. Observe Motor Behavior:

    • Check if the motor rotates clockwise and counterclockwise according to the code.
    • Adjust the delay and PWM values in the code for different speeds.

Practical Tips

  • Use a multimeter to check voltage levels if the motor does not operate correctly.
  • Be cautious of overheating components; ensure proper heat dissipation.

Conclusion

You have now successfully set up and controlled a DC motor using the L293D H-Bridge. This project enhances your understanding of motor control with Arduino. For further exploration, consider experimenting with different motor speeds and directions by modifying the code. You can also explore additional resources, such as the Tinkercad link provided in the video description, for more complex projects.