Disconnecting from arduino pin when power turned off

I’m working on a project where I need to control the speed of a 4 pin pwm pc fan using the arduino. My problem is when I turn the arduino off I want the fan to carry on running but the fan comes to a halt. If I pull the connector from pin 3 which I’m using for the pwm signal the fan comes back on at full speed.

I’m looking for a way that I can isolate pin 3 from the fan when the arduino is not powered. I tried a diode which did isolate the fan but the pwm control failed to work with the arduino switched on.

I could use a relay but I want to keep the power draw as low as possible.

Any ideas?

It's because a shut down Arduino pulls the pin low.

Use a transistor (+ base resistor) and a pull up resistor. Base via resistor to the pin. Emitter to GND. Collector to the pin and with a pull up resistor to Vcc. Not that this will invert the speed control! But that's just a matter of smart software :slight_smile:

Thanks Septillion. I have been trying to get it to work with a transistor but so far haven't been able to get the intended result.

Sorry i'm a bit foggy on some electronics concepts, I wasn't 100% clear on your advice above. I have wired fan to the pin as follows:

Pin 3 > 47k resistor > Base
Collecter > Fan pwm input & to Vcc via 47k resistor
Emitter > GND

The transistor is a TIP122

Does that setup sound correct?

Sounds correct.

The TIP122 is massive oversize though. A simple BC547 should work as well.

Why are you disconnecting power from the Arduino but not the fan? I smell an X/Y problem.

Jiggy-Ninja:
Why are you disconnecting power from the Arduino but not the fan? I smell an X/Y problem.

I’m using the arduino to control the heating, lighting, ventilation etc in a motorhome. The fan is for the ventilation system so I want it to run 24/7 but I may turn the arduino off sometimes if I need to save power as all the electrics run off solar.

septillion:
Sounds correct.

The TIP122 is massive oversize though. A simple BC547 should work as well.

Yes I thought it was probably overkill. It was unfortunately the only transistor I could find. With it wired as described above it’s still not spinning the fan when the arduino is off, when on the fan turns on but goes up to full speed and doesn’t seem to be getting the pwm signal

grogan197:
I'm using the arduino to control the heating, lighting, ventilation etc in a motorhome. The fan is for the ventilation system so I want it to run 24/7 but I may turn the arduino off sometimes if I need to save power as all the electrics run off solar.

I had a feeling that was the case.

Get a Pro Mini and remove the LEDs. Use the 12V fan supply to power the Pro Mini's regulator. With proper use of sleep modes, you can reduce the Pro Mini's power consumption down to mere micro amps, thousands of times less than the PC fan.

That's the way to do it.

I need to use a mega2560 for the project due to the large number of inputs that are been used and fairly lengthy code. This in turn connects via bluetooth to a phone app that shows the readouts and allows for things like the fan speed to be set.

grogan197:
I'm using the arduino to control the heating, lighting, ventilation etc in a motorhome. The fan is for the ventilation system so I want it to run 24/7 but I may turn the arduino off sometimes if I need to save power as all the electrics run off solar.

Compared to fan an Arduino uses NO energy at all. The led's will take most. But if you remove them you can probably run the Arduino for days from the same battery that can only run the fan for an hour. And if you put it to sleep as well it probably lasts for weeks...

I can see the Mega useful for the amount of connections but if I where you I would not want to have one big clusterf*ck where all connections need to meet. I would go for a distributed system throughout the motorhome consisting of multiple (smaller) Arduinos.

And I'm not sure what you want the Arduino to control all but I doubt it doesn't (possibly) fit in a Uno...

grogan197:
Yes I thought it was probably overkill. It was unfortunately the only transistor I could find. With it wired as described above it's still not spinning the fan when the arduino is off, when on the fan turns on but goes up to full speed and doesn't seem to be getting the pwm signal

Did you try to invert the control? So analogWrite(x, 0) is full on. analogWrite(x, 255) is full off.

It might be you need to decrease the resistors a bit. Try 10k. Another thing you can try is to add a pull down resistor (can also be 10k) to the Arduino pin.

Right, I've managed to get it working now! :slight_smile: I Changed the resistors over to 10k's as suggested. After doing that the PWM signal was being inverted as you said but when the arduino was unplugged the fan was still coming to a halt.

I realised it must be due to the pwm cable being pulled low by the vcc pin. I added a diode between the resistor connecting from vcc to base and all is good now.

Many thanks for the advice!

Now I realise that using the mega will be using more current than I could get away with if I switched to smaller arduinos and I could probably get all the connections on a couple of unos but I then have to get them to communicate with each other and send all the info to a master to serve it out via bluetooth. All sounds like a bit of a headache so I'm going to stick with the mega. In practice it should only be needed to save power by shutting it down on the darkest of winter days but it's nice to have that option without having to turn the fan off too.

grogan197:
I realised it must be due to the pwm cable being pulled low by the vcc pin. I added a diode between the resistor connecting from vcc to base and all is good now.

Huh, resistor between base and Vcc? Never told you that :wink:

Ow, and when I wrote Vcc I of course meant a source that stays on when the Arduino is powered off, like the fan power.

Another thing to keep in mind, if you power off the Arduino you may NOT supply it any voltage on the pins. So if the Arduino gets signals from something even when it's off you need to add resistors in line.

grogan197:
Now I realise that using the mega will be using more current than I could get away with if I switched to smaller arduinos and I could probably get all the connections on a couple of unos

Mehh, havn't checked but I even think a single Mega is more power efficient. But really, I would not be concerned with the power of a 10 Arduino's compared to a single fan... Just remove the power led and maybe pot it to sleep and you can do that with tens of Arduino's an still use less then a single fan.

grogan197:
but I then have to get them to communicate with each other and send all the info to a master to serve it out via bluetooth.

True, but I would find that more then worth it if that saved me from routing tens of connections to a single point.

grogan197:
In practice it should only be needed to save power by shutting it down on the darkest of winter days but it's nice to have that option without having to turn the fan off too.

But powering down the fan would help wayyyyyyyy more.

Alright, you might want to power down bluetooth and what not. But keeping the Arduino running barely takes energy. And as a bonus you're still able to control the fan and save even more energy :wink:
[/quote]