Skylarker
Posts: 6
Joined: Tue Oct 12, 2021 5:42 pm

Interfacing with inline fan.

Tue Oct 12, 2021 5:53 pm

Hello!

I'm trying to figure out how I might hook up this inline fan for a seed starting room on my family farm. Preferably a pico, but a pi would be ok too, as both will be in the room.

I have 2 motor controllers I might be able to use, just trying to figure out how.

Here is the motor control wire diagram they gave.
Screenshot_20211012-134858.png
Screenshot_20211012-134858.png (76.02 KiB) Viewed 407 times
I think the code shouldn't be too bad, it's just how to wire it up, if possible. Thank you!

pcmanbob
Posts: 11790
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Interfacing with inline fan.

Wed Oct 13, 2021 7:12 pm

As your fan appears to have a speed controller already built in all you need to do is build the speed control via pwm circuit shown bottom left of the 4 circuits and drive the base of the transistor from one of the pi / Pico gpio pins.

If you need component values suggesting then please ask.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Skylarker
Posts: 6
Joined: Tue Oct 12, 2021 5:42 pm

Re: Interfacing with inline fan.

Wed Oct 13, 2021 9:01 pm

pcmanbob wrote:
Wed Oct 13, 2021 7:12 pm
As your fan appears to have a speed controller already built in all you need to do is build the speed control via pwm circuit shown bottom left of the 4 circuits and drive the base of the transistor from one of the pi / Pico gpio pins.

If you need component values suggesting then please ask.

Thank you! Yes, which components to use would be helpful. I have a few h-bridge motor controllers, but not sure how I'd wire that.

Alternatively, I have a pack of IRLZ34N MOSFETs laying around for an LED project.

If I understand, I would connect GND and +10V respectively, then put the signal pin on a PWM of the pico and write a code to match what I want?

pcmanbob
Posts: 11790
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Interfacing with inline fan.

Wed Oct 13, 2021 10:34 pm

I assume the fan needs 10V to power it , but the information supplied does not mention that specifically only implies it from the wiring connected to the plug as shown.

So the PWM will also need to be 10V based so you need to use the bottom left driver circuit of the 4 shown, as my first post suggested.

This would look like this when connected to as pi, using the suggested components / component values.

Edit..

Having looked at the limited information provided yet again I think this is a mains AC powered fan and all the wiring on the plug is related to speed control only so the diagram for speed control should look like this.

Image

Noting that the pwm signal outputted by the pi will be inverted at the fan, due to the circuit layout suggested by the manufacture.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Skylarker
Posts: 6
Joined: Tue Oct 12, 2021 5:42 pm

Re: Interfacing with inline fan.

Thu Oct 14, 2021 3:32 pm

pcmanbob wrote:
Wed Oct 13, 2021 10:34 pm
I assume the fan needs 10V to power it , but the information supplied does not mention that specifically only implies it from the wiring connected to the plug as shown.

So the PWM will also need to be 10V based so you need to use the bottom left driver circuit of the 4 shown, as my first post suggested.

This would look like this when connected to as pi, using the suggested components / component values.

Edit..

Having looked at the limited information provided yet again I think this is a mains AC powered fan and all the wiring on the plug is related to speed control only so the diagram for speed control should look like this.

Image

Noting that the pwm signal outputted by the pi will be inverted at the fan, due to the circuit layout suggested by the manufacture.
This is a little outside my comfort zone so I appreciate your patience.

I found a few BC547B's it looks like I could use in place of the 2N transistors. All I have on hand for diodes are IN4742A, could I use those?

Also, as per the online instructions I screenshot above, if I connect the blue and the red, the fan turns on. The yellow and GND aren't used when regulating the PWM it appears to me, so it seems I just need something in between the two to to regulate speed, or a simple relay maybe for on/off function controlled by pico or pi.

For my application that would suffice though I would like variable speed. Basically all I really *need* it to do is cut on if it gets to hot, ifelse, run for a few minutes every hour or two for fresh air exchange. So while it would be nice, variable speed isn't critical at this point.

