Dual-Actuator Interface: Precision DC and Servo Control Via Analog Sensors

by guptamanjit13 in Circuits > Electronics

57 Views, 1 Favorites, 0 Comments

Dual-Actuator Interface: Precision DC and Servo Control Via Analog Sensors

Dual-Actuator Interface Precision DC and Servo Control via Analog Sensors.png
Dual-Actuator Interface Precision DC and Servo Control via Analog Sensors.png

What I Made

I designed and built an Arduino-based dual-actuator control system that allows for the real-time adjustment of a DC motor's speed and a servo motor's angular position. The project utilizes an Arduino Uno as the microcontroller, an L298N motor driver for high-current power management, and two potentiometers acting as analog sensors to provide user input.

Why I Made It

The goal of this project was to demonstrate the versatility of analog sensors in controlling physical hardware. By mapping the variable voltage from the potentiometers to PWM (Pulse Width Modulation) signals and servo degrees, I wanted to create a hands-on learning tool that bridges the gap between digital code and mechanical motion.

Supplies

HW-475 LED Module.jpg
Jumper Wires.jpg
830-Point Solderless Breadboard.jpg
B10K Rotary Potentiometer (Sensor).jpg
SG90 Micro Servo Motor.jpg
DC Motor with Propeller.jpg
L298N Motor Driver Module.jpg
Arduino Uno R3.jpg

Materials and Components

  1. Arduino Uno R3: The central microcontroller used to process sensor inputs and execute the motor control logic.
  2. L298N Dual H-Bridge Motor Driver: A high-current driver module required to power the DC motor and interpret PWM signals for speed control.
  3. DC Motor with Propeller: The primary actuator for demonstrating variable speed and rotational motion.
  4. SG90 Micro Servo Motor: A precision actuator used for 180-degree angular positioning.
  5. B10K Rotary Potentiometers (x2): These serve as the analog sensors providing user-controlled variable resistance for speed and position.
  6. 830-Point Solderless Breadboard: The base for organizing your prototyping circuit and sensor connections.
  7. Jumper Wires (M-M and M-F): A variety of multicolored wires used to bridge connections between the Arduino, breadboard, and motor driver.
  8. HW-475 LED Module: A visual status indicator used to signal when the circuit is receiving power or data.
  9. External Power Supply: A 9V battery or 12V DC adapter (essential to provide sufficient current to the L298N and DC motor).

Tools Required

  1. Computer or Laptop: Necessary for writing, compiling, and uploading your code via the Arduino IDE.
  2. USB-B Cable: The standard cable used to connect your Arduino Uno to your computer’s USB port.
  3. Small Flathead Screwdriver: Used for tightening the screw terminal blocks on the L298N motor driver to ensure secure wiring.

Brain Vs. Muscle

circuit dig.png

⚠️ Quick warning: Take it from me, never try to power a DC motor directly from your Arduino’s digital pins. Standard hobby motors draw far too much current and generate voltage spikes that will instantly fry your microcontroller. We are using the high-power L298N Motor Driver as a heavy-duty "bouncer" to keep these electrical noises separate.

  1. The Brain (Logic): Connect the logic control pins from the L298N to the Arduino Uno. Connect IN1 to Digital Pin 7 (Direction 1) and IN2 to Digital Pin 8 (Direction 2). For the specialized speed signal, connect the ENA jumper (ensure the jumper cap is removed) directly to the PWM Pin 5.
  2. The Muscle (Power): Connect the main power wires. The positive wire from your 9V/12V Battery Pack connects to the 12V screw terminal on the L298N. The DC motor itself connects to the OUT1 and OUT2 terminals.

🔑 The Golden Rule: COMMON GROUND! This is the most critical connection for the system to function. You must connect a jumper wire from the L298N’s GND screw terminal directly to a GND pin on the Arduino. If they do not share this common reference point, your PWM speed signals won’t make sense to the driver chip, and your motors will just twitch randomly or do nothing at all.

(Visual Aid Recommendation: Use the 'Fritzing' circuit diagram you previously generated, as it clearly shows this exact common ground configuration.)

