Cipad 27: 4 bascules ON/OFF avec variateurs de vitesse pour contrôler 2 moteurs avec le L293D.

3 min read 2 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 will guide you through controlling two motors using an L293D motor driver with ON/OFF switches and speed variators. This project is suitable for beginners interested in Arduino programming and electronics. By following these steps, you will learn how to set up components, make connections, and write basic code to control motor speed and direction.

Step 1: Gather Your Components

Before starting, ensure you have the following components:

  • Arduino board (e.g., Arduino Uno)
  • L293D motor driver
  • Two DC motors
  • Power supply (appropriate for your motors)
  • ON/OFF switches
  • Variable resistors (potentiometers)
  • Jumper wires
  • Breadboard

Practical Tips

  • Verify the specifications of your motors to ensure compatibility with the L293D.
  • Organize your components to streamline the setup process.

Step 2: Set Up Components

  1. Place components on the breadboard:

    • Position the L293D on the breadboard.
    • Connect the two motors to the output pins of the L293D.
  2. Connect the switches and potentiometers:

    • Wire the ON/OFF switches to control the power to the motors.
    • Connect the variable resistors to adjust motor speed.

Practical Tips

  • Make sure to note the pin configuration on the L293D to avoid incorrect connections.

Step 3: Make Basic Connections

  1. Connect the power supply:

    • Connect the Vcc and GND pins of the L293D to the power supply.
    • Ensure the voltage matches the requirements of your motors.
  2. Connect the inputs:

    • Connect the input pins of the L293D to the Arduino digital pins.
    • Make sure to label these connections for easy reference.

Common Pitfalls

  • Double-check all connections before powering the circuit to prevent damage.

Step 4: Set Up Input/Output Connections

  1. Digital Pin Connections:

    • Assign digital pins on the Arduino for controlling the motors and reading the switches.
  2. Analog Pin Connections:

    • Connect the potentiometers to the analog pins on the Arduino for speed control.

Practical Tips

  • Use color-coded wires for different types of connections (power, ground, signal) to avoid confusion.

Step 5: Write the Arduino Code

  1. Initialize variables:

    • Define the pins used for motor control and speed adjustment.
  2. Set up the loop:

    • Read the switch states to turn motors ON/OFF.
    • Use the potentiometer values to adjust motor speeds.

Example Code

int motorPin1 = 3; // Pin connected to input 1 of L293D
int motorPin2 = 4; // Pin connected to input 2 of L293D
int speedPin = A0; // Pin connected to the speed control potentiometer
int switchPin = 2; // Pin connected to ON/OFF switch

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(switchPin, INPUT);
}

void loop() {
  int switchState = digitalRead(switchPin);
  int speedValue = analogRead(speedPin);

  if (switchState == HIGH) {
    analogWrite(motorPin1, speedValue / 4); // Scale 0-1023 to 0-255
    analogWrite(motorPin2, 0); // Motor runs in one direction
  } else {
    analogWrite(motorPin1, 0); // Motor stops
    analogWrite(motorPin2, 0); // Ensure both outputs are off
  }
}

Common Pitfalls

  • Ensure you scale the potentiometer value correctly to avoid exceeding the PWM range.

Conclusion

By following this tutorial, you have learned how to set up an L293D motor driver with two motors, integrate ON/OFF switches, and use variable resistors for speed control. Next, you can experiment with different motor types, adjust the code for additional functions, or even try controlling more motors. Happy tinkering!