Arduino-Controlled Ultrasonic Sensor with Servo and Dual Motor Driver
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control a pair of DC motors using an L298N motor driver, interfaced with an Arduino UNO microcontroller. The circuit also includes an HC-SR04 ultrasonic sensor for distance measurement and a Servomotor SG90 for precise angular movement. Power is supplied by a 4.5V battery pack, and a rocker switch is used to control the power flow to the circuit.
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.
Servomotor SG90
- A small and lightweight servo motor capable of precise control
- Operates on 5V and has three pins: Signal (SIG), Power (VCC), and Ground (GND).
HC-SR04 Ultrasonic Sensor
- An ultrasonic distance sensor
- It has four pins: Power (VCC), Trigger (TRIG), Echo (ECHO), and Ground (GND).
L298N DC Motor Driver
- A dual H-bridge motor driver capable of driving a pair of DC motors or a stepper motor
- It has multiple pins for motor outputs, power supply, and control signals.
Motor Amarillo Motorreductor Hobby (x2)
- A yellow hobby gear motor
- It has two pins: Power (VCC) and Ground (GND).
Rocker Switch
- A simple on/off switch
- It has two pins for switching the circuit's power.
Battery AAx3 4.5V
- A battery pack consisting of three AA batteries providing 4.5V
- It has two pins: Power (VCC) and Ground (GND).
Wiring Details
Arduino UNO
- IOREF connected to HC-SR04 Ultrasonic Sensor VCC
- 5V connected to Servomotor SG90 VCC
- GND connected to Servomotor SG90 GND, L298N DC motor driver GND, HC-SR04 Ultrasonic Sensor GND, and Battery AAx3 4.5V GND
- Vin connected to L298N DC motor driver 12V and Rocker Switch pin 1
- D12 connected to HC-SR04 Ultrasonic Sensor ECHO
- D11 connected to HC-SR04 Ultrasonic Sensor TRIG
- D10 connected to L298N DC motor driver IN4
- D9 connected to L298N DC motor driver IN3
- D8 connected to L298N DC motor driver IN2
- D7 connected to L298N DC motor driver IN1
- D6 connected to L298N DC motor driver ENB
- D5 connected to L298N DC motor driver ENA
- D3 connected to Servomotor SG90 SIG
Servomotor SG90
- SIG connected to Arduino UNO D3
- VCC connected to Arduino UNO 5V
- GND connected to Arduino UNO GND
HC-SR04 Ultrasonic Sensor
- VCC connected to Arduino UNO IOREF
- TRIG connected to Arduino UNO D11
- ECHO connected to Arduino UNO D12
- GND connected to Arduino UNO GND
L298N DC Motor Driver
- OUT1 connected to Motor Amarillo Motorreductor Hobby VCC
- OUT2 connected to Motor Amarillo Motorreductor Hobby GND
- OUT3 connected to Motor Amarillo Motorreductor Hobby VCC
- OUT4 connected to Motor Amarillo Motorreductor Hobby GND
- 12V connected to Arduino UNO Vin and Rocker Switch pin 1
- GND connected to Arduino UNO GND and Battery AAx3 4.5V GND
- 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2 are not connected in this circuit
- ENA connected to Arduino UNO D5
- IN1 connected to Arduino UNO D7
- IN2 connected to Arduino UNO D8
- IN3 connected to Arduino UNO D9
- IN4 connected to Arduino UNO D10
- ENB connected to Arduino UNO D6
Motor Amarillo Motorreductor Hobby
- VCC connected to L298N DC motor driver OUT1/OUT3
- GND connected to L298N DC motor driver OUT2/OUT4
Rocker Switch
- Pin 1 connected to Arduino UNO Vin and L298N DC motor driver 12V
- Pin 2 connected to Battery AAx3 4.5V VCC
Battery AAx3 4.5V
- VCC connected to Rocker Switch pin 2
- GND connected to Arduino UNO 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:
}
Note: The provided code is a template and does not contain any functional code to control the circuit components. The user must add the necessary code to initialize the pins and implement the control logic for the motors, servo, and ultrasonic sensor.