The Logic (The Code)

For the code, I decided to keep the logic straightforward by using the map() function to translate analog sensor data into motor movements. I’ve added detailed comments within the script, but if you have any questions about the PWM or Servo timing, feel free to ask in the comments!

#include <Servo.h>


// Define Pins for Sensors

#define POT_SPEED_PIN A0

#define POT_SERVO_PIN A1


// Define Pins for Actuators

#define ENA_PIN 5 // PWM Speed Control

#define IN1_PIN 7 // Direction 1

#define IN2_PIN 8 // Direction 2

#define SERVO_PIN 9 // Servo Signal

#define LED_PIN 13 // Status Indicator


Servo myServo;


void setup() {

// Initialize Motor Driver Pins

pinMode(ENA_PIN, OUTPUT);

pinMode(IN1_PIN, OUTPUT);

pinMode(IN2_PIN, OUTPUT);

// Initialize LED Pin

pinMode(LED_PIN, OUTPUT);


// Attach Servo to Pin 9

myServo.attach(SERVO_PIN);


// Set initial motor direction (Forward)

digitalWrite(IN1_PIN, HIGH);

digitalWrite(IN2_PIN, LOW);


Serial.begin(9600);

}


void loop() {

// 1. DC MOTOR CONTROL (Speed Sensor)

int potSpeedValue = analogRead(POT_SPEED_PIN);

// Map 0-1023 sensor range to 0-255 PWM range

int motorSpeed = map(potSpeedValue, 0, 1023, 0, 255);

analogWrite(ENA_PIN, motorSpeed);


// 2. SERVO CONTROL (Position Sensor)

int potServoValue = analogRead(POT_SERVO_PIN);

// Map 0-1023 sensor range to 0-180 degree range

int servoAngle = map(potServoValue, 0, 1023, 0, 180);

myServo.write(servoAngle);


// 3. STATUS INDICATOR

// Turn on LED if any motor is active

if (motorSpeed > 10) {

digitalWrite(LED_PIN, HIGH);

} else {

digitalWrite(LED_PIN, LOW);

}


// Debugging output to Serial Monitor

Serial.print("Motor Speed: ");

Serial.print(motorSpeed);

Serial.print(" | Servo Angle: ");

Serial.println(servoAngle);


delay(20); // Small delay for stability

}

How It Works:

The Sensors: The code reads the variable voltage from the two B10K Potentiometers using analogRead. This gives us a value between 0 and 1023.

The Translation: We use the map() function to convert that 0-1023 range into usable data—0-255 for the PWM speed of the DC motor and 0-180 for the degrees of the servo motor.

The Execution: The Arduino sends a PWM signal to the L298N's ENA pin to throttle the motor speed and a specific pulse-width signal to the SG90 Servo to set its angle.

The Feedback: I added a condition for the HW-475 LED on Pin 13. It will light up whenever the DC motor is spinning, giving you a visual confirmation that the system is "live."

Downloads

Conclusion and Troubleshooting

Troubleshooting (If things aren't moving):

Even the best engineers run into "gremlins" in their circuits. If your motors aren't behaving, check these common fixes:

  1. The "Twitching" Servo: If your SG90 is vibrating or reset-looping your Arduino, it’s likely a power issue. Servos draw high "stall current." Ensure you are using a dedicated DC Power Adapter for the motor driver rather than relying solely on your laptop’s USB port.
  2. The DC Motor is Silent: Double-check your Common Ground. If the L298N's GND terminal isn't physically linked to the Arduino's GND pin, the PWM signal has no reference point and won't trigger the driver.
  3. Zero Sensor Feedback: Open your Serial Monitor (set to 9600 baud). If you don't see the "Motor Speed" or "Servo Angle" values changing when you turn the knobs, check that your potentiometers are firmly seated in the breadboard and that the center "wiper" pins are correctly connected to A0 and A1.
  4. Direction Issues: If the DC motor spins the "wrong" way, simply swap the two wires connected to the OUT1 and OUT2 terminals on the L298N module.