Introduction: Speed Control of Dc Motor From Laptop Using Arduino and Processing

Hello everyone

I am vignesh raja. here i like to share the speed control of dc motor from computer using arduino and processing software. in this project the processing software run a simple application window on computer. based on the position of the mouse cursor in that window the processing send value to arduino using serial communication. Based on the value received from processing arduino controls the speed of dc motor using pwm.

Step 1: Circuit Connection

let us see the circuit diagram of this project. it is a simple connection. we have to connect the dc motor with arduino properly.

Step 2: Arduino Code

Here is the arduino code for this project

const int motorPin = 9;

void setup()


Serial.begin(9600); // initialize serial communication at 9600 baudrate

pinMode(motorPin, OUTPUT); // declare the motor control output pin


void loop() {

byte brightness;

if (Serial.available()) {

brightness =; //read value in serial communication

analogWrite(motorPin, brightness); // write the value to motor control pin as pwm



Step 3: Processing Code

processing is a gui software. it helps to create our own graphics using c++ code.

the link for download processing software

here is the processing code for this project:

you can find your COM port number in which arduino is connected with your computer in below right corner of arduino software.

import processing.serial.*;

Serial port;

void setup() {

size(256, 150);

port = new Serial(this, "COM14", 9600); //replace COM port number in your laptop in which arduino is connected instead of COM14 here


void draw() {

for (int i = 0; i < 256; i++) {


line(i, 0, i, 150);




Thank you for reading. see you all in my next instructable.