loading

Whats the point of having a development board if you cant move things with it?

This is the guide that will get you started with using Servos (geared digitally controlled motors) in your projects using the LinkIt One board.

This is again aimed for people who are just starting their journey in the field of electronics.

Read on to learn how to make your projects move!

Step 1: Getting the Materials

To make this instructable you will need:

  1. A LinkIt One Board with USB
  2. A computer with a working internet connection
  3. A servo motor (I have used a 9g one)
  4. A few jumper wires to connect to the servo to the board

That's it! Gather your supplies and lets get started

Step 2: Understanding a Servo

A servo motor differs from the other types of motors that you may have seen. A servo motor has 3 wires all differently coloured and used to control the motor.

It has gears attached to a normal DC motor along with a driving circuit which enables us to rotate it to a specified degree by sending digital commands

A servo can NOT be rotated 360 degrees and you must NOT try to move it on your own and this may damage the gears (I write from experience)

Step 3: The Connections and Code

First identify the wires that are present in your servo

The different colored wires typically present in a Servo are as follows:

  • Black/ Brown =GND - connect to GND pin on board
  • Red =VCC - connect to 5V pin on board
  • Orange/Yellow =Data - connect to an analog pin / digital pin with the ~ symbol next to it (stands for PWM - a special feature which allows us to control servos) [Pin 9 according to the code]

Once you have made these connections and your LinkIt One board is connected to your computer paste the following code to your arduino IDE window and hit upload!

This should make your servo rotate a 180 degrees and back till infinity.

#include

int i;

Servo myservo;

void setup() {

myservo.attach(9);

myservo.write(90);

}

void loop() {

delay(500);

i += 10;

if (i == 180) {

i = 0; }

myservo.write(i);

}

Step 4: Understanding the Code

#include<Servo.h>

This line is what tells the arduino IDE that we are going to connect a Servo motor to our board and hence we need to incorporate the back end code that goes into sending the right signals to the servo motor.

Servo myservo;

void setup() {

myservo.attach(9);

myservo.write(90);

}

Here we are creating a Servo Object which is basically a virtual version of our servo motor. We are calling this servo myservo and hence once we name it so using the Servo myservo; line we can simply write myservo every time we need to refer to our servo.

We are also mentioning that we are attaching the servo to pin No 9 in the myservo.attach(9); line. We can set the position of the knob of the servo to any angle between 0 to 360 degrees by using the command myservo.write(angle); We are initially setting this value to 90 to begin with.

void loop() {

delay(500);

i += 10;

if (i == 180)

{ i = 0; }

myservo.write(i);

}

Here we are giving the servo increments of 10 degrees by using a for loop which basically increments the value of an arbitrary variable i. Here the value of i keeps on increasing from 0 to 180. Once the value reached 180 it causes our if condition statement to be executed and hence is reset back to 0. This happens along with each new value of i being sent to the servo as an angle that the servo has to turn to. Together this causes the servo to rotate from 0 to 180 and then back to 0.

About This Instructable

237views

3favorites

License:

Bio: &quot;We were created to create&quot; - Me
More by evil_scientist:Getting started with LinkIt One - Servos Getting Started with LinkIt One - Blinking an LED Making a Minion Costume! 
Add instructable to: