Controlling Servo Motor Using Keyboard Input

I'M BACK!!!!

Well hello everybody!! It has been quite a long time since i posted here. A bit busy with studies lately. But nevertheless, today I would like to share to you guys about a simple experiment concerning arduino and servo motor. In this experiment, I will be controlling my servo motor movement, which is connected to arduino, through keyboard input. Let's go to step 1 shall we?

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Step 1: List of Items

As usual I will list all of the items(software included) for this simple experiment:


1. Arduino board (I used arduino UNO)

2. Servo motor ( I used a HD-3001HB servo motor)

3. Male to Male wires


1. Arduino IDE

2 Tera Term

Step 2: Step 2: Assembling the Servo Motor to the Arduino

In a servo motor, there will be three connections provided. In my case, my servo motor consists of connection coloured dark brown,red and orange. After several rounds of internet search, I found that:

1. Dark brown connects to the GROUND

2.Red connects to 5V

3.Orange connects to arduino UNO pin 9

I have attached a JPEG image of the sketch for further clarification(I made the sketch using fritzing by the way). However in the sketch the connections are colored Black, Red, and Yellow:

1. Black connects to the GROUND

2. Red to 5V

3. Yellow to arduino UNO pin 9

Step 3: Step 3: the CODE

Now comes the coding part. I'll try my best to explain as deep as possible of the code that I had made for this experiment.


#include<Servo.h> // include server library

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

int poser = 0; // initial position of server

int val; // initial value of input

void setup() {

Serial.begin(9600); // Serial comm begin at 9600bps

ser.attach(9);// server is connected at pin 9


void loop() {

if (Serial.available()) // if serial value is available


val =;// then read the serial value

if (val == 'd') //if value input is equals to d


poser += 1; //than position of servo motor increases by 1 ( anti clockwise)

ser.write(poser);// the servo will move according to position

delay(15);//delay for the servo to get to the position


if (val == 'a') //if value input is equals to a


poser -= 1; //than position of servo motor decreases by 1 (clockwise)

ser.write(poser);// the servo will move according to position

delay(15);//delay for the servo to get to the position




Pssst: I have also attached the arduino code just in case!!

Step 4: STEP 4: the Output

Now, upload your code to the arduino. After uploading, open Tera Term and make a serial connection to the arduino board. Now press the designated button( a or d) and watch how the servo responds to the keyboard input. Thank You very much for your time in reading this instructable. I am sorry if I had written anything wrong (please inform me about it) or my English is bad as English is my second language. Other than that, I would like bid good luck and happy Innovating. Lastly, I would like to say, I'LL BE BACK!!

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    5 Discussions


    11 months ago on Step 2

    Hello, thank u for this post. But i want to ask a question. Can i do this by using MG995 servo?


    1 year ago

    Thanks for the info! I've been trying to alter the code to have a fast and slow function but just adding a bigger step made it super choppy and putting a limit on it made it even slower. I'm by no means a good coder so if you have any ideas hook me up.

    contorller code servo.PNG

    2 years ago

    How do you set up the serial connection between tera term and arduino


    3 years ago

    Thank you, that got me in the right direction. Best Wishes!


    4 years ago

    thanks for your instructable.
    Tera term.. never used it for the arduino only for switches and apc's. I'll give it a try :)