DIY: Relay Switch Motor Controller - Arduino

136,141

569

35

About: Youtube: www.youtube.com/channel/UCh5aXlcWXmVQ4ipj0y3qjbw?&ab_channel=SimpleCircuits

Hello everyone,

In this tutorial, we will be building a motor controller using two relay switches and an arduino.

Components used in this project:

SainSmart UNO R3: http://www.amazon.ca/gp/product/B00E5WJSHK?psc=1&...

9v battery: http://www.amazon.ca/Tenergy-Charger-250mah-Recha... http://www.dx.com/p/dd15-dc-9v-battery-button-pow...

M-F jumper wires: http://www.amazon.ca/Accmart-Flexible-Breadboard-...

Motor: http://www.amazon.ca/6760RPM-Rotary-Speed-bornes-...

5V relay switch: http://www.amazon.ca/SainSmart-2-CH-2-Channel-Rel...

Supplies:

Step 1: Connect the Motor & Power Supply

Connections:

Motor positive - Relay switch 1 COM input

Motor negative - Relay switch 2 COM input

9v battery positive - Relay switch 1 NO & Relay switch 2 NO

9v battery negative - Relay switch 1 NC & Relay switch 2 NC

Each relay switch has three inputs

NO (Normally open) ,COM (Common) and NC (Normally closed)

In this project, both wires from the motor will connect to both of the COM (middle) inputs of the relay switches.

The positive wire from the 9v battery will connect to both of the NO (top) inputs.

The negative wire from the 9v battery will connect to both of the NC (bottom) inputs.

This external power supply (9v battery) will be used to power the motor. This can be changed to control the speed of the motor.

Step 2: Connect the Arduino

Connection:

Arduino 5v pin - Relay module VCC pin

Arduino GND pin - Relay module GND pin

Arduino pin#7 - Relay module IN1

Arduino pin#8 - Relay module IN2

After we finish connecting the motor, all we need to do is power the relay switch module itself. using the arduino, we can connect the wires and send signals to activate the relay switches.

Step 3: Upload the Code:

#define CW 7 //CW is defined as pin #7//

#define CCW 8 //CCW is defined as pin #8//

void setup() { //Setup runs once//

pinMode(CW, OUTPUT); //Set CW as an output//

pinMode(CCW, OUTPUT); //Set CCW as an output//

}

void loop() { //Loop runs forever//

digitalWrite(CW,HIGH); //Motor runs clockwise//

delay(1000); //for 1 second//

digitalWrite(CW, LOW); //Motor stops//

digitalWrite(CCW, HIGH);//Motor runs counter-clockwise//

delay(1000); //For 1 second//

digitalWrite(CCW, LOW); //Motor stops//

}

//end of code//

Download the code here:

https://drive.google.com/open?id=0Bwb-DkQkOX3jfkdI...

Step 4: Done!

If everything was done correctly, you should end up with a motor that spins clockwise for 1 second and counter-clockwise for 1 second.

As always, you can modify the code and change the voltage for your own projects.

If you want to see this project in action, please click on the link below:

2 People Made This Project!

Recommendations

  • Fandom Contest

    Fandom Contest
  • Gardening Contest

    Gardening Contest
  • Classroom Science Contest

    Classroom Science Contest

35 Discussions

0
None
JoshuaM112

4 months ago

Can I use a single channel relay instead? Will it work?

-TIA

0
None
BhavinP29

4 months ago

Namaste sir, Can I use 12v battery for relay? And arduino uno power supply?

0
None
RiyaGeethz

4 months ago

Mam/Sir,How it can be modified in connection if 4 channel relay and two motors had been used to control direction of motor.

0
None
HenryC123

Question 6 months ago on Introduction

This is getting very close to what I want. How can the program etc. be modified to allow astep in one direction then a step in the opposite direction . I would think that the relays would need to be switched on and off as required.
Thanks
h

0
None
Luck1504

Question 6 months ago

Hi, it's a wonderful project but I was wondering: could I connect a 9v battery to the relay and connect the Arduino at the PC?
Thanks

0
None
Farooqitj

Question 7 months ago

have made this projected and it turns the motor both ways. Thanks for very use full instructable. but the question is that cw and ccw movements are not same. Is that because i used geared motor ?

update: changed geared motor to simple motor, still same behavior. on one direction motor rotates around 40% less than the other direction.

0
None
mansoorshah

9 months ago on Step 3

hi sir

this is very nice prject i make too like this and its work i am glad to make this and thanks for yours tips and share it with all procedure and commponents .

sir i have a question : sir if i used this project for solar stand which is moving up and down (east To West )with the help of a DC 12 volt motor and also 2 LDR used for sun tracking

so sir you help me how can i make this, ,

i do some work on it but codes still not working properly!

if u see my project tell me i make pic and send you sir with many thanks i am waiting for yours reply

Mansoor shah

Email: ssgpk2@gmail.com

0
None
DanielB857

Question 10 months ago on Step 4

this with a timer .. perfect what i need.Just googla and try to find how to code them: S

0
None
MukymooD

10 months ago

How would I modify this for use with a solenoid valve? I have followed the instructions; the lights on the relay are coming on and off alternating which is what you would expect. the valve isn't doing anything

0
None
ErikD49

Question 1 year ago on Introduction

is it possible to build something that would send a signal at a certain voltage ?

0
None
efarnham731

1 year ago

I need a similar motor controller. But I only need a controller that will start the motor for 5 minutes then shuts it off. I would need a button to start it each time. All small items, nothing that takes a lot of room. Smaller is better! How do I do this?

0
None
GowChotu

1 year ago

good video. Can you make a video on how to control the motor speed using relay and arduino?

0
None
spj007

1 year ago

hi thanks for this very clear video. even for me ( a nono in electric )
i got it to work fine for me. i am making a solar tracking device with a 12 volt (drill) dc motor. you say in your video that you can put power directly on the motor for more speed. could you explain this a bit more for me ? scheme perhaps ?
thanks in advance.
kind regards JP ,the netherlands

0
None
pavan kumarm

2 years ago

Can I use an electromagnet in the place of a dc motor for changing the polarity? Also im facing the problem with the repulsive forces between electromagnets. Will u pls suggest ?

0
None
Malik Attau

2 years ago

I m using this ioio otg in project of home automation if i use pin 1 to 30 to connect load with the help of relays it will effect the performance of IOIO OTG or not ?? current will effect IOIO OTG ?

0
None
Malik Attau

2 years ago

i m using same relay for my home automation project but the problem is that when i give 5 v from ioio otg to chnel 1 relay does not work but hen i give grnd pin to the chanel 1 pin relay operates what is the problem can anyone tell me plzz

0
None
shriharis1729

3 years ago

Can anyone tell how the same would work with a single relay channel. Or will it not ?

1 reply
0
None
nupurpur

3 years ago

I connected the circuit perfectly. The relays seem to work fine,although the motor doesn't rotate.What could be the reason?

1 reply
0
None
JUNEZ RIYAZnupurpur

Reply 2 years ago

go through this

https://www.youtube.com/watch?v=2LqPKpQfyTE