Arduino-Controlled Dual Motor Driver with Ultrasonic Sensing
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary of the Circuit
This circuit is designed to control two hobby gearmotors using an L298N DC motor driver, which is interfaced with an Arduino UNO microcontroller. The Arduino UNO also interfaces with an HC-SR04 Ultrasonic Sensor for distance measurement. The entire circuit is powered by a Li-ion battery, which provides the necessary voltage for the motor driver and the microcontroller through voltage regulation.
Component List
L298N DC Motor Driver
- Description: A motor driver module capable of driving two DC motors.
- Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB.
Hobby Gearmotor with 48:1 Gearbox (x2)
- Description: A DC motor with a gearbox for increased torque.
- Pins: pin 1, pin 2.
Li-ion Battery, 2200 mAh 11.1 V
- Description: A rechargeable battery providing the power source for the circuit.
- Pins: +, -.
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13.
HC-SR04 Ultrasonic Sensor
- Description: An ultrasonic ranging module for distance measurement.
- Pins: VCC, TRIG, ECHO, GND.
Wiring Details
L298N DC Motor Driver
- 12V connected to Li-ion battery (+)
- GND connected to Arduino UNO (GND), Li-ion battery (-), and HC-SR04 Ultrasonic Sensor (GND)
- 5V connected to Arduino UNO (5V)
- OUT1 connected to Gearmotor 1 (pin 1)
- OUT2 connected to Gearmotor 1 (pin 2)
- OUT3 connected to Gearmotor 2 (pin 2)
- OUT4 connected to Gearmotor 2 (pin 1)
- ENA connected to Arduino UNO (D9)
- IN1 connected to Arduino UNO (D4)
- IN2 connected to Arduino UNO (D5)
- IN3 connected to Arduino UNO (D6)
- IN4 connected to Arduino UNO (D7)
- ENB connected to Arduino UNO (D10)
Hobby Gearmotor with 48:1 Gearbox
- Gearmotor 1 pin 1 connected to L298N DC Motor Driver (OUT1)
- Gearmotor 1 pin 2 connected to L298N DC Motor Driver (OUT2)
- Gearmotor 2 pin 1 connected to L298N DC Motor Driver (OUT4)
- Gearmotor 2 pin 2 connected to L298N DC Motor Driver (OUT3)
Li-ion Battery, 2200 mAh 11.1 V
- (+) connected to L298N DC Motor Driver (12V)
- (-) connected to Arduino UNO (GND), L298N DC Motor Driver (GND), and HC-SR04 Ultrasonic Sensor (GND)
Arduino UNO
- GND connected to L298N DC Motor Driver (GND), Li-ion battery (-), and HC-SR04 Ultrasonic Sensor (GND)
- 5V connected to L298N DC Motor Driver (5V) and HC-SR04 Ultrasonic Sensor (VCC)
- D9 connected to L298N DC Motor Driver (ENA)
- D4 connected to L298N DC Motor Driver (IN1)
- D5 connected to L298N DC Motor Driver (IN2)
- D6 connected to L298N DC Motor Driver (IN3)
- D7 connected to L298N DC Motor Driver (IN4)
- D10 connected to L298N DC Motor Driver (ENB)
- D13 connected to HC-SR04 Ultrasonic Sensor (ECHO)
- D12 connected to HC-SR04 Ultrasonic Sensor (TRIG)
HC-SR04 Ultrasonic Sensor
- VCC connected to Arduino UNO (5V)
- TRIG connected to Arduino UNO (D12)
- ECHO connected to Arduino UNO (D13)
- GND connected to Arduino UNO (GND), L298N DC Motor Driver (GND), and Li-ion battery (-)
Documented Code
Arduino UNO Code (sketch.ino)
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Note: The provided code is a template and does not contain any functional code to control the motors or read the ultrasonic sensor. The user must implement the control logic and sensor reading code within the setup() and loop() functions.