Вы находитесь на странице: 1из 7

Controlling a 12V DC motor/fan with an Arduino

Most of the Arduino runs on 5V and driving low power actuators like LED is fine with a resistor but how do I control relays / motors / pump / fans that runs more than 5V ? I get a lot of beginner questions like below :1. How do I switch ON & OFF a 12V DC fan from an Arduino ? I was told I need a relay, what type of relay should I get ? 2. How do I control the speed of a 12V DC motor or fan from Arduino ? Let's look at these scenarios one by one so that I can explain them in more details. Firstly, even if a motor or pump or fan (anything with coils inside) is 3V or 5V, do NOT power it directly from the Arduino pins as the Arduino pins can only supply a maximum of 40mA. As per my previous article on Arduino pins, they are not designed to drive a DC motor or coils. Always use a separate power source to drive these high load components and have a relay to switch them. Question 1:How do I switch ON & OFF a 12V DC fan from an Arduino ? I was told I need a relay, what type of relay should I get ? A 12V DC fan or motor have coils inside it. You would need a relay to control it. A relay is an electrically operated switch to turn on or off a device. Most relay use an electromagnet to operate a switching mechanism mechanically. You could hear a "click" when the relay switches on when it magnetize the coil and turn on the switch. Below is an image of a 12V Single Pole Double Throw (SPDT) relay housed in a transparent casing. You can see the copper wires winding or coil clearly.

12V SPDT relay

The advantage of a relay is that they can allow high flow of current and voltage across them but the disadvantage of a relays is that it is a mechanical device with springs, so the switching speed is much slower than semiconductors ( called switching speed in the specs ) and have wear and tear of the mechanical parts. They are also more expensive to manufacture compared to semiconductors switches. Below is my sample circuit using an Arduino to drive a 12V DC Fan with a 12V relay. Arduino optoisolator 4N35 12V SPDT Relay 12V PC fan

4N35 optoisolator

An optoisolator is a chip that combined two circuits ( a LED & NPN phototransistor ) into an integrated circuit to isolate two different voltage. The Arduino is on 5V and the relay & DC fan is on 12V. According to the 4N35 datasheets, it can support up to 70V from pin 4 to 5. See the circuit diagram below :-

Arduino 4N35 12V Relay

When pin 12 is turn ON or HIGH, it will triggered the LED between pin 1 & 2 inside the 4N35 optoisolator (6 pins white chip) to turn on the phototransistor ( pin 4 & 5) and complete the circuit and send 12V power into the relay (black colour). When the coil is energize, you will hear a click and switch on the motor. The red wires are connected to 12V power supply. Using this method, it can only switch on or off a circuit but could not control the variable speed of the motor. A second method will use a semiconductor, NPN Power Transistor model TIP122 to control the speed of the DC motor using PWM from pin 9. On Part 2 of the article, I will explain on how to control the speed of a 12V DC fan using PWM.

1.

Hi stan001,

Firstly, an excellent tutorial! I just received my Arduino Uno yesterday, so forgive me for the dumb questions (to follow) as I'm very new to this. I would like to do something similar to what you have done in this tutorial. Instead of triggering a 12V DC fan, would like to trigger a 12V DC strike plate lock (for a security gate). I presume that what you have done in this tutorial will suite my needs perfectly, simply by swapping out the fan for the lock? Can you perhaps re-upload the enlarged image of your diagram, the current image is of low quality and it's difficult to see. -Regards, William. Reply 2. stan001Apr 2, 2011 08:35 PM Hi, Pls post the questions to the facebook group on the Useful Links above, there are project pictures and more interactions compared to this comments notes... Reply 3. 1ofakindworkJul 29, 2011 05:12 PM

How would I control a DC motor with a real time clock. I would like to have preset times to operate the motor. Then I would like to preset a time to reverse polarity and run the motor in the opposite direction. Thank you Jeffrey. Reply 4. ScottInNHNov 8, 2011 04:38 AM Hi. Please correct your Arduino pin power statement - your decimal point is off. This text should say "Arduino pins can only supply a maximum of 40mA or 0.04 Amp". Reply 5. AnonymousNov 14, 2011 10:41 AM >>Arduino pins can only supply a maximum of 40mA or 0.4 Amp This is a rather old blog entry but I thought you'd want to fix this line anyways. 40mA is 0.04A, not 0.4A :) Reply 6. AnonymousNov 18, 2011 09:32 PM new to this topic i did not realize that there's a chip for this. i was using my IR emitter detector diode. but it was giving too weak output. i could light a small led but not a 6v motor. even though the battery was 6v. big thanks for the tip Reply 7. AnonymousDec 10, 2011 02:13 PM thanks! Reply 8.

KaseDec 12, 2011 12:45 AM Hi there? I am also new to this! But since the opto-isolator can stand high voltage (upto 70V) if we for ex. need to switch ON or OFF something wich is already have its own 12 V supply ( you can imagine any 12 V circuit with LED as load but somewhere a open switch with we can then feed into Emitter and Collector of Opto-isolator accordingly.) So can we just use Opto-isolator as a switch ON or OFF if required? (I am sorry I am not good in explaining hopefully you understood what I mean.) In facts I want to use arduino to do nothing more than switching ON and OFF a certain Switch which hence completes (closes) a certain circuit. will this right? Thanks. Reply 9. stan001Jan 1, 2012 01:51 PM @ScottInNH, thanks, error corrected. Reply 10. stan001Jan 1, 2012 02:04 PM @Kase, if you just wanted to switch ON / OFF something on a 12V, NO, it does not work as the current passing thru the optoisolator (pin 4 & 5) might be too HIGH for the transistors inside to handle. From the 4n35 datasheets, the collector max current is only 100mA. Reply 11. stan001Jan 1, 2012 02:20 PM @jeffery, yes, you can control the fan speed by the time of the day. If you would also like to reverse the polarity, you would also need a H-bridge to do that. Reply

12. AnonymousJan 21, 2012 08:27 AM hello.. I just wanted to know if you could help with the process to make the circuit for a line bot.. i mean a detailed explanation as to how to connect the Dc motors, relay, pot and everything? :) Reply 13. stan001Jan 25, 2012 12:07 PM Pls post yr questions on my fb group page... Reply 14. luisFeb 7, 2012 03:36 PM hello im trying to conect a 12v pump but i dont get how to connect the relay ? in the foto wich one is the collector, emitter, etc. heres the code im using: /* * Trigger a relay */

int pumpPin = 12; // relay unsigned long time; unsigned long lastPumpTime; int pumpPeriodHours = 6; // hours between pumps int pumpPeriodSec; // seconds between pumps int pumpDurationSec = 10; // seconds the pump is running int statusPeriod = 5000; // ms time between status blinks-- to let you know it's alive void setup() {

pinMode(pumpPin, OUTPUT); digitalWrite(pumpPin, LOW); pumpPeriodSec =30; //pumpPeriodHours * 60 * 60; // seconds between pump starts //pumpPeriodSec = 30; // for setting short periods when testing } void loop(){ lastPumpTime = millis(); // Activate the pump digitalWrite(pumpPin, HIGH); delay((pumpDurationSec*1000)); digitalWrite(pumpPin, LOW); } Reply

Вам также может понравиться