Transistor as a Switch: Build a NOT Gate Using One Transistor
letsBug
0:00 / 0:00
Transistor as a Switch: Build a NOT Gate Using One Transistor
35 просмотров · 7 дн. назад
letsBug
196 подписчиков
35 просмотров · 7 дн. назад
How to use a transistor as a switch, then turn it into a NOT gate: a transistor is a switch with no moving parts, flipped by electricity. We wire a 2N2222 so a button (through a 10 kilohm base resistor) switches an LED, work out the base current (about 0.26 mA switching about 6 mA), see why an ESP32 pin drives motors through a transistor, then flip the bit: a 470 ohm pull-up on the collector turns one transistor into a NOT gate. Press the button, the light goes off.
Full written guide: https://blog.letsbug.in/2026/10/trans...
Open the circuits in Falstad (free, runs in your browser; click the button to press it, click again to let go)
1) Transistor switch: button + 10k base resistor + 2N2222 + LED
https://www.falstad.com/circuit/circu...
2) NOT gate (inverter) with logic probes on the input and output
https://www.falstad.com/circuit/circu...
In Falstad: green = positive voltage, grey = ground, yellow dots = current. Hover over a part to see its current and voltage.
Key ideas
Base current = (3.3 V - 0.7 V) / 10 kilohm = 0.26 mA. It switches an LED current of about 6 mA: more than 20 times bigger.
NOT gate: resistor from the supply to the collector, output taken at the collector. Input 0 → output 1; input 1 → output 0.
Truth table (NOT)
in | out
0 | 1
1 | 0
Real world
An ESP32 pin gives about 40 mA at most; a 2N2222 is rated for 600 mA, so the pin drives the base and the transistor carries the big current. Apple's A17 chip has about 19 billion transistors.
It doesn't work?
Transistor hot, or the simulator stops? Check the base resistor: without it, nothing limits the base current.
Which leg is which? Check your part's datasheet.
Change one thing (answer next episode)
Open link 2 and build a second NOT gate (copy the transistor, its two resistors and the LED), feeding the first gate's output into its base resistor. Press the button: what does the second LED do?
Practice (answers are in the full written guide)
1) With a 4.7 kilohm base resistor and 3.3 V, about how much base current flows?
2) The NOT gate's input is 1. What is its output?
Study material & sources
Falstad circuit simulator (Paul Falstad, JavaScript port by Iain Sharp): https://www.falstad.com/circuit/ (verified)
P2N2222A datasheet (onsemi): https://www.onsemi.com/pdf/datasheet/... (verified)
BC546/BC547 datasheet (onsemi): https://www.onsemi.com/pdf/datasheet/... (verified)
Transistor (Wikipedia): https://en.wikipedia.org/wiki/Transistor (verified)
Bipolar junction transistor (Wikipedia): https://en.wikipedia.org/wiki/Bipolar... (verified)
Inverter (logic gate) (Wikipedia): https://en.wikipedia.org/wiki/Inverte...) (verified)
Resistor-transistor logic (Wikipedia): https://en.wikipedia.org/wiki/Resisto... (verified)
Transistor count (Wikipedia): https://en.wikipedia.org/wiki/Transis... (verified)
Chapters
0:00 Press the button, the light goes off
0:30 Last episode's challenge: the answers
0:58 What a transistor is
1:35 A transistor switches an LED
2:16 Pause and try: the base current
2:44 Why your ESP32 needs a transistor
3:13 Try it in Falstad
3:39 Flip the bit
4:10 The NOT gate
4:39 Truth table, symbol and inverters
5:06 It doesn't work: no base resistor
5:42 Change one thing
6:16 Recap and what's next
#TransistorAsASwitch #NOTgate #Inverter #2N2222 #LogicGates #Falstad #Electronics #ESP32 #letsBugBuilds #STEM