These hands-on labs guide you through building complete actuator control systems, from DC motor speed ramping and servo-based robotic grippers to multi-actuator systems and PID feedback control. Each lab uses ESP32 with Wokwi simulation for safe experimentation before hardware deployment.
Learning Objectives
After completing these labs, you will be able to:
Construct complete actuator control systems from scratch using ESP32 and motor drivers
Integrate multiple actuator types (DC motors, servos, buzzers, LEDs) in a single project
Implement coordinated multi-axis motion control with synchronized timing
Validate actuator designs in Wokwi simulations before hardware deployment
Diagnose and resolve common actuator wiring, power, and control problems
For Beginners: Actuator Labs
These labs are like cooking recipes for electronics – they walk you through building real circuits step by step, from connecting wires on a breadboard to writing code that makes motors spin and buzzers beep. You will use a free online simulator called Wokwi, so you can experiment safely without worrying about breaking any physical components.
12.1 Lab 1: DC Motor Control with L298N
Objective: Control a DC motor using the L298N H-bridge driver with smooth acceleration and deceleration.
Materials:
ESP32 development board
L298N motor driver module
6V DC motor
9V power supply (for motor)
Jumper wires
Circuit Diagram:
ESP32 L298N DC Motor
GPIO26 ------> IN1
GPIO27 ------> IN2
GPIO14 ------> ENA (PWM)
GND ----------> GND --------> Motor GND
+9V ---------> Motor VCC (from external PSU)
OUT1 --------> Motor +
OUT2 --------> Motor -
If current PWM is 128 (50% duty), add 25 to reach 153 (60% duty), increasing motor speed. Higher \(K_p\) values respond faster but may overshoot and oscillate — typical starting values are 0.1-1.0 for motor speed control applications.
Worked Example: Calculating Servo Speeds for Coordinated Multi-Axis Motion
Problem: A 2-DOF robotic arm must move from position A (base=45°, arm=45°) to position B (base=135°, arm=90°) in exactly 2 seconds. Both servos must arrive simultaneously to prevent jerky motion. Calculate the required speeds for each servo.
Given Servo Specifications (SG90):
Speed rating: 0.1 seconds / 60 degrees at 5V
This means: 60° rotation takes 0.1 seconds
Or: 600 degrees per second maximum speed
Step 1: Calculate Angular Distance for Each Servo
Base servo:
Start: 45°
End: 135°
Distance: 135° - 45° = 90° rotation
Arm servo:
Start: 45°
End: 90°
Distance: 90° - 45° = 45° rotation
Step 2: Calculate Required Angular Velocity
Both servos must complete in 2 seconds:
Base servo speed: 90° ÷ 2 seconds = 45°/second
Arm servo speed: 45° ÷ 2 seconds = 22.5°/second
Step 3: Verify Speed is Within Servo Capability
SG90 maximum speed: 600°/second
Both required speeds (45°/s and 22.5°/s) are well below the 600°/s maximum, so this motion is achievable.
moveToPosition(135,90,2000);// Base to 135°, Arm to 90°, in 2000ms
Step 5: Calculate Actual Step Increments
With 2000ms duration and 20ms steps: - Total steps: 2000 ÷ 20 = 100 steps
Base servo:
90° total ÷ 100 steps = 0.9° per step
Arm servo:
45° total ÷ 100 steps = 0.45° per step
Step 6: Verify Servo Can Achieve Step Resolution
SG90 servos typically have: - Control resolution: 1° (can position to nearest degree) - Our increments: 0.9° and 0.45° per step
Since we’re commanding sub-degree increments, the servo’s internal control will round to nearest degree, creating very smooth motion with minimal visible stepping.
Real-World Complications:
Issue 1: Servo Speed Variance
Datasheet says 0.1s/60° but real servos vary by ±20%
Solution: Measure actual servo speed, adjust timing
Issue 2: Different Servo Models
Base servo (metal gear MG996R): 0.17s/60° (slower)
Arm servo (SG90): 0.1s/60°
They’ll arrive at different times!
Solution for Mixed Servos:
// Calculate minimum time for each servo (distance * seconds_per_degree)float baseTime =90.0*(0.17/60.0);// = 0.255 seconds minimumfloat armTime =45.0*(0.10/60.0);// = 0.075 seconds minimum// Convert to milliseconds and use the longer time as the floorint minDurationMs = max((int)(baseTime *1000),(int)(armTime *1000));// 255 msint duration = max(minDurationMs,2000);// Use 2000 ms for smooth motion
Key Insight: Coordinated multi-axis motion requires: 1. Calculate each axis’s travel distance 2. Normalize all axes to same total time 3. Break motion into small steps (20ms intervals for servos) 4. Account for different servo speeds if mixing models 5. Use linear interpolation for smooth, synchronized arrival
Extension: Non-Linear Motion (Ease-In/Ease-Out)
For more natural motion, use easing functions:
float easeInOutCubic(float t){return t <0.5?4* t * t * t :1- pow(-2* t +2,3)/2;}// In loop:float progress = easeInOutCubic((float)i /(float)steps);
This starts slow, speeds up in middle, slows at end—much more human-like than linear motion.
12.6 Knowledge Check
Question: PID Proportional Gain
Key Takeaway
Hands-on labs are essential for understanding actuator behavior that theory alone cannot convey, including power supply limitations, real-world timing constraints, and the importance of smooth acceleration profiles. Always prototype with simulation tools like Wokwi before moving to physical hardware, and remember that proper power supply design is as important as the control code itself.
For Kids: Meet the Sensor Squad!
“Lab day! Lab day!” cheered Lila the LED, blinking excitedly. The Sensor Squad had set up a mini workshop.
“Okay team,” said Max the Microcontroller, “today we’re building a robot arm! Servo Sam, you’re in charge of the joints.”
Servo Sam flexed his gears. “Base rotation – check! Arm lift – check! Gripper – check! I can move to any angle you tell me, Max!”
“But wait,” Bella the Battery said worriedly. “Three servos? That’s a lot of power! Don’t you dare try to power them all through Max – he’ll overheat!”
“Good thinking, Bella!” said Max. “We need a big external power supply for the servos. I just send them tiny signal messages telling them where to go. The heavy lifting power comes from elsewhere.”
Sammy the Sensor watched as the arm picked up a small block. “I can see the arm is at 45 degrees… now closing the gripper… now lifting! It’s working!”
“The secret,” Max explained, “is smooth movements. If I tell all the servos to jump to new positions instantly, the arm jerks around and might knock things over. Instead, I move them gradually – a little bit at a time – like doing a slow-motion dance!”
“Building is the best way to learn!” Lila flashed in agreement.
1. Not Measuring Actuator Current Before Selecting Driver Components
The appropriate transistor, MOSFET, or H-bridge IC depends critically on the actuator’s actual current draw. Without measuring current with a multimeter in series, you might select a driver rated for 500 mA for a motor that draws 800 mA under load, causing driver overheating or failure during the lab. Measure current in your specific circuit before finalizing component selection.
2. Skipping Motor Direction Verification Before Speed Control
When implementing H-bridge DC motor control, verify direction behavior with low PWM duty cycle (20-30%) before incrementing to full speed. Running a motor at full speed in the wrong direction can mechanically damage the mechanism being driven. Always confirm correct rotation direction at low speed first.
3. Lab Wiring on Breadboard Coming Loose During Motor Operation
Motor vibration and cable tension cause breadboard connections to loosen during operation, producing intermittent faults difficult to diagnose. Use wire colors consistently (red for power, black for ground, yellow/green for signals), press connectors firmly into breadboard holes, and consider twist-tying cable bundles to reduce mechanical stress on connections.
4. Not Implementing Ramp-Up in Motor Control Lab Firmware
Starting a motor at 100% PWM immediately causes maximum inrush current, which can trigger power supply protection, cause microcontroller brownout resets, or mechanically stress the driven mechanism. In lab firmware, always ramp PWM duty cycle from 0 to target over 500 ms - 2 seconds to control startup current and reduce mechanical shock.
12.8 What’s Next?
Now that you have completed the hands-on labs, deepen your understanding with the theory chapters or test your knowledge with the assessment.