====== Controlling a Servo motor ====== This scenario demonstrates how to control the position of a servo motor using Arduino. Servo motors are used for precise angular positioning in robotics and automation. In this lab, a thermistor sensor is attached to the servo motor arm in a way that it can be moved on the front of the fan (DC motor). By triggering the fan, it is possible to change the temperature and so initiate output changes on thermistor readings. {{:en:iot-open:practical:hardware:taltech:arduino:scenarios:servo.jpg?200|}} ===== Prerequisites ===== * Familiarize yourself with the Arduino hardware reference. * Install the built-in Arduino Servo library. * Understand basic PWM concepts for servo control. ===== Hardware Connections ===== ^ Component ^ Arduino Pin ^ | Servo Signal | 10 (PWM) | Servo specifications: * Standard miniature servo (SG90 or similar) * Voltage: Typically 5V * PWM frequency: 50 Hz * Rotation range: ~0° to 180° ===== Task ===== Write a program that rotates the servo sequentially to 0°, 90°, and 180°, pausing for one second at each position. ===== Steps ===== === Step 1: Include Servo Library === #include === Step 2: Initialize Servo Object === Declare a servo object and assign it a pin: Servo myServo; const int servoPin = 10; === Step 3: Setup === Attach the servo object to the servo pin: void setup() { myServo.attach(servoPin); } === Step 4: Control Loop === Program the servo rotation sequence: void loop() { myServo.write(0); // Move to 0 degrees delay(1000); // Wait 1 second myServo.write(90); // Move to 90 degrees delay(1000); // Wait 1 second myServo.write(180); // Move to 180 degrees delay(1000); // Wait 1 second } ===== Validation ===== Observe the servo motor rotate precisely to the angles 0°, 90°, and 180°, pausing clearly at each position. ===== Troubleshooting ===== If the servo does not move or if jittering occurs: * Check the servo connections (signal to pin 10, power, and ground). * Ensure power supply is stable (servo typically requires 5V). * Verify servo library inclusion and pin assignment.