pcmanbob
Posts: 11790
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Interfacing with inline fan.

Thu Oct 14, 2021 6:56 pm

Any general purpose NPN transistor should be fine, but you may need to change the base resistor.

Your diode will not do you need a zener diode with the part no. I suggested.

You need to build the circuit shown to use pwm speed control , if you just want on off then a relay switching a connection between red and blue will work.

Anything else may simply not work or damage the fan speed controller or you pi/pico.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Skylarker
Posts: 6
Joined: Tue Oct 12, 2021 5:42 pm

Re: Interfacing with inline fan.

Sun Oct 17, 2021 2:43 pm

pcmanbob wrote:
Thu Oct 14, 2021 6:56 pm
Any general purpose NPN transistor should be fine, but you may need to change the base resistor.

Your diode will not do you need a zener diode with the part no. I suggested.

You need to build the circuit shown to use pwm speed control , if you just want on off then a relay switching a connection between red and blue will work.

Anything else may simply not work or damage the fan speed controller or you pi/pico.

Thank you yet again. I should get the appropriate diode in the post today and should be able to finish this.

This was a good excercise for me to learn more about circuitry. The one thing I do not understand is the need for the diode in the first place. I know what a diode does, just not why it's needed here. According to the paper, and my experiments, you can just tape the GND, BLUE and RED together and it will stay on. The pico is only going to send 3.3v to this 10v system. I guess I'm just not sure why a diode is needed here.

pcmanbob
Posts: 11790
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Interfacing with inline fan.

Sun Oct 17, 2021 3:02 pm

So the zener diode is just there to limit the the voltage that an be applied to the PWM input/blue wire, not sure why the manufacture would include it seeing as the red wire is a 10V output,

But I guess you could be using a separate supply to power the PWM or may be the Red wire /10V is a nominal voltage that could be higher than 10V.

Regarding connecting the red/blue and ground wires , you should NOT be connecting all 3 together.

Red and Blue is fine that will just run your fan at full speed.

Blue and Black/ground is ok because the will just cause your to stop, same as using the speed control via a POT and setting it to minimum speed.

However you should NOT be connecting black/ground to Red that is shorting the 10V output to ground and will damage your fan speed control.

The pi/pico is not putting any voltage in to the fan , it is only turning on the 2N2222 transistor which allows the 10V to flow to ground, and so when you apply the PWM signal to the transistor you are applying a 10V PWM voltage to the fan and controlling its speed.

You are effectively using the PWM to control the fan in the same way as the example using the POT.

I suggest you read up on how a transistor works...
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Skylarker
Posts: 6
Joined: Tue Oct 12, 2021 5:42 pm

Re: Interfacing with inline fan.

Wed Oct 20, 2021 4:51 pm

pcmanbob wrote:
Sun Oct 17, 2021 3:02 pm
So the zener diode is just there to limit the the voltage that an be applied to the PWM input/blue wire, not sure why the manufacture would include it seeing as the red wire is a 10V output,

....

The pi/pico is not putting any voltage in to the fan , it is only turning on the 2N2222 transistor which allows the 10V to flow to ground, and so when you apply the PWM signal to the transistor you are applying a 10V PWM voltage to the fan and controlling its speed.

You are effectively using the PWM to control the fan in the same way as the example using the POT.

I suggest you read up on how a transistor works...
I got it to work! I'm still learning the circuit diagrams, and it took one burned transistor but I got it!

I still find it puzzling how red and blue can be connected to the same leg of the transistor and not cut on! But it works! I also find it odd that the fan cuts off when pin is HIGH (1) and on when pin is LOW(0)

I am able to cut if off and on through the shell on my raspberry and Thonnny. I am having trouble trying to figure out the proper syntax to get the main.py program. I first just want to cut it off/on when the temp gets outside range.

