Arduino-Controlled Dual DC Motor & IR Sensor Obstacle Detection System
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control two DC motors using an Arduino UNO microcontroller and an L298N DC motor driver. It includes two IR sensors for input and an HC-SR04 Ultrasonic Sensor for distance measurement. The circuit is powered by a 12V battery, which supplies power to the motor driver and indirectly to the other components through the motor driver's 5V output.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
DC Motor (x2)
- An electric motor that runs on direct current (DC) electricity.
- It has two pins for connecting to the motor driver.
L298N DC Motor Driver
- A dual H-bridge motor driver that can drive two DC motors or one stepper motor.
- It has pins for motor outputs, motor inputs, power supply, and enable pins for controlling motor speed and direction.
IR Sensor (x2)
- An infrared sensor capable of detecting obstacles and measuring distance.
- It has three pins: out, gnd, and vcc.
Battery 12V
- A 12V battery used to power the motor driver and through it, the rest of the circuit.
HC-SR04 Ultrasonic Sensor
- An ultrasonic ranging module that provides 2cm to 400cm non-contact measurement function.
- It has four pins: VCC, TRIG, ECHO, and GND.
Wiring Details
Arduino UNO
GNDconnected to the battery's negative terminal and L298N's GND.A0connected to the first IR sensor's output.A1connected to the second IR sensor's output.D13connected to the HC-SR04 Ultrasonic Sensor's ECHO pin.D12connected to the HC-SR04 Ultrasonic Sensor's TRIG pin.D11connected to L298N's ENB pin.D10connected to L298N's ENA pin.D9connected to L298N's IN1 pin.D8connected to L298N's IN2 pin.D7connected to L298N's IN3 pin.D6connected to L298N's IN4 pin.
DC Motor 1
pin 1connected to L298N's OUT2.pin 2connected to L298N's OUT1.
DC Motor 2
pin 1connected to L298N's OUT4.pin 2connected to L298N's OUT3.
L298N DC Motor Driver
GNDconnected to the battery's negative terminal and Arduino UNO's GND.12Vconnected to the battery's positive terminal.ENAandENBconnected to Arduino UNO for speed control.IN1,IN2,IN3, andIN4connected to Arduino UNO for direction control.OUT1,OUT2,OUT3, andOUT4connected to the DC motors.
IR Sensor 1
outconnected to Arduino UNO's A0.gndconnected to Arduino UNO's GND.vccconnected to HC-SR04's VCC.
IR Sensor 2
outconnected to Arduino UNO's A1.gndconnected to Arduino UNO's GND.vccconnected to HC-SR04's VCC.
HC-SR04 Ultrasonic Sensor
VCCconnected to the IR sensors' VCC.TRIGconnected to Arduino UNO's D12.ECHOconnected to Arduino UNO's D13.GNDconnected to Arduino UNO's GND.
Battery 12V
+connected to L298N's 12V.-connected to Arduino UNO's GND and L298N's GND.
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:
}
This code is a template and does not contain any functional code. It needs to be filled in with the logic for controlling the motors based on the input from the IR sensors and the HC-SR04 Ultrasonic Sensor. The setup() function is used for initializing the pins and the loop() function will contain the main logic that will run repeatedly.