Jump to content

Ken Jancef, Here is a writeup I did for controlling the fan using an Arduino and PWM


G+_David Peach
 Share

Recommended Posts

Ken Jancef, Here is a writeup I did for controlling the fan using an Arduino and PWM. Hopefully that will get you started. I was away from home and all my toys last week when we were talking about this, but after getting home yesterday I had to jump in and solve the problem even if just for myself.

 

Forgive any schematic errors, they didn't teach us this stuff in Bible college.

 

http://www.mythoughtspot.com/2017/06/20/controlling-a-fan-using-pwm-and-arduino/

http://www.mythoughtspot.com/2017/06/20/controlling-a-fan-using-pwm-and-arduino/

Link to comment
Share on other sites

Read the post first. I wrote it with the 12V issue in mind. I was actually running the fan in the video from 9V.

 

Your biggest concern is pushing too much amperage through the Arduino. You can power the Arduino from 12V and just use 1 power supply for everything, but having a separate power supply isn't that hard and eliminates the possibility of cooking the Arduino.

 

However, if someone wants to jump in and give us the safe numbers for powering the fan and Arduino (and the process for doing so) from a single 12V supply, I am all for it.

Link to comment
Share on other sites

I did read it, albeit a little quick since it's getting late. It's starting to make sense, but I have no knowledge whatsoever about wiring electronics and reading schematics. Your post is making it clear. I'll read it in detail at work tomorrow. I know I will want to add the temp sensor, but this is an awesome start!!

Link to comment
Share on other sites

The Instructable and Adafruit links will shed even more light on it all. When I did a similar project a few months ago (controlling 12V RGB LED strips with PWM), I finally started understanding transistors as switches.

 

Play with it and it might finally make sense.

Link to comment
Share on other sites

Yes you can, and must, power it separately in the linked project. That is what he is doing too. He shows a 9V battery powering his fan in the Fritzing sketch. In his video it looks like he is only using 7.2 V which is why he had to give it a little push to get it started.

 

The IC takes the place of my transistor, resistor, diode setup. But it is working in the same manner.

 

Good luck on this. It is nice that he has given a way to control based on temperature. It is your situation exactly.

Link to comment
Share on other sites

Oh, ok. So I can feed the Arduino the power it needs (9V I think..), and feed 12V to the board for the fan..? Going to order the parts tomorrow. I'll let you know how I make out...

 

By the way... even though I like to have a wiring diagram to look at, I still like to learn about where things go and why... your post was the ONLY one I read that made me understand it. Much appreciated... :)

Link to comment
Share on other sites

You're welcome. Glad it was helpful.

 

You can see in the video that he is using two power sources. He has the battery which is only powering the fan. The Arduino is plugged into USB and getting it's power that way. He doesn't show the Arduino's power source in the wiring diagram picture, but it is not using the 9V battery. Only the fan is getting power from the battery. His video makes that clearer.

 

As far as the power requirements for the Arduino Uno, it takes either power from USB (which is 5V), or it will take power through the barrel jack. The barrel jack can take anything from 5V up to 20V (I think), but ideally it is recommended 7V to 12V.

Link to comment
Share on other sites

David Peach About your schematic.. is that an NPN or PNP transistor, and what's with D1. I'm accustomed to seeing diodes for draining induced current when de-energizing a relay, but on a low-current circuit like for your fan, I don't see the point. What am I missing?

 

Yes, one can infer transistor type from the schematic. For the n00bs, y'all. Everyone else can fend for themselves.

Link to comment
Share on other sites

Jason Marsh, you are correct, I did not say whether it was an NPN or PNP. It is an NPN Darlington transistor. You can find out more about it by searching for "datasheet TIP122."

 

From the article about why to use the diode: "Between the collector and emitter we also insert a diode. This prevents the spinning of the fan (or DC motor) from pushing power back through the transistor and blowing up the Arduino. A DC motor (which a fan is) generates electricity when spinning but does not have outside power pushing it. So when the Arduino stops sending a signal to the fan the fan will spin down and in the process create a small DC voltage. In this case it is probably not enough to matter, but it is a good habit to put a diode in place to stop the newly created voltage from traveling backwards into the Arduino. As you probably know, a diode only allows the electricity to travel one direction. We want power to travel from the Arduino to the fan but not the other direction."

 

So, it is probably not necessary, but a nice habit when working with motors. (So I have been told. I am not a trained professional.)

Link to comment
Share on other sites

Ken Jancef??, I think this will require some testing. Since your fan already has PWM brains built in, it may or may not work with this setup. To control yours with the built in PWM abilities, from what I have read, you will need a 25 kHz signal on the fan's PWM line. The Arduino does not provide that. You will have to use a library or write some special timing function to make it work.

 

What I would do is try your fan as if it were a two-wire fan. If using my circuit: hook your positive straight to the 12 V + power supply and the ground to the collector. If using the other circuit: connect the ground and + of your fan (you should be able to Google the pinout of your fan) into pins 3 and 6 of the IC. Should not matter which is which, but your fan may soon backwards. See it works.

 

Or, get a simpler fan. I have a dozen or two sitting in a junk box that I rip out of old computers people can't seem to stop giving me.

Link to comment
Share on other sites

David Peach Ok... another question on this... so I got it all wired up and in my enclosure, but the problem I'm having is that when the temp gets to 30c, the fan is supposed to spin at 30%. But the fan doesn't start spinning. If I flick the blades with my finger it starts. It seems the fan may not be getting enough power? I'm feeding 12v to that breadboard. And the fan is a 4-wire fan... could that be the issue, as you said earlier there might be? The + is in Pin 6, the - is Pin 3. I tested it putting a soldering iron near the temp sensor. If I flip the + - it doesn't work at all...

Link to comment
Share on other sites

Ken Jancef, try this: add spinning the fan up to 100% for 1 second and then let it drop down to 30%. That should get it started and then the PWM pulses after that should work as expected.

 

You may have to do a quick spin up for anything below a certain % to get it started. I would think anything above 75% should start OK on its own. You can test and see how low you can go to get it started or just add the 1 second (maybe less) of full power at the beginning of any percentage < 75 when starting from 0%.

 

(This is fun, me theorizing and having someone else put in the effort to see if my theories work.)

Link to comment
Share on other sites

In this example, "Enable" is Pin 5 on the Arduino, going into Pin 1 on the L293D chip

 

So here is a snippet of the code... could I do an addition of:

 

"analogWrite(Enable, 255)"

 

before the line "analogWrite(Enable, 77)" in the below example? Will the fan speed drop from the 255 (full power) to 77 (30% power)?

 

 

if(temp <30 ) { // If the temperature less than 30

analogWrite(Enable,0); // 0% PWM duty cycle

lcd.print("Fan OFF ");

delay(100);

}

else if(temp>=30 & temp<32) { // If the temperature is between 30 & 32

analogWrite(Enable, 77); // 30% of maximum duty cycle value (255).

lcd.print("Fan Speed: 30% ");

delay(100);

 

and on and on....

Link to comment
Share on other sites

I am not an expert on this, but I would try (starting at your else if):

else if(temp>=30 & temp<32) {

analogWrite(Enable, 255);

delay(1000);

analogWrite(Enable, 77);

lcd.print("Fan Speed: 30% ");

delay(100);

 

I think that should spin your fan up to 100% for 1 second (you may not need that long) before it goes back to checking the temperature every 1/10 th of a second.

Link to comment
Share on other sites

 Share

×
×
  • Create New...