Controlling DC Motors

FORGET EVERYTHING!! Ok I have 2 motors DC that´ll work at 9V (inputs) controlled from the pins of the Arduino and the integrated circuit LM293D (throughole version). The Arduino will run this code: //Motor1 int IN1 = 9; int IN2 = 8; int ENA1 = 10; // Motor 2 int IN4 = 6; int IN3 = 5; int ENA2 = 3; int speedmotor = 127; //1=Hacia delante, 2=Hacia atrás, 3=Giro izquierdas, 4=Giro derechas int movimiento = 0; int movAnterior = -1; bool estado = true;
//Bluetooth(incluir libreria y softwareserial)
void setup() { Serial.begin(9600); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(ENA1, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); pinMode(ENA2, OUTPUT); //Se imprime un texto cada vez que se conecte Serial.println("CONTROL INALAMBRICO CONECTADO "); } void loop() { if(Serial.available()){ //Digo al Arduino que lea si el valor almacenado es mayor a 0 movimiento = Serial.parseInt(); //devuelve un numero entero y lo soobreescribe en la variable de movimiento } if(movimiento != movAnterior){ movAnterior = movimiento;
if(movimiento == 0){ Serial.println("Coche Detenido"); digitalWrite(IN1, 0); digitalWrite(IN2, 0); digitalWrite(IN3, 0); digitalWrite(IN4, 0); analogWrite(ENA1, 0); analogWrite(ENA2, 0); estado = true; } if(movimiento == 1){ Serial.println("Ir hacia adelante: "+String(speedmotor)); digitalWrite(IN1, 1); digitalWrite(IN2, 0); digitalWrite(IN3, 0); digitalWrite(IN4, 1); analogWrite(ENA1, speedmotor); analogWrite(ENA2, speedmotor); estado = true; } else if(movimiento == 2){ Serial.println("Ir hacia atras: "+String(speedmotor)); digitalWrite(IN1, 0); digitalWrite(IN2, 1); digitalWrite(IN3, 1); digitalWrite(IN4, 0); analogWrite(ENA1, speedmotor); analogWrite(ENA2, speedmotor); estado = true; } else if(movimiento == 3){ Serial.println("Girar hacia la derecha: "+String(speedmotor)); digitalWrite(IN1, 1); digitalWrite(IN2, 0); digitalWrite(IN3, 1); digitalWrite(IN4, 0); analogWrite(ENA1, speedmotor); analogWrite(ENA2, 0); estado = true; } else if(movimiento == 4){ Serial.println("Girar hacia la izquierda: "+String(speedmotor)); digitalWrite(IN1, 0); digitalWrite(IN2, 1); digitalWrite(IN3, 0); digitalWrite(IN4, 1); analogWrite(ENA1, 0); analogWrite(ENA2, speedmotor); estado = true; } Serial.println("movimiento: "+String(movimiento)); if(movimiento == 5 && estado == true){ Serial.println("speedmotor antes de cambiar: "+String(speedmotor)); speedmotor = speedmotor - 50; speedmotor = constrain(speedmotor, 10, 255); Serial.println("speedmotor despues de cambiar: "+String(speedmotor)); analogWrite(ENA1, speedmotor); analogWrite(ENA2, speedmotor); delay(500); estado = false; } else if(movimiento == 6 && estado == true){ Serial.println("speedmotor antes de cambiar: "+String(speedmotor)); speedmotor = speedmotor + 50; speedmotor = constrain(speedmotor, 10, 255); Serial.println("speedmotor despues de cambiar: "+String(speedmotor)); analogWrite(ENA2, speedmotor); analogWrite(ENA1, speedmotor); delay(500); estado = false; } delay(1000);
} } It is design to run bassed on a 9V 2100mAh battery. There will also be a bluetooth model (HC-04) that will be connected to a mobile phone that through an APP will send the respective number (1 or 2 or 3... depending on what the user want to do at that moment) put all the respective resistors and capacitors that you consider necessary but everything throughole please
He actualizado el esquema para tu robot con Arduino Uno + L293D DIP + 2 motores DC a 9 V + Bluetooth HC-05.
Hecho:
  • L293D rewired para tu código:
    • Motor 1: D9 → IN1, D8 → IN2, D10 → ENA1/PWM
    • Motor 2: D5 → IN3, D6 → IN4, D3 → ENA2/PWM
  • VCC2 del L293D ahora va al rail de 9 V, no a 5 V.
  • Añadí entrada de batería de 9 V, capacitores through-hole, HC-05 y divisor resistivo para RX del Bluetooth.
  • Actualicé la documentación:
