Arduino-Controlled Obstacle-Avoiding Robot with Ultrasonic Sensor and Servo
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control a set of motors, read distance measurements from an ultrasonic sensor, and provide feedback through a servo and a buzzer. The main controller for the circuit is an Arduino UNO, which interfaces with an L298N DC motor driver to control the speed and direction of the motors. The HC-SR04 Ultrasonic Sensor is used for distance sensing, and a servo is controlled via PWM from the Arduino. A buzzer provides audio feedback, and a rocker switch (SPST) is used to control the power supply from the 18650 Li-ion batteries to the motor driver.
Component List
- Servo: A motor with feedback control for precise angle positioning.
- HC-SR04 Ultrasonic Sensor: A sensor for measuring distances using ultrasonic waves.
- Gearmotor DC Wheels (Right and Left): Motors used for driving the wheels of a vehicle.
- Buzzer: An audio signaling device.
- L298N DC Motor Driver: A module for controlling the direction and speed of DC motors.
- Arduino UNO: A microcontroller board based on the ATmega328P.
- Rocker Switch (SPST): A single-pole single-throw switch used to control the power circuit.
- 18650 Li-ion Battery x 2: A power source for the circuit.
Wiring Details
Servo
- GND: Connected to the common ground.
- VCC: Connected to the 5V supply from the Arduino UNO.
- Pulse: Connected to digital pin D10 on the Arduino UNO for PWM control.
HC-SR04 Ultrasonic Sensor
- GND: Connected to the common ground.
- VCC: Connected to the 5V supply from the Arduino UNO.
- TRIG: Connected to analog pin A1 on the Arduino UNO.
- ECHO: Connected to analog pin A2 on the Arduino UNO.
Gearmotor DC Wheels (Right and Left)
- PIN1 (Right): Connected to OUT2 on the L298N motor driver.
- PIN2 (Right): Connected to OUT1 on the L298N motor driver.
- PIN1 (Left): Connected to OUT3 on the L298N motor driver.
- PIN2 (Left): Connected to OUT4 on the L298N motor driver.
Buzzer
- POSITIVE: Connected to digital pin D9 on the Arduino UNO.
- NEGATIVE: Connected to the common ground.
L298N DC Motor Driver
- GND: Connected to the common ground.
- 5V: Connected to the 5V supply from the Arduino UNO.
- 12V: Connected to one terminal of the rocker switch.
- OUT1, OUT2, OUT3, OUT4: Connected to the respective pins of the Gearmotor DC Wheels.
- IN1, IN2, IN3, IN4: Connected to digital pins D4, D5, D6, and D7 on the Arduino UNO respectively.
Arduino UNO
- GND: Connected to the common ground.
- 5V: Provides the 5V supply to the servo and ultrasonic sensor.
- D4, D5, D6, D7: Control signals for the L298N motor driver.
- D9: Output to the buzzer.
- D10: PWM output to the servo.
- A1, A2: Input from the ultrasonic sensor.
Rocker Switch (SPST)
- Terminal 1: Connected to the 12V input on the L298N motor driver.
- Terminal 2: Connected to the positive terminal of the 18650 Li-ion batteries.
18650 Li-ion Battery x 2
- +: Connected to terminal 2 of the rocker switch.
- -: Connected to the common ground.
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 implementation. The setup() function is intended to contain initialization code that runs once, such as pin mode declarations. The loop() function is meant to contain the main logic of the program, which runs repeatedly.
Additional Notes
- The code for the Arduino UNO is currently a placeholder and needs to be completed with the logic for controlling the motors, reading sensor data, and driving the servo and buzzer.
- The wiring details provided assume a common ground configuration where all components share the same ground reference.
- The power supply from the batteries to the motor driver is controlled by the rocker switch, allowing for an easy way to power the motors on and off.
- The L298N motor driver's ENA and ENB pins can be connected to PWM-capable pins on the Arduino if speed control is required. These connections are not documented in the provided net list and would need to be added.