arduino_uno_guy
Published © GPL3+

The Beginners Guide to Micro Servos

This will teach you basic things you need to know about servos.

BeginnerFull instructions provided55,235
The Beginners Guide to Micro Servos

Things used in this project

Hardware components

SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Servo.h

Story

Read more

Schematics

Wiring diagram

Wire the servo up to your Arduino board EXACLY or else it won’t work

Code

Code for project 1

Arduino
Copy this code into ide
#include <Servo.h>


Servo servo

void setup() {
  servo.attach(9);
  
}
void loop() {
  servo.write(0);
  delay(500);
  delay(10000);
  servo.write(90);
  delay(500);
  delay(10000);
  servo.write(180);
  delay(500);
  delay(10000);
  servo.write(90);
  delay(500);
  delay(10000);
  servo.write(0);
  delay(500);
  delay(10000);
}

Code for project 2

Arduino
Upload this code in a different sketch in ide
#include <Servo.h>

Servo servo;

void setup() {
  servo.attach(9);
  
}
void loop() {
  for(int i=0;i<180; i++){
    servo.write(i);
    delay(15);
  }
  for(int i=180; i>0; i--){
    servo.write(i);
    delay(7);
  }
  
}

Code for for project number 3

Arduino
Upload this code into a blank sketch in arduino
#include <Servo.h>

Servo servo;

void setup(){
  servo.attach(9);
}
void loop(){
  servo.write(10);
  delay(300);
  servo.write(0); 
  delay(300);
  servo.write(20); 
  delay(300);
  servo.write(0); 
  delay(300);
  servo.write(30); 
  delay(300);
  servo.write(0); 
  delay(300);
  servo.write(40); 
  delay(300);
  servo.write(0); 
  delay(300);
  servo.write(50); 
  delay(300);
  servo.write(0); 
  delay(300);
  servo.write(60); 
  delay(300);
  servo.write(0); 
  delay(300);
  servo.write(70); 
  delay(300);
  servo.write(0); 
  delay(300);
  servo.write(80); 
  delay(300);
  servo.write(0); 
  delay(300);
  servo.write(90);
  delay(300);
  delay(1000);
  servo.write(0); 
  delay(300);
  
}

Code for project 4

Arduino
Upload this code into a new sketch in ide
#include <Servo.h>

int pos=random(0,180);

Servo servo;

void setup(){
  servo.attach(9);
}
void loop(){
  servo.write(pos);
  delay(250);
  pos=random(0,180);
  delay(5000);
}

Credits

arduino_uno_guy

arduino_uno_guy

1 project • 8 followers

Comments