Controlling fan speed with Photon and FET transistor

So, this is what I have come up with so far:

Even though the schematic looks somewhat right, the breadboard sketch looks off to me. I followed the guide lines generated in Fritzing when I did the schematic sketch to place the jumpers on the BB.

And I’m still not sure about the red and blue rails.

This schematic is the best so far, IMHO. I can’t speak to the breadboard layout, since I don’t use fritzing, and am not a huge fan of breadboards in general.

How about this?


That looks more like it!

Thank you so much, really appreciate it.

So, the components I’ll need:
1 Diode 1N4148
1 Capacitor 10uF/50V
2 Resistor 120ohm
2 Resistor 100ohm (The shop I’m thinking of buying from does not have 220ohm)
1 FOD817B DIP-4 Optocoupler
1 N-Channel MOSFET 60V 30A
DC Barrel jack
12V axial fan
Wires
Breadboard

My last question is how I best can cram all this into a casing.
Im thinking something in the range of 120 to 150mm x 100 to 120mm.
Why casing? This is going to be a magnetic stir plate when it’s ready.
I feel that a bread board will have a hard time fitting in a casing like that.

The breadboards that come with the Particle kits are 80x55mm, and there are even smaller ones available.
You also might want to get medium (insertion) force breadboards if you intend to move components from time to time.
If they have no 220Ohm resistors you should also be OK with 330Ohm.
https://docs.particle.io/datasheets/kits/#photon-kit

I’ve gathered most of the materials I need.

The last thing I’m trying to come to an conclusion about is how to drive both the Particle and the fan with the same power source.

Say I connect a 12V DC adapter to the breadboard. Could I leech 5V power from that? Maybe by using one of these, or similar? https://www.conrad.se/?websale8=conrad-swe&pi=157954&rdeocl=1&rdetpl=desktop_productpage&rdebox=box1

How could I connect a USB cable to that?

@TripleJr, you can absolutely use that buck regulator (in fact, I have)! I suggest you power the Photon via the Vin pin instead of the USB connector. Make sure you add a 0.1uF decoupling capacitor between the Vin pin and GND. :wink:

1 Like

Ok, first try kind of failed.

It would not spin at all.

So, I tried bypassing the MOSFET directly to the opto coupler. That somewhat failed too.
I could get the fan to spin really slowly if I helped it start. When I put the fan directly to the power source it worked as expected though.

My DC adapter is rated at 300mA at 12V and the fan at 140mA.

Where’s the problem? :confused:

This thread looks interesting … Any luck so far ?

Just got it working as of yesterday evening!

The only problem is that the fan makes a beeping sound in lower RPMs, but that’s not something that concerns me much. Next step or an upgrade would be swapping it for some kind of brushless motor.

Thanks for the help everyone!

Hi @TripleJr,

I’m also trying the same thing but for ceiling fan AC 220V. I just saw your post. :blush: Can you please share the final schematic with their CODE ?

My schematic is:

@mohitagnihotri, @Omer’s fan is DC whereas your ceiling fan uses AC so the circuits will be vastly different. His design can’t be applied to your fan.

Hi @peekay123,

Thank you for telling me. I want to control AC fan speed. I found many post related with fan speed in the community but didn’t find any working solution for me.

Can you please guide me here? I did following thing but it is not working ultimately. Can you find, why is it not working?

My schematic is

My code is

//Code is based on 220V 50Hz AC

int AC_LOAD = A4;   // Output to Opto Triac pin
int dimming = 128;  // Dimming level (0-128)  0 = ON, 128 = OFF

void setup()
{
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(A4, zero_crosss_int, RISING);  // Choose the zero cross interrupt # from the table above
}

//the interrupt function must take no parameters and return nothing
void zero_crosss_int()  //function to be fired at the zero crossing to dim the light
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

  int dimtime = (75*dimming);       
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay 
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
    for (int i=5; i <= 128; i++){
    dimming=i;
    delay(10);
   }  
}

Thanks!

@mohitagnihotri, the code is not working because your hardware does not match the code! The code is expecting a zero-crossing signal which generates an interrupt. Your circuit does not have that zero-crossing detector. Did you find the code in this forum? What about the circuit?

You may want, for the sake of safety and simplicity, to look at this board on Tindie:

https://www.tindie.com/products/bugrovs2012/1ch-ac-dimmer-module-controller-board/?pt=full_prod_search

It will do exactly what you want, is compatible with the Photon and the code is essentially idential to the one you posted. :wink:

Hi @peekay123, Thank you so much :smile:

I found the code and schematic from here: http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/?ALLSTEPS

I think, if I would choose the following the circuit then it should work. Is it compatible with the Photon and their code too?

@mohitagnihotri, yes the circuit will work and the code will also with minor modifications. I caution you that working with 220V can be fatal if not done properly.

@peekay123, thanks again. Definitely, I’ll do with proper attention.
I’ll notify you here, if I succeed.

I'm going to second that. If you're not comfortable with working with mains, then please, do not attempt to DIY it. It may cost you more than you bargained for, and that's just not worth it.
Unless you can guarantee proper and safe practice around working with mains, hire a professional. Mains is not something to be messed with and will kill you if handled improperly.
Depending on where you're located you might also be subjected to a variety of regulations prohibiting you from tampering with mains unless certified. If you fail to meet these, you may get fines, and insurances might not cover you in case of accidents.
Thread carefully.

1 Like

@peekay123 I did it :smile: Thank you so much!

Now, it is working with Fan and Bulb both.

Check here: https://goo.gl/MMBp7f

2 Likes

I am also working on similar thing. do you mind sharing the final circuit and code?

Thank you