Transistor as a 3.3v switch - EE consult

Hi all-

I’m using the Photon as the brain of a cat box monitor, and part of that is photon-controlled timing of an automatic air freshener.

Out of the box, the air freshener runs on 2xAA batteries, and I have hacked out and re-routed those wires to the 3.3v output of the Photon, and it works great - problem being, in order to sell some additional refills, the air freshener allows a maximum “spritz” gap of 36 minutes. I want to completely control when it goes off, so as to avoid macing my cat inadvertently. So, a continuous supply of power is no good.

Upon being powered up, the air freshener unit does a spritz, so applying power to it for just long enough to do that will allow me to have full control of when it goes off, which, when paired with the motion sensor, will make sure kitty has plenty of time to get away before the Hawaiian Breeze descends.

I wired up an NPN transistor to D2 with a 1k ohm resistor, based on what I found around the web as a “poor man’s relay,” and nothing happened. I stepped it down to 330, nothing happened, I stepped it down to 220, nothing happened. Finally, I said screw it and just ran naked wire from D2 to the base pin on the transistor…and it worked perfectly.

Like so:

(please note it is not actually a DC motor, it seems to be a very simple little servo connected to a timer IC in the air freshener, but Frizting’s library has limits)

In operation, what happens is that certain events trigger D2 HIGH for about 8 seconds, and using millis() to check that it’s been 8 seconds, it is then set LOW. So, this transistor is opening the 3.3v pin to this load for about 8 seconds at a time, every so often: when a qualifying motion event has occurred, or I hit the button on my phone.

This works amazingly well, and that makes me distrust it.

I’ve built a voltage divider on a 5v power rail separate from the photon, but the 30ma that is is generating is insufficient to activate the air freshener. It’s been working without causing any magic smoke on the 3.3v rail that maxes out at 100ma. Beyond that range of 30-100ma, I am unsure of the exact current draw of the air freshener because it is a very short spike and I don’t have complex signal analysis tools.

My actual question:

Assuming that the load is less than 100ma, as I haven’t smoked anything yet in using it, is it a dangerous scenario to continue to run it as depicted in the above diagram?

(NOTE: it is not actually installed in the cat’s box yet, it’s still a prototype on a bench. Like I said, I distrust it.)

The transistor’s rated to 500ma, so the Photon should die before it…right?

I’ve already begun working up a plan to completely separate the air freshener’s power rail from the Photon, so that the data pin to the transistor is more like an isolated relay. However, the voltage regulator I want to use won’t arrive til after the holidays, and I don’t seem to have the right resistors on hand to build a quickie voltage divider, so I figured I would consult the sage electrical engineers on this forum to let me know what my risk level would be in leaving things as is.

It’s working great, and it’s such a nice, compact little footprint if I just run it all through the Photon’s 3.3v out…

Doesn’t seem like an issue to me though a resistor from the Base to the GPIO would be good. :slight_smile:

@patrickcentral, besides the base current limiting resistor, you need to add a flyback diode across the motor since it is an inductive load. Adding a current limiting resistor from 3V3 to the motor may bear good idea as well to protect the photon regulator.

1 Like

Closing the loop on this for anyone else who may be trying something similar -

I never had any problems with using the pictured configuration - ran like a champ, actually.

In an abundance of caution, as I was packing this project up for a real run in the cat box, I decided to run an isolated separate power rail to supply the 3.3v to the air freshener, and so the base pin will be the only thing connected to the Photon, and will simply act as a relay. 4 bucks on Adafruit is worth the peace of mind :smile: