Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:iot-open:practical:hardware:taltech:arduino:scenarios:servo [2025/06/25 08:56] – created raivo.sellen:iot-open:practical:hardware:taltech:arduino:scenarios:servo [2025/09/02 14:49] (current) raivo.sell
Line 1: Line 1:
-====== Servo motor ======+<pagebreak> 
 +====== 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 === 
 +<code c> 
 +#include <Servo.h> 
 +</code> 
 + 
 +=== Step 2: Initialize Servo Object === 
 +Declare a servo object and assign it a pin: 
 +<code c> 
 +Servo myServo; 
 +const int servoPin = 10; 
 +</code> 
 + 
 +=== Step 3: Setup === 
 +Attach the servo object to the servo pin: 
 +<code c> 
 +void setup() { 
 +  myServo.attach(servoPin); 
 +
 +</code> 
 + 
 +=== Step 4: Control Loop === 
 +Program the servo rotation sequence: 
 +<code c> 
 +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 
 +
 +</code> 
 + 
 +===== 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.
  
en/iot-open/practical/hardware/taltech/arduino/scenarios/servo.1750841816.txt.gz · Last modified: 2025/06/25 08:56 by raivo.sell
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0