Arduino Servo Basic Code

In arduino projects, you might add servo to your projects. This short tutorial, show you the basic how arduino and servo works together.

Arduino Servo Basic Code

 

Instruction;
1) Connect all jumper wire as shown in diagram.

2) Connect the signal wire from servo to digital pin 9.

Upload this code to your arduino

Arduino Servo Basic

/*
  Servo Basic
  Understanding the basic of servo in arduino projects. Sweep servo to 0, 90, 180, 90 and 0.

  Coded by: arduinoprojects101.com
*/

// include the library code:
#include <Servo.h>

Servo myservo;  // create servo object to control a servo

void setup(){
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop(){
  myservo.write(0);     // sets the servo at 0 degree position
  delay(1000);          // waits for the servo to get there
  myservo.write(90);    // sets the servo at 90 degree position
  delay(1000);          // waits for the servo to get there
  myservo.write(180);   // sets the servo at 180 degree position
  delay(1000);          // waits for the servo to get there
  myservo.write(90);    // sets the servo at 90 degree position
  delay(1000);          // waits for the servo to get there
}

Servo cable have 3 wire, make sure you connect it properly;

Major Components in Project
Parts List;
1) 1x Arduino
2) 1x Servo Motor
3) Jumper wire

For more detail: Arduino Servo Basic Code


A Propos De L'Auteur

Ibrar Ayyub

Je suis expérimenté, rédacteur technique, titulaire d'une Maîtrise en informatique de BZU Multan, Pakistan à l'Université. Avec un arrière-plan couvrant diverses industries, notamment en matière de domotique et de l'ingénierie, j'ai perfectionné mes compétences dans la rédaction claire et concise du contenu. Compétent en tirant parti de l'infographie et des diagrammes, je m'efforce de simplifier des concepts complexes pour les lecteurs. Ma force réside dans une recherche approfondie et de présenter l'information de façon structurée et logique format.

Suivez-Nous:
LinkedinTwitter

Laisser un Commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

fr_FRFrench
Faire défiler vers le Haut