Bipolar Junctional Transistor (BJT) Latching Pushbutton On/Off Circuit

by JD_K in Circuits > Electronics

3346 Views, 17 Favorites, 0 Comments

Bipolar Junctional Transistor (BJT) Latching Pushbutton On/Off Circuit

20221231_104138.jpg

I have need of a ON/OFF circuit for a future project. That project will be battery-operated and use an Atmega328 microcontroller, a BME280 environmental sensor and a liquid crystal display (LCD) to show the results. The device will be used by people who are not so familiar with the device, so the operation should be simple, and I want it to turn off automatically after one minute to save power (they forget to turn things off). I will add the option for a subsequent press of the button to turn off the device to further save power. (If you are curious, my plan is to use two AAA batteries and add an inexpensive boost converter to boost the voltage to 3.3 volts which is rated voltage of the BME280.)

In a previous project I made a push-button on/off circuit using MOSFETs, which would work but MOSFETs are overkill. Therefore, in this Instructable I will show my prototype push-button on/off circuit with two BJT transistors, which is reminiscent of the MOSFET circuit. This Instructable is focused on the BJT circuit to keep it simple, but ultimately will use a microcontroller to latch it. I will include some Arduino code below if you want to try it.

Supplies

  • PNP BJT x1 (I used 2N4126)
  • NPN BJT x1 (I used 2N2222A)
  • Tactile push button x1
  • Rectifier diode x1 (I used IN7001)
  • Schottky diode x1 (I used 1N5819)
  • 10 kOhm resistor x2
  • 1 kOhm resistor x3
  • AAA batteries x2 and a battery holder
  • Half-sized solderless breadboard and wires
  • For demonstration purposes for this Instructable: 220 Ohm resistor and single LED
  • Microcontroller if you want it to actually latch the circuit

Originally for this circuit I used two rectifier diodes which worked fine with the LED. However, in the final project (Atmega328, BME280, LCD etc., not shown here), the push-button-off functionality did not work. The microcontroller could not detect the button being pressed. After changing one diode to a Schottky diode, it worked reliably. Schottky diodes affect voltage to a lesser degree than regular rectifier diodes. I have one Schottky diode in this Instructable, but depending on what you are doing, two rectifier diodes might work just fine.

Bipolar Junctional Transistors

BJTs 2N2222a 2N4126png.png
NPN transistor_bb.png
PNP Transistor_bb.png

There are many descriptions on the internet of what BJTs are made out of, and how to use them (this Youtube video from Applied Science is very useful) so I will only give an overview of these transistors to give an understanding of the circuit. In this circuit the BJTs are being used as a switch. They each have three leads, called: base, collector and emitter. You will need to look up which pin is which for the specific BJT you are using, but in the photo of the BJTs I have labelled the ones I am using.

In this circuit the NPN transistor I used is a 2N2222A, which, when the lettering if facing you has the pinout from left to right: emitter, base and collector. With an NPN transistor, the base pin is kept at a low voltage via a 10 kOhm pull down resistor to keep it switch off. This large resistor connected to zero volts (ground) ensures that any interference in the air cannot accidentally turn it on, but has high enough resistance that a larger voltage (through a smaller resistor) can still turn it on. Then to switch it on (see Fritzing diagram), the voltage on the base pin must be higher than the voltage on the emitter pin. This allows a small current to flow into the base pin, which means a larger current can flow from the collector to the emitter pin. It is this larger current being permitted to flow from collector to emitter that allows a device to be turned on, that’s how NPN transistors work like a switch. Usually, the device you want to switch on is between the positive voltage (e.g., battery) and the collector pin. And in this case, the “device” to switch on will be the PNP transistor (see below).

For this circuit the PNP transistor is a 2N4126 (it is what I had on hand). When the lettering of this transistor is facing you, the pins from left to right are: emitter, base and collector. PNP transistors work in a similar way to NPN, however the voltage polarities are reversed. The voltage to the base pin is normally pulled high through a 10 kOhm resistor to keep the transistor switched off, and if you bring the voltage lower than the emitter pin (see other Fritzing diagram), then a small current can flow through the collector and out the base pin. This means a larger current can flow from the emitter pin to the collector pin. Thus, usually the device to be switched on is between the emitter pin of the PNP transistor and ground (or the negative terminal of the battery).

The Push-Button Circuit

BJT Pushbutton latching on-off circuit_bb.png
Bipolar Junctional Transistor: Latching Pushbutton On/Off Circuit

