DIY: Relay Switch Motor Controller - Arduino

172,172

582

45

Introduction: DIY: Relay Switch Motor Controller - Arduino

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...

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:

Move It

Participated in the
Move It

2 People Made This Project!

Recommendations

  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

45 Discussions

0
JohanG18
JohanG18

Question 18 days ago on Introduction

Good Day , This I Build works well on DC motor , but I am busy with a AC 220 Volt Split Phase motor. The motor is fitted with a centrifugal switch and that cause the problem Once the motor is CW motion you cant change the direction before the centrifugal switch closes.
Some more information :
1/2 Hp 220 Volt Motor with Starting Winding, Red and Brown Wire Live and Neutral Starting Capacitor 330 Uf in series with Live

Directional , Crossover Switch was in Place before I get a Two Channel , Opto Isolated Relays controlled by my Spark-fun Red Board , Same as UNO

Red and White is the Running Winding and desperately connected to Live and Neutral


Is there a other way to make the relays both "Low" to let the centrifugal switch close and to start the CCW Motion

The motor starts perfectly with manual switch in both directions Amps 3.5 on 50 hz 220 Volt

I am 64 Years old on Pension and electronics and Programming was never part of my Scope

Help will be appreciated , Only God can Safe my 30 Year old Speed Queen

0
jrantolin
jrantolin

Question 5 months ago on Step 4

Asking how to use the relay to shield v3 my motor is 2 wire only the shield v3 os 4 connection can you teach me how to connect?

0
maheshshinde364
maheshshinde364

6 months ago

I want to add a IR proximity sensor as a switch to control the Motor. i.e. if an object is detected by IR sensor then motor should get start rotating. I need circuit diagram and code for it.

0
butterkita
butterkita

8 months ago on Step 4

This worked well, would like to have a wiring diagram

0
ASSALRACHID
ASSALRACHID

Question 8 months ago on Step 1

Hi friend i want to contrôle a dc motor using 2 relays and arduino
I face some problèmes, do the power supply must be indépendant of power supply of arduino the energy source 12 v im using before lm78xx circuit
I connect no-no and nc-nc
Positive of motor com 1 and négative com 2
Positive battery to NO and négative battery to NC
WHEN i send signal of 5v the relay sign that is working but motor not run

0
BarryS103
BarryS103

Question 1 year ago

I have a stationary spin bike with an aluminum clad wheel and set of magnets used for resistance. When the magnet assembly, which is on a hinge, is moved closer to the wheel, the resistance increase, replicating peddling uphill.

I have a DC step motor with a cam attached to the shaft and would like to know how to make a device that, when a button is pushed, the motor will move 5 degrees from zero, and only move a total of 90 degrees. This would be a total of 18 steps of 5 degrees.

I would need a second button that would act the same but reversing the direction of the motor.

The system would need to have the ability to track its position as to no be able to go past 0 degrees CCW, regardless of its position, and not exceed 90 degrees CW. In other words, if I press the button to move CCW when at zero degrees (home position) the motor will not move, but will move CW.

Also, if the motor is at 90 degrees, and the CW button is pressed, the motor will not move, but will index CCW.

The action of pressing either button, if not at its limit, will only cause the motor to rotate 5 degrees CW or CCW, which ever is applicable.

The eighteen 5 degree movements is the equivalent of changing gears 18 times, fro 0 degrees to 90 degrees.

Ruamissionary@gmail.com

0
vkvisuals41
vkvisuals41

Question 1 year ago on Step 4

Block diagram and cirucut diagram need

0
EuH1
EuH1

5 years ago on Introduction

Can I know how to control the speed of the motor?

0
SELVAGANESH VENKATESAN
SELVAGANESH VENKATESAN

Reply 1 year ago

Whether Speed of the motor can be controlled ?? Because the Motor runs at full speed.. Is this possible to run the motor in different RPM ???



Did You get the Answer @EuK1??? Kindly Share Me if u had solved your Queries !!!!

0
GowChotu
GowChotu

2 years ago

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

0
SELVAGANESH VENKATESAN
SELVAGANESH VENKATESAN

Reply 1 year ago

Whether Speed of the motor can be controlled ?? Because the Motor runs at full speed.. Is this possible to run the motor in different RPM ???



Did You get the Answer @GowChotu ??? Kindly Share Me if u had solved your Queries !!!!

0
SELVAGANESH VENKATESAN
SELVAGANESH VENKATESAN

Question 1 year ago on Step 4

Whether Speed of the motor can be controlled ?? Because the Motor runs at full speed.. Is this possible to run the motor in different RPM ???

0
JoshuaM112
JoshuaM112

2 years ago

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

-TIA

0
BhavinP29
BhavinP29

2 years ago

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

0
RiyaGeethz
RiyaGeethz

2 years 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
HenryC123
HenryC123

Question 2 years 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
Luck1504
Luck1504

Question 2 years 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
Farooqitj
Farooqitj

Question 2 years 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
mansoorshah
mansoorshah

2 years 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
DanielB857
DanielB857

Question 2 years ago on Step 4

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