AI Tutor
If you switch off a sensor by disconnecting its ground connection, the entire sensor circuit remains energized at the full positive supply voltage. Any connected communication lines, like I2C or SPI, can accidentally provide a sneaky return path to ground and destroy your microcontroller.
To truly isolate a circuit, we must cut off the positive supply rail using high-side switching, where the switch sits directly between the positive supply rail (VDDV_{DD}) and the load.
How do we make a transistor conduct when it sits directly on that high-voltage positive rail?

P-Channel Enhancement MOSFET Operation

In 1925, Austro-Hungarian physicist Julius Edgar Lilienfeld patented the concept of a field-effect transistor to control current flow through an electrostatic field without consuming continuous input power.
A P-channel MOSFET turns ON when its gate-to-source voltage (VGS=VGβˆ’VSV_{GS} = V_G - V_S) drops below a negative threshold (VGS(th)V_{GS(th)}), typically around βˆ’2Β V-2\text{ V} to βˆ’4Β V-4\text{ V}.
Connecting the source to a +24Β V+24\text{ V} rail means the gate must reach +24Β V+24\text{ V} to turn off, but what happens when your microcontroller output only goes up to +3.3Β V+3.3\text{ V}?

The Level-Shifting Dilemma

If a 3.3Β V3.3\text{ V} logic pin connects directly to the P-FET gate on a 24Β V24\text{ V} rail, the resulting gate-source voltage is VGS=3.3Β Vβˆ’24Β V=βˆ’20.7Β VV_{GS} = 3.3\text{ V} - 24\text{ V} = -20.7\text{ V}.
This permanently turns the MOSFET ON, and because most FET gates break down at Β±20Β V\pm 20\text{ V}, it will instantly puncture the thin gate-oxide insulating layer.
To solve this, we insert a small NPN bipolar junction transistor (BJT) to act as an intermediate level-shifter that bridges the 3.3Β V3.3\text{ V} logic domain and the high-voltage supply rail.