Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based Battery-Powered Motor and Servo Control System

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Battery-Powered Motor and Servo Control System

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

L298N DC Motor Driver (1)

L298N DC Motor Driver (2)

DC Mini Metal Gear Motor

Li-ion 5000mAh Battery

Water Pump

Servo

Wiring Details

Arduino UNO

L298N DC Motor Driver (1)

L298N DC Motor Driver (2)

DC Mini Metal Gear Motor

Li-ion 5000mAh Battery

Water Pump

Servo

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() {