DKVDH
Published © GPL3+

Simple Servo project for Beginners

This project is an easy way to understand the basics of servo movement with an Arduino Uno.

BeginnerProtip18,417
Simple Servo project for Beginners

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Male Jumper Wires
×1
Arduino Uno PWR sheild
Not required
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×2

Story

Read more

Schematics

Arduino Uno Simple Servo Tester by DKVDH

Simply follow the directions.

Code

Arduino Uno Simple Servo Tester by DKVDH

C/C++
Simply copy and paste code into Arduino IDE or Arduino Web Editor and upload to Arduino Uno.
//Written By DKV 3-8-19, Servo tester//
#include <Servo.h>
Servo servo1; //first servo attached to A0
Servo servo2; //second servo attached to A1

int servoPos1 = 0; //starting positions for servos
int servoPos2 = 0;

void setup() {
  servo1.attach(A0); //servo attaching pins (A0)
  servo2.attach(A1); //servo attaching pins (A1)
};

void loop() {
//SERVO 1
  for(servoPos1 =0; servoPos1 < 180; servoPos1++) //When servo is a position 0, servo will rotate to 180 degrees (half rotation)
  {
    servo1.write(servoPos1);
    delay(10);
  };
  
  for(servoPos1 = 180; servoPos1 > 0; servoPos1--) //When servo is a position 180, servo will rotate to 0 degrees (beginning position)
  {
    servo1.write(servoPos1);
    delay(10);

    
//SERVO 2
    for(servoPos2 =0; servoPos2 < 360; servoPos2++) //full rotation of servo
    {
      servo2.write(servoPos2);
      delay(10);
    };
    for(servoPos2 = 360; servoPos2 > 0; servoPos2++) //full rotation back to starting position
    {
      servo2.write(servoPos2);
      delay(20);
    };
  };
};

Credits

DKVDH

DKVDH

6 projects • 3 followers

Comments