Estado de verificación:
  • La revisión eléctrica y de fabricación no mostró errores.
  • Queda pendiente revisar/limpiar DRC de layout porque añadí componentes nuevos through-hole y todavía habría que colocarlos físicamente en la PCB y rutearlos.
Nota importante: verifica que cada motor no supere aprox. 600 mA continuos con el L293D. Si los motores consumen más, conviene cambiar a un driver más potente.
Auto-place components
Run ERC/DRC
Add terminals
Check motor current

Refine this doc
Ask about this doc
Motor Driver 9 V Design Notes
User requirements
  • Two brushed DC motors.
  • Motor supply: 9 V, 2100 mAh battery.
  • Controller: Arduino Uno.
  • Driver IC: L293D, through-hole/DIP version.
  • Bluetooth serial module controlled by a mobile app sending movement numbers.
  • All added physical components should be through-hole where practical.
Arduino pin mapping from provided sketch

Table


FunctionArduino pinL293D pin
Motor 1 IN1D91A
Motor 1 IN2D82A
Motor 1 enable/PWMD10EN1,2
Motor 2 IN3D53A
Motor 2 IN4D64A
Motor 2 enable/PWMD3EN3,4
Bluetooth TXArduino D0/RXUART receive
Arduino D1/TXBluetooth RXThrough resistor divider
Power budget and sizing notes
The motor stall current was not provided, so the design must treat the L293D as the limiting component. The L293D is suitable only for small brushed DC motors: about 600 mA continuous output current per channel, with short non-repetitive peaks around 1.2 A. Each motor stall current should be less than the L293D limit, ideally with margin.
Estimated load budget:

Table


LoadRailTypical/limit used
Arduino Uno5 V logicabout 50-100 mA typical depending on board/peripherals
Bluetooth module5 V/VCC module inputabout 30-50 mA typical
L293D logic5 V logiclow current relative to motors
Motor 19 V motor railmust be <= 600 mA continuous through L293D
Motor 29 V motor railmust be <= 600 mA continuous through L293D
Worst-case motor rail sizing should assume up to about 1.2 A continuous total if both motors approach the L293D per-channel limit. Startup/stall can exceed this; if the motors have stall current above about 600 mA each, a stronger driver such as TB6612FNG, DRV8833, or a discrete MOSFET H-bridge is recommended.
Battery warning
A 9 V battery marked 2100 mAh may not sustain high motor current well unless it is a high-current rechargeable pack. Small rectangular 9 V batteries have high internal resistance and can sag badly with DC motors. A 6xAA battery pack or 2-cell Li-ion/LiPo with the correct driver is usually more reliable for a robot car.
Support components
  • 100 nF decoupling on L293D VCC1 logic supply.
  • 100 nF decoupling on L293D VCC2 motor supply.
  • 100 uF or larger bulk capacitor on the 9 V motor rail near the L293D.
  • 1 kΩ / 2.2 kΩ divider from Arduino TX to Bluetooth RX to reduce 5 V UART TX to about 3.4 V.
  • Arduino RX can read Bluetooth TX directly in most HC-05/HC-06 breakout modules.
Important design correction from previous version
The motor driver VCC2 must be connected to the 9 V motor rail, not the Arduino 5 V rail. L293D VCC1 remains at Arduino 5 V logic.

    User requirements

    Arduino pin mapping from provided sketch

    Power budget and sizing notes

    Battery warning

    Support components

    Important design correction from previous version

Documents

    Notas de diseño — Puente H Arduino Bluetooth

    Firmware — Arduino Uno + HC-05 + L293D

    Motor Driver 9 V Design Notes

Assets

Assets are files uploaded to this project which can be used in various ways.

USB-C ESP32 Environmental Node thumbnail
Low-power USB-C environmental sensor node using a dual-radio Wi‑Fi/BLE MCU, digital temperature/humidity sensing, protected 5 V USB-C input, and 3.3 V regulation for consumer use.

Properties

Properties describe core aspects of the project.

Pricing & Availability

Distributor

Qty 1

Arrow

$8.95–$13.35

Digi-Key

$13.19

HQonline

$4.36

LCSC

$1.46–$5.43

Mouser

$15.55

TME

$6.16

Verical

$5.17–$10.17

Controls