Comment fonctionne Les ponts en H ou H-Bridge , Arduino télécommande IR

3 min read 2 months 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 provides a comprehensive guide on how H-bridges work and how to control them using an Arduino and an infrared remote control. H-bridges are essential for controlling the direction of motors in robotics and other applications. This guide will walk you through the setup, coding, and practical applications.

Step 1: Understanding the H-Bridge

  • An H-bridge is a circuit that allows a voltage to be applied across a load in either direction.
  • It consists of four switches (transistors) arranged in an "H" shape.
  • The key functions of an H-bridge include:
    • Control the direction of a DC motor.
    • Enable speed control via PWM (Pulse Width Modulation).

Step 2: Components Needed

Gather the following components to complete this project:

  • Arduino board (e.g., Arduino Uno)
  • H-bridge module (e.g., L298N)
  • DC motor
  • Infrared remote control
  • IR receiver module
  • Jumper wires
  • Breadboard (optional)

Step 3: Wiring the H-Bridge

Set up the circuit according to the following connections:

  1. Connect the H-bridge to the Arduino:
    • IN1 to Arduino pin (e.g., pin 9)
    • IN2 to Arduino pin (e.g., pin 10)
    • ENA to Arduino pin (e.g., pin 5 for PWM control)
  2. Connect the motor to the H-bridge outputs:
    • Motor terminals to OUT1 and OUT2 on the H-bridge.
  3. Connect the power supply to the H-bridge:
    • Ensure the voltage matches the motor requirements.
  4. Connect the IR receiver module:
    • VCC to Arduino 5V
    • GND to Arduino GND
    • Signal pin to Arduino pin (e.g., pin 2)

Step 4: Installing Libraries

Before coding, install the necessary libraries for IR communication:

  1. Open the Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries.
  3. Search for "IRremote" and install the library by shirriff.

Step 5: Writing the Arduino Code

Use the following code as a starting point for controlling the motor with the IR remote:

#include <IRremote.h>

const int recv_pin = 2;
IRrecv irrecv(recv_pin);
decode_results results;

const int motorPin1 = 9;
const int motorPin2 = 10;
const int enablePin = 5;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value);
    switch (results.value) {
      case 0xFFA25D: // Example code for button 1
        // Move motor forward
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);
        break;
      case 0xFF629D: // Example code for button 2
        // Move motor backward
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, HIGH);
        break;
      case 0xFFE21D: // Example code for button 3
        // Stop motor
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        break;
      default:
        break;
    }
    irrecv.resume(); // Receive the next value
  }
}
  • Replace the button codes with those corresponding to your remote control.

Step 6: Testing the Setup

  • Upload the code to your Arduino.
  • Point the infrared remote at the IR receiver and press the buttons to control the motor.
  • Ensure the motor responds correctly to the commands (forward, backward, stop).

Conclusion

In this tutorial, you learned how to set up an H-bridge with an Arduino and control it using an infrared remote. You now have the foundational skills to manipulate DC motors in various projects. Next, consider exploring how to integrate additional sensors or modify the code for more complex behaviors. Happy building!