2N2222 NPN Transistor as a switch - Arduino example with LED Flash

  Рет қаралды 91,016

DIY Engineers

DIY Engineers

Күн бұрын

Пікірлер: 64
@diyengineers
@diyengineers Ай бұрын
Where to buy [Amazon Affiliate]: Arduino UNO: amzn.to/3U7xAoT Hilitchi Transistors Assortment Kit: amzn.to/4aI8Mux Electronic Component Kit: amzn.to/3xDtHAn Amprobe AM-510 Multimeter: amzn.to/44gy2WE Amprobe TL35B Test Leads with Alligator Clips: amzn.to/3Utf8s0 Breadboard (Elenco 9440): amzn.to/4b5Onzq
@gradygraham1281
@gradygraham1281 3 жыл бұрын
First of all let me say. Its so refreshing to see the younger generation taking and active interest not only in understanding electronics and circuitry along with the laws that govern its principles, but also taking on a role as instructors and teachers of such. You are the future designers who will change our world in so many innovative and useful ways. As an electrician of 34 years I applaud you. Constructive criticism. Its important to have your math spot on. The numbers wont lie. What might lie is the testing equipment's calibration or the variables of the parts you are using. Things as simple as the resistance of wire size and length along with ambient temperature could cause some of the math not being precise when it comes to the values your digital volt meter was registering as well as the resistor value the resistor claims to be vs the actual resistance when measured.. I would like to see you get to the bottom of this and fully explaining why the measured values did not match the math values. OHM'S law has been around for a long long time and its proven over time and experiments. I would like to see you give explanations based on reality when the testing equipment does not match the math. If you know your testing equipment is sound then perhaps you could give us the actual VD across the LED or the actual values of the transistor. Something had to be the cause for the math not being spot on when tested. And this is where you separate the blind from the leaders of the blind. Personally I have thumbed up and subscribed to your channel. I am so happy to see someone not only give resistor values and the math but then show the circuit being tested to make sure the math was correct as it should be. I will be following you and hope to watch you learn and grow and accomplish great things. You are well on your way. Thank you for an excellent video.
@gradygraham1281
@gradygraham1281 3 жыл бұрын
Example kzbin.info/www/bejne/bnWwi4auiJKrjMU
@diyengineers
@diyengineers 2 жыл бұрын
Thanks for watching and for your encouragement!
@RexxSchneider
@RexxSchneider 2 жыл бұрын
The main reason why the maths is not spot-on is because the LED has built-in current limiting, which may be either a resistor or a constant current device. The datasheet for the LED is showing 15mA, but that will be a typical current under a specific set of operating circumstances and in this circuit, nobody should be surprised if it was measured as 17.7mA. Measuring the voltage across the LED will tell you nothing other than the Vce(sat) of the transistor at that current. The small error in the measured base current (0.91mA vs 0.94mA) is well within the range of accuracy of a 5% resistor, and it should be noted that the 0.6V for Vbe used in the calculation might be anywhere between 0.6V and 1.2V, except that those values are quoted for Ib=15mA and we only have about 1mA, so we don't have specifications for what Vbe actually will be. Using 0.6V as a "guestimate" is quite reasonable, but then you have to expect some variations from what you measure in a real circuit.
@dimyttt1780
@dimyttt1780 Жыл бұрын
@@RexxSchneider Thanks, that's pretty accurate.
@citizengkar7824
@citizengkar7824 2 жыл бұрын
Nice presentation-concise & to the point: excellent style, of incorporating the various aspects of design & concept, plus initial & final testing. This is from an electronics noob.
@diyengineers
@diyengineers 2 жыл бұрын
Thanks!
@Anton-wc7lb
@Anton-wc7lb Жыл бұрын
Woho! It's working, thanks! Good idea with the trouble shooting, I did that and found voltage across my LED, that way I realised that my LED was broken.:)
@diyengineers
@diyengineers Жыл бұрын
Thanks for watching!
@shakirabdo638
@shakirabdo638 2 жыл бұрын
Awesome video ❤, I understand every word you said
@diyengineers
@diyengineers 2 жыл бұрын
Thanks for watching!
@roy761017
@roy761017 18 күн бұрын
I don’t understand why the 220ohm resistor is needed there between button and GND1. If there is no connection, you don’t need resistor right? Why put an extra wire between GND1 and button there? Appreciate for any help.
@NormanCzerski
@NormanCzerski 19 күн бұрын
With no current limiting in series with the LED and transistor, you should destroy the LED and/or transistor. What is the voltage drop across the LED, what is the voltage drop across the transistor and what is the total current through the transistor. While this may have worked for the components you used, it could be useless for random component choice. At what point of the conduction curve is the transistor?
@markday3145
@markday3145 3 жыл бұрын
With typical indicator LEDs, you have to limit current flowing through them, or you will burn them out. Is this LED different in that regard? Will it limit its current draw (thus reducing the collector current)?
@diyengineers
@diyengineers 3 жыл бұрын
Yes. This LED flash is ready to use from the supplier/seller and does not require adding a resistor for current control. If you were using a typical LED, you would need a resistor.
@Rickety3263
@Rickety3263 11 ай бұрын
I think this will be my reference for my arduino remote control for 2 nerf machine gun switches
@danielmalatji1813
@danielmalatji1813 7 ай бұрын
How bout we now using Arduino with the npn and relay to control a 220Vac fan☺️☺️☺️
@wadebrewer7212
@wadebrewer7212 8 ай бұрын
Why 4.7kohm resistor. I am firing 2N2222 with arduino out and a 1kohm resistor.
@kentharris7427
@kentharris7427 2 жыл бұрын
I am using a Transistor to increase the current at 5 volts. I am making a parking proximity sensor using a HC-SR04 Ultrasonic Module and a 650 NM laser. The HC-SR04 detects the car rolling into the garage and the 650NM Laser is turned on for 30 seconds. The laser draws 30mA at 5 volts. I am going to use a 2.2K resister on the Transistor base.
@RexxSchneider
@RexxSchneider 2 жыл бұрын
When you drive a transistor into saturation, the rule of thumb is to set the base current at 1/10 of the collector current. have a look at the datasheet for the 2N2222 and you'll see that all of the examples of saturation show base currents one-tenth of the collected current quoted. If the collector current needs to be 30mA, then normal design is to drive the base with 3mA. The value is not critical and if you have 5V available to drive the base, then a 1.5K resistor will give you about 3mA. Your 2.2K resistor will give about 2mA base current and that will also work fine to drive a 2N2222 into saturation.
@qzorn4440
@qzorn4440 3 жыл бұрын
great video... this will work nicely as a pulse amplifier from 3vdc to 15vdc... thanks a lot....:)
@diyengineers
@diyengineers 3 жыл бұрын
Thank you for watching and taking the time to comment! The potential applications for transistors are endless. Glad you enjoyed watching!😃👍
@apratube
@apratube 3 жыл бұрын
your switch uses pull-down resistor, right? meaning, the pin will see 0 if button not pressed. your code says, if button == 0 (not pressed), then turn the LED on (?).. but your video shows the other way around.. is my understanding correct?
@diyengineers
@diyengineers 3 жыл бұрын
Thank you for your question. I reviewed the circuit and code, and I agree you are correct. When you press the button, a 5V signal will be sent to Digital Input #2, and when you release the button (not pressed) a 0V signal will be sent to Digital Input #2. That means that Button_State = 0 when the button is released (not pushed). The code shows that when Button_State = 0 the LED will turn on, but then the video shows the opposite. I must have changed this last minute and forgot to fix the code. To address this, change the If-statement as follows: if (Button_State == 1){ digitalWrite(LED, HIGH); } else{ digitalWrite(LED, LOW); }
@GtechExplorerations
@GtechExplorerations 2 ай бұрын
Very clear presentation, but your calculation of 0.94 mA is is off by an order of 1,000. It should be 0.00094 mA. If it were nearly 1 amp your Arduino would be fried the instant the LED was turned on.
@pcbland7850
@pcbland7850 2 жыл бұрын
Amazing my friend ♥♥♥♥♥ Nice to meet you ♥♥♥♥♥ Best wishes for you ♥♥♥♥♥ Keep it up ............. ♥♥♥♥♥
@diyengineers
@diyengineers 2 жыл бұрын
Big thanks
@michaelborisow815
@michaelborisow815 3 жыл бұрын
What's the point of the base? I was able to do this without any connections there, nor any transistor at all, of course
@diyengineers
@diyengineers 3 жыл бұрын
So did you just power it directly to the voltage source? The intent is to use the transistor as a switch, which then let's you control the flash with an Arduino (or similar) which operates at a voltage that's below what's needed by the LED.
@j5892000
@j5892000 3 жыл бұрын
I'm confused. Why even use a transistor when you can hook the led up straight in series with the switch?
@g.stefanstoica
@g.stefanstoica 3 жыл бұрын
It was used as an example. In this case you could just bypass everything. This video shows how to control a circuit with a higher voltage than your 5V controlling circuit.
@diyengineers
@diyengineers 3 жыл бұрын
Hi NoVakane. Thanks for watching. The transistor let's you switch another power source on/off by using the low power I/O pins. You wouldn't be able to power directly a device that operates at a current or voltage that's above the allowable limits of the Arduino, so the transistor let's you go beyond those limits (as long as the voltage and current don't exceed the transistor limits). Thanks for watching!
@deang5622
@deang5622 Жыл бұрын
Because in years gone by LEDs would typically require 15 or 20mA of current to illuminate them to a reasonable level of brightness, and the logic outputs of chips in those days could not source enough current. Their output drive current was typically a few milliamps and so a transistor had to be used. Now in more modern times the drive current requirement for an LED can be a lot lower. So whilst a transistor may not be strictly necessary in this instance, it is important to be able to design with a transistor on a logic pin output, to teach the design process.
@j5892000
@j5892000 Жыл бұрын
@@deang5622 ooh I see
@OrbMan97
@OrbMan97 2 жыл бұрын
How can I control a motor using 2 sensors? It works if I wire both sensors in parallel to the same pwm pin. But I want to be able to control the motor from 2 different arduino pins. Is this possible? Would i need to use 2 different bjts?
@diyengineers
@diyengineers 2 жыл бұрын
Hi. Thanks for watching! I think you should take the sensor signals on separate I/O pins in the Arduino, and use the code (if statements, etc) to determine when to send a given signal to the motor to move.
@alistairmurray626
@alistairmurray626 3 жыл бұрын
Hi, i'm just about to test this circuit, but i'm worried about the 12v going to the Vin or the arduino, should that be there? other examples don't seem to be as detailed as yours. Won't 12v fry the arduino??
@diyengineers
@diyengineers 3 жыл бұрын
Hi, you can power the Arduino UNO multiple ways. The Vin pin is one of them. See the links below: www.arduino.cc/en/reference/board store-usa.arduino.cc/products/arduino-uno-rev3/?selectedStore=us
@alistairmurray626
@alistairmurray626 3 жыл бұрын
@@diyengineers Ahh! thanks!
@longdongsilver4719
@longdongsilver4719 3 жыл бұрын
You should mention that a normal LED would be destroyed if you connect it directly to 12V via a transistor. Most LEDs don't have built-in limiting resistors. So you just forgot the limiting resistor on your schematics.
@diyengineers
@diyengineers 3 жыл бұрын
Thanks for watching and for calling this out!
@bassamskafi1384
@bassamskafi1384 3 жыл бұрын
I can fixed resistance 8k or 10k on the base
@diyengineers
@diyengineers 3 жыл бұрын
Sorry, not sure if I understood. Let me know if you have any questions! 🙂
@tungvan4029
@tungvan4029 3 жыл бұрын
Can u explain? Why chose res 4.7k without caculate.
@diyengineers
@diyengineers 3 жыл бұрын
Hi! Thank you for your question. On the video at 5:25 I go over the minimum voltage between the base and the emitter, and we write the equation to relate the base current to the voltage drops and resistance (in this case selected to be 4.7k). Selection of 4.7k allowed the base current (ib) to be 0.94mA, which is below the maximum allowable at the Arduino IO Pins. As a result, 4.7k is an acceptable resistance. You could use a different resistance, but you need to ensure all equations work. For example, if you picked a larger resistance, the value of ib would drop, which is okay when comparing against the maximum allowable current, but this could cause issues on the equation I show later (ic = hfe_min * ib), because if Ib is too low, then Ic might be low too, resulting in the LED not turning on. Hope this helps!
@tungvan4029
@tungvan4029 3 жыл бұрын
Thanks. At 10:01 Ic =18.54mA and Ib=0.9mA so hfe=19, but in datasheet hfe_min=35, why? AND 0:43, the current operating LED is 15mA, 18.54>15, i meant what is the current rate of LED?
@diyengineers
@diyengineers 3 жыл бұрын
The current gain (Ic/Ib) can vary due to manufacturing tolerances of the transistors, temperature, current, etc. What you want to do is design your circuit such that it can operate at the minimum specified current gain, in this case at 35. You can see this at 6:19 where I calculate Ic using the minimum specified current gain, I get 32.8mA, which is above what the LED should be pulling, so we know the transistor will be able to provide the required current (which is expected to be less than the 32.8mA that were calculated). We are not pushing the current, the LED is pulling the current based on what it needs (based on its specifications), so we are simply doing the calculation to ensure the transistor can supply what the LED demands. When I made this video, the LED specification indicated an operating current of 15mA. Normally we would use this as guidance for the design of the circuit. I went back to the website (link below) and saw that they actually updated the specification to show a current of 20mA. So our measurement is now below the rating they have on the website. Slight variations versus listed values are expected. www.superbrightleds.com/moreinfo/led-wired-bolts/little-dot-smd-led-accent-light/639/#tab/specifications
@tungvan4029
@tungvan4029 3 жыл бұрын
@@diyengineers yup. thanks a lot!
@diyengineers
@diyengineers 3 жыл бұрын
Glad I could help! 😀👍
@easyrobotic9754
@easyrobotic9754 3 жыл бұрын
Coooollll
@diyengineers
@diyengineers 3 жыл бұрын
Thanks for watching!
@harpuli
@harpuli 3 жыл бұрын
that led is dead without a resistor at 12v
@diyengineers
@diyengineers 2 жыл бұрын
I think I made mention of it being a special LED with a built-in resistor. But, yes, if it was a standard LED, it would be an issue. Thanks for watching!
@RexxSchneider
@RexxSchneider 2 жыл бұрын
Because LEDs are now so commonly used in automotive applications, it makes sense for a manufacturer to build the part with a built-in resistor (or some other means of current limiting) so that the voltages encountered in use with a car having a 12V battery can be connected directly to the part. You can see that the datasheet specifies a voltage between 9V and 14.8V, and car alternators are specified to output a maximum of 14.8V. When you see a part specified with a maximum voltage of 14.8V, it is a sure indicator that it's designed for automotive use and will tolerate 12V directly.
@robinsonsoto8471
@robinsonsoto8471 3 жыл бұрын
You are applying 12 v to a led without current limiting resistor. This does not make sense.
@diyengineers
@diyengineers 3 жыл бұрын
Hi Robinson. It is an LED flash that was designed to light up when 9V-14.8V are applied. It's a ready to use component (not a standard LED). That's why a resistor is not needed (it's already built-in). See this link for more details: www.superbrightleds.com/moreinfo/led-wired-bolts/little-dot-smd-led-accent-light/639/
@ФеофанЭтополедолжнобытьзаполне
@ФеофанЭтополедолжнобытьзаполне 2 жыл бұрын
The fact that this particular part has "built-in resistance" does not matter since your circuit diagram clearly states "regular LED". Also you code doesnt add up with actual results obtained, which kinda undermines the whole experiment. And the worst thing is that you math isnt actually explaining anything. It doesnt explain how to find values we are looking for, how to find proper resistance and transistor, it just shows how your already-in-place results are correct (and they are not, since your shematics doesnt reflect actual parts being used). This material is useless AND confusing for anyone who knows less than you do (or claim to).
@diyengineers
@diyengineers 2 жыл бұрын
Thanks for watching!
@ФеофанЭтополедолжнобытьзаполне
@ФеофанЭтополедолжнобытьзаполне 2 жыл бұрын
@@diyengineers yeah, you tricked me into that. Hope you proud.
DS3231 with Arduino UNO
11:10
DIY Engineers
Рет қаралды 3 М.
Fun with Transistors
24:33
HackMakeMod
Рет қаралды 631 М.
Правильный подход к детям
00:18
Beatrise
Рет қаралды 10 МЛН
Smart Sigma Kid #funny #sigma
00:33
CRAZY GREAPA
Рет қаралды 38 МЛН
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 58 МЛН
NPN vs. PNP Transistors as Common-Emitter Switches
8:58
Kevin Patterson (Kevin H. Patterson)
Рет қаралды 611 М.
Port Register Control | Increase speed of Read/Write - Arduino101
15:22
3 Ways to power an Arduino Board - Do you know them?
9:20
Programming Electronics Academy
Рет қаралды 151 М.
10 awesome application of capacitors in circuits
29:01
Electronic Wizard
Рет қаралды 418 М.
Designing Power MOSFET Circuits - Circuit Tips and Tricks
20:10
MicroType Engineering
Рет қаралды 355 М.
Правильный подход к детям
00:18
Beatrise
Рет қаралды 10 МЛН