Werktags vor 14:00 Uhr bestellt = am selben Tag versendet 30 Tage Widerrufsrecht 1 Jahr Garantie
← Zurück zur Übersicht

Schaltplan und Codebeispiel

So schließt du den Motorsteuerungsmodul TB6612FNG für Arduino an einen Arduino UNO oder ESP32 an, mit einem Beispiel-Sketch, den du direkt hochladen kannst.

TB6612FNG Dual-Motor-Treibersteuerung

Dieses Projekt steuert einen DC-Motor-Kanal mit dem Dual-H-Brücke-Treiber TB6612FNG. Das Sketch aktiviert den Treiber über den standby-Pin und lässt den Motor abwechselnd vorwärts laufen, anhalten und rückwärts laufen, mit PWM-Geschwindigkeitssteuerung. Öffnen Sie den Serial Monitor mit 115200 baud, um den Betriebsstatus zu beobachten.

Anschlussplan: Motorsteuerungsmodul TB6612FNG für Arduino an einem Arduino UNO
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Motorsteuerungsmodul TB6612FNG für Arduino an einem Arduino UNO
Anschlusstabelle · Zum Vergrößern klicken
TB6612FNG_Dual_Motor_Driver_Control.ino · kompiliert und getestet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : TB6612FNG Dual Motor Driver Control
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : TB6612FNG Motor Driver
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

const int PIN_PWMA = 5;
const int PIN_STBY = 6;
const int PIN_AIN1 = 7;
const int PIN_AIN2 = 8;

void setup() {
  Serial.begin(115200);

  pinMode(PIN_PWMA, OUTPUT);
  pinMode(PIN_STBY, OUTPUT);
  pinMode(PIN_AIN1, OUTPUT);
  pinMode(PIN_AIN2, OUTPUT);

  // Take driver out of standby mode
  digitalWrite(PIN_STBY, HIGH);

  Serial.println(F("TB6612FNG Motor Driver Initialized"));
}

void driveMotorA(bool forward, int speed) {
  speed = constrain(speed, 0, 255);

  if (forward) {
    digitalWrite(PIN_AIN1, HIGH);
    digitalWrite(PIN_AIN2, LOW);
    Serial.print(F("Motor Forward at speed: "));
  } else {
    digitalWrite(PIN_AIN1, LOW);
    digitalWrite(PIN_AIN2, HIGH);
    Serial.print(F("Motor Reverse at speed: "));
  }

  analogWrite(PIN_PWMA, speed);
  Serial.println(speed);
}

void stopMotorA() {
  analogWrite(PIN_PWMA, 0);
  digitalWrite(PIN_AIN1, LOW);
  digitalWrite(PIN_AIN2, LOW);
  Serial.println(F("Motor Stopped"));
}

void loop() {
  // Drive forward at speed 200
  driveMotorA(true, 200);
  delay(2000);

  // Stop
  stopMotorA();
  delay(1000);

  // Drive reverse at speed 200
  driveMotorA(false, 200);
  delay(2000);

  // Stop
  stopMotorA();
  delay(1000);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

TB6612FNG Motortreiber mit ESP32

Dieses Projekt zeigt, wie man einen Gleichstrommotor mit dem TB6612FNG Dual-H-Brücken-Motortreiber und einem ESP32 ansteuert. Der Sketch aktiviert den Treiber über den STBY-Pin und lässt Motor Kanal A nacheinander vorwärts laufen, abbremsen, rückwärts laufen und bremsen. Öffnen Sie den Seriellen Monitor mit 115200 Baud, um den aktuellen Motorzustand und die Geschwindigkeit anzuzeigen.

Anschlussplan: Motorsteuerungsmodul TB6612FNG für Arduino an einem ESP32 DevKit V1
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Motorsteuerungsmodul TB6612FNG für Arduino an einem ESP32 DevKit V1
Anschlusstabelle · Zum Vergrößern klicken
TB6612FNG_Motor_Driver_with_ESP32.ino · kompiliert und getestet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : TB6612FNG Motor Driver with ESP32
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : TB6612FNG Motor Driver
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// TB6612FNG Dual H-Bridge Motor Driver Demo on ESP32

const int PIN_STBY = 13;
const int PIN_AIN1 = 12;
const int PIN_AIN2 = 14;
const int PIN_PWMA = 27;

void setup() {
  Serial.begin(115200);

  pinMode(PIN_STBY, OUTPUT);
  pinMode(PIN_AIN1, OUTPUT);
  pinMode(PIN_AIN2, OUTPUT);
  pinMode(PIN_PWMA, OUTPUT);

  // Enable driver
  digitalWrite(PIN_STBY, HIGH);
  Serial.println("TB6612FNG Motor Driver Initialized");
}

void driveMotor(bool forward, int speed) {
  if (forward) {
    digitalWrite(PIN_AIN1, HIGH);
    digitalWrite(PIN_AIN2, LOW);
  } else {
    digitalWrite(PIN_AIN1, LOW);
    digitalWrite(PIN_AIN2, HIGH);
  }
  analogWrite(PIN_PWMA, constrain(speed, 0, 255));
}

void stopMotor() {
  digitalWrite(PIN_AIN1, LOW);
  digitalWrite(PIN_AIN2, LOW);
  analogWrite(PIN_PWMA, 0);
}

void loop() {
  // Forward acceleration
  Serial.println("Motor Forward: Accelerating");
  for (int spd = 50; spd <= 255; spd += 25) {
    driveMotor(true, spd);
    delay(150);
  }
  delay(1000);

  // Stop
  Serial.println("Motor Stop");
  stopMotor();
  delay(1000);

  // Reverse acceleration
  Serial.println("Motor Reverse: Accelerating");
  for (int spd = 50; spd <= 255; spd += 25) {
    driveMotor(false, spd);
    delay(150);
  }
  delay(1000);

  // Stop
  Serial.println("Motor Stop");
  stopMotor();
  delay(2000);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Zuletzt angesehen

WeMos D1 R32 ESP32 4Mb Development Board WiFi Bluetooth Dual Core Arduino Uno R3 Format

WeMos D1 R32 ESP32 4Mb Development Board WiFi Bluetooth Dual Core Arduino Uno R3 Format

€ 8,85
Ansehen
ACEBOTT Erweiterung Wasserballkanone für ESP32 Roboterwagen

ACEBOTT Erweiterung Wasserballkanone für ESP32 Roboterwagen

€ 59,00
TOF400C-VL53L1X Entfernungssensor Time-Of-Flight 4-400cm

TOF400C-VL53L1X Entfernungssensor Time-Of-Flight 4-400cm

€ 18,15
Druckknopf | Ein-Aus Self Lock | 5V LED Blau | Edelstahl | 12mm

Druckknopf | Ein-Aus Self Lock | 5V LED Blau | Edelstahl | 12mm

€ 3,49