I am working on a project where I need to control a 12V DC motor using an NPN transistor via the PCF8575 I2C GPIO expander.
The problem I'm encountering is that when I power up the device, the PCF8575 default pin states are high. As a result, the motor is unintentionally activated until I send the 0x00 I2C command to set the outputs low. This causes the motor to run for a short period of time before I manually disable it.
Possible Solutions that i think can work:
Set PCF8575 Outputs Low by Default:
-Is it possible to configure the PCF8575 to default to low outputs on startup?
Inverted Logic for Transistor: Another idea I’m considering is to configure the system so that the transistor is activated when the PCF8575 output is low and deactivated when the output is high (inverted logic).
Which of these approaches do you think is the best solution, considering the need for simplicity and minimizing extra components?
Not according to the data sheet. However, the data sheet says this:
At power on, the I/Os are high. In this mode, only a current source (IOH) to VCC is active. An additional strong pullup to VCC (IOHT) allows fast-rising edges into heavily loaded outputs.
IOH is in the range of 30 to 300 uA, and IOHT is a transient of up to 1 mA, so you may be able to configure the transistor bias such that it does not turn on with that minimal base current.
There may be a better choice of I/O expander. The MCP23017 I/O pins default to input on power up, for example.
For a better informed discussion, post a schematic of your circuit.
You can use a logic inverter, such as an HC04. With this setup, a high signal will turn the motor off, and a low signal will turn it on. This approach is less hassle than wiring an additional transistor.
Alternatively, you can replace the transistor with an N-channel MOSFET. If the MOSFET is not avalanche-rated, you will need to add a flyback diode across the motor to protect the circuit from voltage spikes.
It would be easier to activate a pnp transistor on low...
You might need an additional npn to reverse logic again (to get the reverse of reverse).
Or you can change the logic in software.
Additional plus of pnp is that the load can be connected to output and gnd.
The mosfet approach given above will do the same, but with (slightly) lower losses...
When driving a motor with an npn transistor, you need to minimise the voltage drop and heat generated in the transistor and maximise the voltage available to the motor. This means needing to saturate the base of the npn with around 1/10th as much current as the motor draws when running. PCF8575 pins cannot provide (source) enough current for that. For example if the motor draws 200mA when running, you need to sink around 20mA into the npn base. Add already pointed out, the PCF8575 can supply only 300uA which is 100x too little.
Can you drive the transistor directly from an Arduino pin instead of the PCF8574? If you have no free Arduino pins, could you free up an Arduino pin by using a PCF pin for that purpose? Some pin that does not need to source a large current. For example driving an LED by wiring it to sink current into the PCF pin. PCF pins can sink much larger currents, I think 20mA, than they can source.
Not really, it has a current source that act like a pull-up. If you try to pull it down, you may exceed the pin current limit, plus you can't pull it back up
All you need are two MOSFETs or two transistors to fix the problem.
That's a Darlington npn, which means that in fact it is two npn transistors in a single package. These have advantage of much higher gain, so you won't need to source 1/10th of the motor current into its base, maybe only 1/100th. But if the motor draws 3A, that base current will still need to be 30mA, which is 100x more than the PCF8575 pins can source.
The disadvantage of Darlingtons is that they have a very high voltage drop. Probably around 1.5V. with 3A current flowing through it, it will need to dissipate around 4.5W of heat and will need a large heatsink.
A MOSFET would have a much lower voltage drop. If you choose the model of MOSFET carefully, it's resistance (Rds-on) would be less than a hundred milliohms, and it's power dissipation will be less than 1W.
But as @jim-p said, you still have the problem that your PCF chip defaults to HIGH output, switching the MOSFET on at startup.