571 Actuator Hands-On Labs
Learning Objectives
After completing these labs, you will be able to:
- Build complete actuator control systems from scratch
- Interface multiple actuator types in a single project
- Implement coordinated motion control
- Use Wokwi simulations for testing before hardware deployment
- Troubleshoot common actuator problems
571.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
+12V --------> Motor VCC (from external PSU)
OUT1 --------> Motor +
OUT2 --------> Motor -
Code:
#define MOTOR_IN1 26
#define MOTOR_IN2 27
#define MOTOR_EN 14
const int pwmFreq = 5000;
const int pwmChannel = 0;
const int pwmResolution = 8;
void setup() {
Serial.begin(115200);
pinMode(MOTOR_IN1, OUTPUT);
pinMode(MOTOR_IN2, OUTPUT);
ledcSetup(pwmChannel, pwmFreq, pwmResolution);
ledcAttachPin(MOTOR_EN, pwmChannel);
Serial.println("DC Motor Controller with Ramping");
}
void loop() {
Serial.println("Accelerating forward...");
rampSpeed(0, 255, true, 50);
delay(2000);
Serial.println("Decelerating to stop...");
rampSpeed(255, 0, true, 50);
delay(1000);
Serial.println("Accelerating backward...");
rampSpeed(0, 255, false, 50);
delay(2000);
Serial.println("Decelerating to stop...");
rampSpeed(255, 0, false, 50);
delay(1000);
}
void rampSpeed(int startSpeed, int endSpeed, bool forward, int delayMs) {
int direction = (endSpeed > startSpeed) ? 1 : -1;
if (forward) {
digitalWrite(MOTOR_IN1, HIGH);
digitalWrite(MOTOR_IN2, LOW);
} else {
digitalWrite(MOTOR_IN1, LOW);
digitalWrite(MOTOR_IN2, HIGH);
}
for (int speed = startSpeed;
direction > 0 ? speed <= endSpeed : speed >= endSpeed;
speed += direction * 5) {
ledcWrite(pwmChannel, speed);
Serial.print("Speed: ");
Serial.println(speed);
delay(delayMs);
}
ledcWrite(pwmChannel, endSpeed);
}Expected Learning Outcomes:
- Understand H-bridge operation for bidirectional motor control
- Implement PWM speed control
- Create smooth acceleration/deceleration profiles
571.2 Lab 2: Servo-Based Robotic Gripper
Objective: Build a 2-DOF robotic arm with gripper using servo motors and coordinated motion.
Materials:
- ESP32 development board
- 3x SG90 or MG90S servo motors
- 5V 2A power supply
- Breadboard and jumper wires
Do NOT power multiple servos from the ESP32 5V pin! Use an external 5V 2A power supply. Connect ESP32 GND to power supply GND (common ground).
Circuit Diagram:
ESP32 Servos
GPIO18 ------> Base Servo (Signal)
GPIO19 ------> Arm Servo (Signal)
GPIO21 ------> Gripper Servo (Signal)
GND ----------> All Servo GND
5V ------------> All Servo VCC (from external PSU, NOT ESP32 5V!)
Code:
#include <ESP32Servo.h>
Servo baseServo;
Servo armServo;
Servo gripperServo;
#define BASE_PIN 18
#define ARM_PIN 19
#define GRIPPER_PIN 21
struct Position {
int base;
int arm;
int gripper;
};
void setup() {
Serial.begin(115200);
baseServo.attach(BASE_PIN);
armServo.attach(ARM_PIN);
gripperServo.attach(GRIPPER_PIN);
moveToPosition({90, 90, 90}, 1000);
Serial.println("Robotic Gripper Ready");
Serial.println("Commands: h=home, g=grab, r=release, s=sequence");
}
void loop() {
if (Serial.available()) {
char cmd = Serial.read();
switch(cmd) {
case 'h':
Serial.println("Moving to home position");
moveToPosition({90, 90, 90}, 1500);
break;
case 'g':
Serial.println("Grab sequence");
grabSequence();
break;
case 'r':
Serial.println("Release sequence");
releaseSequence();
break;
case 's':
Serial.println("Pick and place sequence");
pickAndPlace();
break;
}
}
}
void moveToPosition(Position target, int duration) {
int currentBase = baseServo.read();
int currentArm = armServo.read();
int currentGripper = gripperServo.read();
int steps = duration / 20;
for (int i = 0; i <= steps; i++) {
float progress = (float)i / (float)steps;
baseServo.write(currentBase + (target.base - currentBase) * progress);
armServo.write(currentArm + (target.arm - currentArm) * progress);
gripperServo.write(currentGripper + (target.gripper - currentGripper) * progress);
delay(20);
}
}
void grabSequence() {
moveToPosition({90, 45, 90}, 1000);
delay(500);
moveToPosition({90, 45, 45}, 800);
delay(500);
moveToPosition({90, 90, 45}, 1000);
}
void releaseSequence() {
moveToPosition({90, 45, 45}, 1000);
delay(500);
moveToPosition({90, 45, 90}, 800);
delay(500);
moveToPosition({90, 90, 90}, 1000);
}
void pickAndPlace() {
Position home = {90, 90, 90};
Position pickPos = {45, 45, 90};
Position pickGrab = {45, 45, 45};
Position placePos = {135, 45, 45};
Position placeRelease = {135, 45, 90};
moveToPosition(pickPos, 1500);
delay(500);
moveToPosition(pickGrab, 800);
delay(500);
moveToPosition(placePos, 2000);
delay(500);
moveToPosition(placeRelease, 800);
delay(500);
moveToPosition(home, 1500);
}571.3 Lab 3: Multi-Actuator Control System
This lab combines multiple actuator types in a single project.
571.3.1 Wokwi Simulation
571.3.2 About the Components
| Component | Type | Control Method | Function |
|---|---|---|---|
| Servo Motor | Position | PWM (50Hz, 1-2ms pulse) | Angle control |
| DC Motor | Speed | PWM (5kHz) + Direction | Variable speed |
| RGB LED | Visual | 3x PWM channels | Color mixing |
| Buzzer | Audio | Tone frequency | Sound alerts |
571.3.3 Challenges
Create a traffic light using the RGB LED:
- Red for 5 seconds
- Yellow for 2 seconds
- Green for 5 seconds
- Yellow for 2 seconds
- Repeat
Add a buzzer beep when changing to green (pedestrian signal).
Use a potentiometer to control:
- DC motor speed (0-100%)
- LED brightness (proportional to speed)
- Buzzer pitch (higher = faster)
Implement a temperature-responsive fan:
- Read temperature from sensor (or simulate with potentiometer)
- Below 20C: LED blue, motor off
- 20-25C: LED green, motor 50%
- 25-30C: LED yellow, motor 75%
- Above 30C: LED red, motor 100%, alarm buzzer
571.4 Lab 4: Advanced PID Control
This lab implements PID feedback control for precise motor speed regulation.
571.4.1 Learning Objectives
- Understand PID controller theory and tuning
- Implement encoder feedback for closed-loop control
- Debug control loop issues using Serial Monitor
571.4.2 Key Concepts
Proportional Term (P):
Output = Kp x Error
Responds to current error. Higher Kp = faster response but may overshoot.
Integral Term (I):
Output = Ki x Integral(Error)
Eliminates steady-state error. Higher Ki = faster correction but may oscillate.
Derivative Term (D):
Output = Kd x Derivative(Error)
Dampens oscillations. Higher Kd = more stability but sensitive to noise.
571.4.3 Tuning Guide
- Start with Kp = 1, Ki = 0, Kd = 0
- Increase Kp until system oscillates
- Reduce Kp by 50%
- Add Ki to eliminate steady-state error
- Add Kd if oscillations occur
571.5 Troubleshooting Guide
| Problem | Possible Cause | Solution |
|---|---|---|
| Motor doesnโt spin | Wrong wiring | Check IN1, IN2, and EN connections |
| Motor only spins one direction | Direction pins swapped | Swap IN1 and IN2 |
| Servo jitters | Insufficient power | Use external 5V supply |
| Stepper skips steps | Acceleration too fast | Reduce max speed, increase acceleration time |
| Driver overheats | Current too high | Add heatsink, reduce motor current |
| Random resets | Missing flyback diode | Add diode across inductive loads |
571.6 Whatโs Next?
Now that youโve completed the hands-on labs, test your knowledge with the assessment chapter.