🤖 Servo Control Lesson (Student Challenge)
PHASE 1: Think First (No Code)
🧠Goal
Your task is to build a program that controls two servo motors using the Serial Monitor.
- One servo should move to the angle you type
- The second servo should move in the opposite direction
🔧 What You Need to Figure Out
How do you control a servo motor in Arduino?
How do you connect (attach) a servo to a pin?
How do you send and receive data using the Serial Monitor?
How do you make sure the angle stays between 0 and 180?
How can you make one servo move in the opposite direction?
PHASE 2: Tools You Can Use
🧩 Servo Setup
#include <Servo.h>
Servo servo1;
Servo servo2;
🧩 Setup Commands
Serial.begin(9600);
servo1.attach(A1);
servo2.attach(A2);
servo1.write(90);
servo2.write(90);
🧩 Reading Input
Serial.available() > 0
int angle = Serial.readStringUntil('\n').toInt();
🧩 Safety
angle = constrain(angle, 0, 180);
🧩 Moving Servos
servo.write(angle);
🚀 Decide:
Which servo follows the input?
Which one should be reversed?
PHASE 3: Logic Challenge
🎯 Expected Behavior
- Input 0 → Servos: 0° and 180°
- Input 90 → Servos: 90° and 90°
- Input 180 → Servos: 180° and 0°
If input = 30 → output should be 150
If input = 60 → output should be 120
💡 Hint
What number are you subtracting from?
PHASE 4: Build It
🧪 Steps to Try
- Set up two servo motors
- Open Serial Monitor
- Send a number (0–180)
- Make both servos respond correctly
🚀 Final Challenge:
Build the entire program using ONLY the commands above.
PHASE 5: Think Deeper
- What happens if you remove the mirror logic?
- How could you control more than two servos?
- How would you make the movement smoother?