This project consists of one DC motor being controlled via simple serial commands from the PC.  

 

This project consists of one DC motor being controlled via simple serial commands from the PC.


The DC Motor has 2 wires, simply Positive and Negative.
When the positive and negative of the dc motor is connected to a power source then the motor will start turing until the power is removed.

A DC motor is usually able to reverse its turning direction by simply switching the positve and negative wires around.
(Yes,as strange as it sounds... DC motors are able to actually switch the positive and negaitve the other way around to change direcitons)

So, since we want to control the motor both direcitons, we are using 4 relays in this project.

Say for instance, we have a DC motor with a green wire and a yellow wire, if we apply positive the green and negative to the yellow it will turn, and if we switch the green and yellow around it will go the other way.

So lets wire up our relays and motors.

Relay 1
NO > Power source positive +
COM > Green wire on Motor

Relay VCC pin > Arduino 5V
Relay IN (or S) pin > Arduino pin 9
So now this one controls the positive from the power source to the motor's green wire.


Relay 2
NO > Power source negative -
COM > Yellow wire on Motor

Relay VCC pin > Arduino 5V
Relay IN (or S) pin > Arduino pin 10

The purpose of this relay is to control the negative from the power source to the motor

--- As is, if you turn on relay 1 and relay 2, the motor will start spinnng until you switch the relays off.


Relay 3
NO > Power source positive -
COM > Yellow wire on Motor

Relay VCC pin > Arduino 5V
Relay IN (or S) pin > Arduino pin 11

Relay 4
NO > Power source negative +
COM > Green wire on Motor

Relay VCC pin > Arduino 5V
Relay IN (or S) pin > Arduino pin 12


---
So now we have 4 Relays.
If we turn on relay 1 and 2, the motor will spin i.e right
Then if we turn on relay 3 and 4, the motor will then spin in the opposite direction i.e left

Note: We cannot put all 4 relays on at the same time, that will cause the wires to heat up and perhaps do some not so pleasant works... ^_^

For this reason, in the code, when the command 'right' is sent, it first turns relay 3 and 4 off (if its on) and then it turns relay 1 and 2 on.
Likewise with the 'left' command.


IMPORTANT Note:
The relays that were used in the test were some funny kind of ones which were by default On, and if you want to turn the relay Off you have to digtalWrite HIGH (yeah man..really up side down)
So to turn it On you have to use digitalWrite LOW ..lol...

 

 

 

 

 

 


How to control the motor:

Once the wiring is all done, upload the code and then open the serial monitor (press CTRL + SHIFT + M) and type in any of the following commands and press send:

 

right

left

stop

 


Also note: be sure to make the baud rate in the serial monitor to 9600, if it is anything else it is likely not to work