Arduino UNO-Based Battery-Powered Motor and Servo Control System
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit involves an Arduino UNO microcontroller, two L298N DC motor drivers, a DC Mini Metal Gear Motor, a Water Pump, a Servo, and a Li-ion 5000mAh battery. The Arduino UNO controls the motor drivers, which in turn control the DC motor and water pump. The servo is also controlled by the Arduino. The power for the circuit is supplied by the Li-ion battery.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
L298N DC Motor Driver (1)
- Description: A dual H-Bridge motor driver.
- 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
L298N DC Motor Driver (2)
- Description: A dual H-Bridge motor driver.
- 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
DC Mini Metal Gear Motor
- Description: A small DC motor with metal gears.
- Pins: IN1, IN2
Li-ion 5000mAh Battery
- Description: A rechargeable lithium-ion battery.
- Pins: 11.1V, GND
Water Pump
- Description: A small water pump.
- Pins: VCC, GND
Servo
- Description: A small servo motor.
- Pins: gnd, vcc, pulse
Wiring Details
Arduino UNO
- 5V connected to 5V of both L298N DC Motor Drivers.
- GND connected to GND of both L298N DC Motor Drivers and GND of Li-ion 5000mAh Battery.
- Vin connected to 12V of both L298N DC Motor Drivers and 11.1V of Li-ion 5000mAh Battery.
- D13 connected to IN3 of L298N DC Motor Driver (2).
- D12 connected to IN2 of L298N DC Motor Driver (1).
- D11 connected to ENA of L298N DC Motor Driver (1).
- D10 connected to IN4 of L298N DC Motor Driver (1).
- D7 connected to IN4 of L298N DC Motor Driver (2).
- D6 connected to IN1 of L298N DC Motor Driver (1).
- D5 connected to ENB of L298N DC Motor Driver (1).
- D4 connected to IN3 of L298N DC Motor Driver (1).
L298N DC Motor Driver (1)
- 5V connected to 5V of Arduino UNO and L298N DC Motor Driver (2).
- GND connected to GND of Arduino UNO, L298N DC Motor Driver (2), and Li-ion 5000mAh Battery.
- 12V connected to Vin of Arduino UNO, 12V of L298N DC Motor Driver (2), and 11.1V of Li-ion 5000mAh Battery.
- IN2 connected to D12 of Arduino UNO.
- ENA connected to D11 of Arduino UNO.
- IN4 connected to D10 of Arduino UNO.
- IN1 connected to D6 of Arduino UNO.
- ENB connected to D5 of Arduino UNO.
- IN3 connected to D4 of Arduino UNO.
- OUT1 connected to gnd of Servo.
- OUT2 connected to vcc of Servo.
- OUT3 connected to IN2 of DC Mini Metal Gear Motor.
- OUT4 connected to IN1 of DC Mini Metal Gear Motor.
L298N DC Motor Driver (2)
- 5V connected to 5V of Arduino UNO and L298N DC Motor Driver (1).
- GND connected to GND of Arduino UNO, L298N DC Motor Driver (1), and Li-ion 5000mAh Battery.
- 12V connected to Vin of Arduino UNO, 12V of L298N DC Motor Driver (1), and 11.1V of Li-ion 5000mAh Battery.
- IN3 connected to D13 of Arduino UNO.
- IN4 connected to D7 of Arduino UNO.
- OUT3 connected to GND of Water Pump.
- OUT4 connected to VCC of Water Pump.
DC Mini Metal Gear Motor
- IN1 connected to OUT4 of L298N DC Motor Driver (1).
- IN2 connected to OUT3 of L298N DC Motor Driver (1).
Li-ion 5000mAh Battery
- 11.1V connected to 12V of both L298N DC Motor Drivers and Vin of Arduino UNO.
- GND connected to GND of both L298N DC Motor Drivers and GND of Arduino UNO.
Water Pump
- VCC connected to OUT4 of L298N DC Motor Driver (2).
- GND connected to OUT3 of L298N DC Motor Driver (2).
Servo
- gnd connected to OUT1 of L298N DC Motor Driver (1).
- vcc connected to OUT2 of L298N DC Motor Driver (1).
- pulse connected to D9 of Arduino UNO.
Code Documentation
Arduino UNO Code
const int ENA = 11; // L298N ENA
const int IN1 = 6; // L298N IN1
const int IN2 = 12; // L298N IN2
const int ENB = 5; // L298N ENB
const int IN3 = 4; // L298N IN3
const int IN4 = 10; // L298N IN4
const int servoPin = 9; // Servo pulse pin
#include <Servo.h>
Servo myServo;
void setup() {
// Initialize motor control pins
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// Initialize servo
myServo.attach(servoPin);
// Start with motors and servo off
digitalWrite(ENA, LOW);
digitalWrite(ENB, LOW);
myServo.write(90); // Neutral position
}
void loop() {
// Example: Run DC motor forward
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, 255); // Full speed
delay(2000); // Run for 2 seconds
// Stop DC motor
analogWrite(ENA, 0);
delay(1000); // Wait for 1 second
// Example: Run water pump
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(ENB, 255); // Full speed
delay(2000); // Run for 2 seconds
// Stop water pump
analogWrite(ENB, 0);
delay(1000); // Wait for 1 second
// Example: Move servo to 0 degrees
myServo.write(0);
delay(1000); // Wait for 1 second
// Move servo to 180 degrees
myServo.write(180);
delay(1000); // Wait for 1 second
// Return servo to neutral position
myServo.write(90);
delay(1000); // Wait for 1 second
}
L298N DC Motor Driver (1) Code
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
L298N DC Motor Driver (2) Code
void setup() {