Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
jehankandt
Published © Apache-2.0

Arduino With Servo motor

How to use loop with Servo motor

IntermediateFull instructions provided652
Arduino With Servo motor

Things used in this project

Hardware components

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

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Arduino with Servo motor

Arduino with Servo motor loop

Code

Arduino with Servo motor

C/C++
Arduino with Servo motor loop
//...............JehanKandy........................
//........www.jehankandy.com.......................
//........www.github.com/JehanKandy................

//.......................Motors....................
//.........Servo Motor Function and for loop.......

//in here you should include Servo.h lib..
#include <Servo.h>

//define Servo motors
Servo motor1;


void setup() {
  //define pins for Servo Motors
  motor1.attach(2);  

}

void loop() {
  //Now in here you can call the all functions
  Servom();
  Servoloop();
  

  
  
}
//create function for Servo motoe -> Servom
void Servom(){
  motor1.write(90);
  delay(1000);
  motor1.write(90);
  delay(1000);
}
//create another function for for loop with servo motor -> Servoloop
void Servoloop(){
  for(int i = 0; i <= 180; i=i+20){ //forword
    motor1.write(i);
    delay(100);
  }
  for(int q = 180; q >= 0; q=q-20){ //backword
    motor1.write(q);
    delay(1000);
  }
}

//.........coded by : JehanKandy....
//...........Thank You..............

Credits

jehankandt
21 projects • 8 followers
Contact

Comments

Please log in or sign up to comment.