The centre of the pushbutton circuit is the PNP transistor. It will provide power to the microcontroller, sensor and display of my future project. For the purposes of demonstration in this Instructable, it will just turn on an LED (the dummy load in the picture). Here the base of the PNP transistor is pulled high through a 10 kOhm resistor to ensure it stays off. Then when the button is pressed, the base is then also connected to ground through a 1 kOhm resistor. This is enough to turn on the PNP transistor while the button is pressed. However, by itself, this will turn off when the button is released because the base no longer has any connection to ground. This is where the NPN transistor comes in, to latch the circuit and maintain power.  

The base of the NPN transistor is pulled low through a 10 kOhm resistor to keep it off. When the circuit turns on, the microcontroller is powered and it starts running through its program. One of the very first things in the microcontroller’s program is that it must supply a high voltage to the base pin to switch on the NPN transistor. By doing so, the “device” the NPN is switching on in this case is the PNP transistor. The collector pin of the NPN transistor will keep the base pin of the PNP transistor in a low voltage state, which keeps it on. This is the latching function as it will ensure the PNP transistor is supplying current even when the button is released.

Lastly, there are a couple of diodes in this circuit to make use of the button once the circuit is powered up. Diodes are usually used to only allow current to flow in one direction. In this circuit the cathode of both diodes, the lead on the side with the stripe, are connected to the same side of the button. When the button is pressed, current can only flow through both diodes, the button and the 1 kOhm resistor to ground (the top rail of the breadboard in the picture). The diodes are not strictly needed for latching the circuit, but are included so that after powering up, the button can be re-purposed after the microcontroller has powered up. The diode is connected to an input pin on the microcontroller that is programmed to detect a low voltage signal (though the Schottky diode, the resistor to ground). In my set up, I am re-purposing the button for a push-button-off function. The microcontroller will detect a button press, it will stop the latch signal to the NPN transistor which turns off the PNP transistor, and therefore all power to the device.

If you want to keep the circuit simple, you can omit the two diodes and connect the base of the PNP transistor directly to one side of the button, and the other side of the button through the 1 kOhm resistor to ground. The button will not be used at all after powering up. In this case you could program the microcontroller to stop the latch signal at some pre-determined point in the program (e.g., after a certain amount of time, or when a sensor detects a specific condition, etc.), or just unplug power to turn it off. The device will shut down and not start again until the button is pressed again.

If you are interested in trying this circuit, please follow the Fritzing diagram included in this step. I note that the LED only draws about 3 mA, but depending on what you plan to power and what voltage you plan to use with this circuit, you may have to experiment with different values for each of the 1 kOhm resistors to ensure you get enough current.

No Detectable Current Draw When Off (that I Could Measure Anyway)

20221231_105913.jpg

This is the first time I made a circuit like this with BJTs and I wondered if there was any quiescent current consumption when the device is off. If there was, then the batteries would die faster than if I just used a regular on/off switch instead (Again, I did not want a switch that the operator could forget to turn off). In a previous Instructable I made a nanocurrent meter (see picture), which I used here to see if I could detect a smaller current than what my multimeter could show. I am happy to say that if there is any current drawn, it is smaller than 30 nA (= 0.00000003 A) at 3.3 volts, so if there is any battery drain it would be negligible.

Example Code and Conclusion

BJT Pushbutton latching on-off circuit_MICROCONTROLLER_forSchematic_schem.png
BJT Pushbutton latching on-off circuit_MICROCONTROLLER_bb.png
BJT Pushbutton latching on-off circuit_Arduino_bb.png

Well, that’s it. You can use the code below and an Arduino or an Atmega328 if you wish to try it: connect the purple wire in the picture to D2, orange wire to D3, and the LED & 220 Ohm resistor to D13. Connect 5volts to the breadboard (not directly to the Arduino), and make sure everything has a common ground connection. Press the button to power up, and see the LED flash. If you do nothing, it is programmed to power down after 60 seconds. If you press the button, it will shut down immediately. If you can get this working, then you can apply this ON/OFF circuit to your needs.

This BJT circuit would work well with any Arduino, but it works best with a bare microcontroller (like an Atmega328) without a bootloader, which all Arduino boards usually have. The reason is that the bootloader adds a small delay before the circuit can be latched. Not a big deal, you just have to hold the on button a few seconds for the Arduino to finish running the bootloader when starting up.


Thanks for reading my Instructable. This circuit is a prototype so if you have feedback, please feel free to provide some in the comment section below!