Тёмный
No video :(

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

DIY Engineers
Подписаться 7 тыс.
Просмотров 84 тыс.
50% 1

Опубликовано:

 

28 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 62   
@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 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8DMZSxS-xVc.html
@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!
@Rickety3263
@Rickety3263 7 месяцев назад
I think this will be my reference for my arduino remote control for 2 nerf machine gun switches
@shakirabdo638
@shakirabdo638 Год назад
Awesome video ❤, I understand every word you said
@diyengineers
@diyengineers Год назад
Thanks for watching!
@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.
@danielmalatji1813
@danielmalatji1813 3 месяца назад
How bout we now using Arduino with the npn and relay to control a 220Vac fan☺️☺️☺️
@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!
@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!😃👍
@Zanzibar-LandOfBlacks
@Zanzibar-LandOfBlacks Год назад
I am an electronics student, and I am trying to understand how a transistor is used like a switch. Why do we need the transistor to switch on and off the LED while we can just use that button when the LED is connected to a battery?
@diyengineers
@diyengineers Год назад
Thanks for watching. I am using the signal from the Arduino to turn the light on and off. The issue is that due to the electrical rating of the LED Flash, I am unable to power directly from the Arduino, so I use the Arduino signal to tell the transistor when to allow current to flow through it (basically having the transistor to operate as a switch). This transistor is rated to handle the electrical load from the LED, which is why I am using it.
@pcbland7850
@pcbland7850 2 года назад
Amazing my friend ♥♥♥♥♥ Nice to meet you ♥♥♥♥♥ Best wishes for you ♥♥♥♥♥ Keep it up ............. ♥♥♥♥♥
@diyengineers
@diyengineers 2 года назад
Big thanks
@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.
@luise8781
@luise8781 3 года назад
Thank you, very helpful
@diyengineers
@diyengineers 3 года назад
Thanks for 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); }
@wadebrewer7212
@wadebrewer7212 4 месяца назад
Why 4.7kohm resistor. I am firing 2N2222 with arduino out and a 1kohm resistor.
@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 2 года назад
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
@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.
@alistairmurray626
@alistairmurray626 2 года назад
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 2 года назад
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 2 года назад
@@diyengineers Ahh! thanks!
@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.
@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 2 года назад
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/
@user-pm8je4fo7e
@user-pm8je4fo7e Год назад
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 Год назад
Thanks for watching!
@user-pm8je4fo7e
@user-pm8je4fo7e Год назад
@@diyengineers yeah, you tricked me into that. Hope you proud.
Далее
DS3231 with Arduino UNO
11:10
Просмотров 2,4 тыс.
Only I get to bully my sister 😤
00:27
Просмотров 36 млн
Секрет фокусника! #shorts
00:15
Просмотров 43 млн
How an NPN Transistor Works as a Switch?
7:58
Просмотров 54 тыс.
MOSFETs and Transistors with Arduino
40:50
Просмотров 1 млн
What is 2N2222 npn transistor using with Arduino Uno
10:43
NPN vs. PNP Transistors as Common-Emitter Switches
8:58