Here is my code. Please excuse all the delays that are #'d out, i was using 2 different DHT sensors and they were wonky to get to work without delays in certain areas. I recently got a few SHT types so that temperature code is going to swap out to work with those.

Code: Select all

import machine
from machine import Pin, I2C

import os
import sys
from ssd1306 import SSD1306_I2C
import utime as time
from dht import DHT11, InvalidChecksum
 
WIDTH  = 128                                            # oled display width
HEIGHT = 64                                             # oled display height
 
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=200000)       # Init I2C using pins GP8 & GP9 (default I2C0 pins)
print("I2C Address      : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c))                   # Display I2C config
#time.sleep(2)
fan = Pin(15, machine.Pin.OUT)
 
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)                  # Init oled display
while True:
    #time.sleep(1)
    pin = Pin(2, Pin.OUT, Pin.PULL_DOWN)
    sensor = DHT11(pin)
    time.sleep(2) #forsensorwithredlight
    t  = (sensor.temperature)
    h = (sensor.humidity)
    #time.sleep(1)
    print("Temperature: {}".format(sensor.temperature))
    print("Humidity: {}".format(sensor.humidity))
    tf = (sensor.temperature) *1.8 + 32
    #fan.value(1)  ###      <-fan will react if i change this!
if (tf)>95
    fan.value(0)   ###        <-this is where i get an "invalid syntax" error (line 33)
    #else
    #fan.value(1)
    # Clear the oled display in case it has junk on it.
    oled.fill(0)       
    # Add some text
    oled.text("C.A.T.H.E.I.", 11, 1)
    oled.text("Temp: ",1,20)
    oled.text(str(tf),50,20)
    oled.text("*F",90,20)
    
    oled.text("RH: ",1,37)
    oled.text(str(sensor.humidity),50,37)
    oled.text("%",90,37)

    time.sleep(1)
    oled.show()

Invalid syntax line 33

If i can get it off and on based on the temperature, i can probably then handle learning to control its speed via pwm.

pcmanbob
Posts: 11790
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Interfacing with inline fan.

Wed Oct 20, 2021 7:08 pm

I will try and explain simply how the circuit works.

First off lets remember that if you apply 10v to the blue wire the fan runs, if you apply 0V to the blue wire the fan stops, so with that in mind and looking at the diagram.

Image

So if the pi is outputting a low on gpio 8 then the transistor is turn off, so the 10V will be connected to the blue wire via the resistor, in reality it will be slightly less than 10V because there will be a very small current flowing due to the high resistance of the input on the blue wire and the 1.1K of the resistor , so the will be a very small volt drop across the resistor, so the fan runs. ( blue line )

Now lets consider what happens when the pi is outputting a high, this causes the transistor to switch on, so now we have the blue wire and the bottom of the resistor connected directly to ground via the transistor.

Now because current will take the path of least resistance and as I have already stated the blue wire will have a high input resistance, the current will flow through the 1.1K resistor and directly to the ground, so the entire voltage will be dropped across the 1.1K resistor at a current of about 8mA , so this means that the bottom of the resistor and the blue wire will be at zero volts so the fan will switch off. ( red line )

So as I originally said the output of the circuit is the inverse of the input,

so to turn the fan on you apply a low output from the pi gpio to the transistor base,
to turn the fan off you apply a high output from the pi gpio to the transistor base.

You look to be using a pico and micro python so it looks like you are missing the colon from the end of the if statement.

Code: Select all

if (tf)>95: <<<<<<<<<< added colon
    fan.value(0)
    
As you are using a pico I cant offer any example code.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Skylarker
Posts: 6
Joined: Tue Oct 12, 2021 5:42 pm

Re: Interfacing with inline fan.

Wed Oct 20, 2021 7:49 pm

Update, i was able to get it working after adding the following 5 lines to the bottom of the code. I had tried it before but silly me forgot the colon at the end of the first line.


Code: Select all

 if tf > 95:
        fan.value(0)
    else:
        fan.value(1)
    time.sleep(1)

Return to “Automation, sensing and robotics”