🤖 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.

🔧 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

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

  1. Set up two servo motors
  2. Open Serial Monitor
  3. Send a number (0–180)
  4. Make both servos respond correctly
🚀 Final Challenge: Build the entire program using ONLY the commands above.
PHASE 5: Think Deeper