Tuesday, 20 September 2016

How to turn on an LED using a Transistor Explained By ArduinoPak

How to turn on an LED using a Transistor Explained By ArduinoPak

Hey there, You are new to arduino. You are testing out new stuff and your scratching your head thinking, how do I turn on an LED using a transistor, well that is no problem. We are here, we can keep this short and get straight to the stuff.

Remember that Ohms law is Voltage = current x resistance. We are going to use this to calculate the resistor required to use in the series with an LED. The 10-bar red LED arrays that I am using has a 2.0V drop across the LED at 20mA current, this means that my resistor has to be able to take up 3.0V of my 5.0V supply anf give me 20mA. Given that R=V/I = 3V/0.02A = 150ohms. This resistor is said to be stopping the current through the LED and without it the LED would burn.

Now, we got to select a transistor which can switch the current. I need the current on and switched to the LED when the Arduino's output pin is high, so I am going to use an NPN transistor in common-emitter mode. PNP would be used to switch on an LED when the output from the Arduino is low. But I am using an NPN and hey, now you know a difference between NPN and PNP. 

My transistor has to be a maximum collector current which is greater than my desired load current of 20mA. A minimum current gain that allows me to comfortable source a base current from the Arduino pin which can give me the collector current I need, so when the Arduino pin is high, current can flow and into the transistors base, turning it on and allowing current to flow to the collector to the emitter and this will eventually light up the LED. 

I have this BC337 transistor with a min current gain of 100 at 150mA and this is the right stuff.

To calculate the right base resistor value so that the transistor can be fully on and act as it should which means that it acts as an amplifier in which collector current is proportional to base current. The base current IB = IC/hFE = 20mA/100 = 0.2mA. This is way lower than I need to be careful of. If I go for a 4.7K resistor, this will give me IB= (5V-0.7V)/4.7K = ~1mA - plenty to make sure I get the load current I want. The 0.7V is the voltage drop across the base-emitter junction when the transistor is on.

So here is the circuit: 
 
The Arduino code to test the circuit is very simple, using pin 5 to drive the transistor switch:
const int motorPin= 2;
void setup()
{
    pinMode (motorPin, OUTPUT);
}
void loop()
{
    digitalWrite (motorPin, HIGH);
    delay (1000);
    digitalWrite (motorPin, LOW);
    delay (1000);
}
And there we have it. Now I have the basis for switching currents through multiple LEDs - which will be very useful for driving LED arrays.


WE SELL ALMOST EVERYTHING IN THE ELECTRONICS MARKET, MICRO-CONTROLLERS, RESISTOR, CAPACITORS, TRANSISTOR, OPTO-COUPLERS, DIODES, LEDS, RELAYS, CRYSTALS, PCB TERMINAL BLOCKS, HEAT SINKS, HEADER ROWS, PUSH BUTTON SWITCHES, WATER HEATERS, UPS, STABILIZERS, CONTACTORS, ATS, ULN2003, BRIDGE RECTIFIER DB104 AND SO MUCH MORE. THE LIST WOULD GO ON.


IF YOU NEED ANYTHING, A RESISTOR, A TRANSISTOR, AN IC, AN ARDUINO BOARD, A RASPBERRY PI OR WHATEVER IT IS, IF IT IS ELECTRICAL, WE WOULD HAVE IT. SO VISIT OUR SITE TODAY AND GET BUYING.

WWW.ARDUINOPAK.COM


No comments:

Post a Comment