/ Sunday, 19 February 2017 / No comments / Arduino , How-To
How to use Transistor switch with Arduino
Transistor switching with arduino
Transistor as a Switch with Arduino:
Transistor a semiconductor device which is use as a switch with arduino. There are many different applications in which transistor is used.The reason of using Transistor with Arduino is that in any microcontroller there is not enough current to drive heavy loads like motors so for drive the heavy loads we use some extra switch like transistor or relays. Here we are going to switching led with transistor for basic knowledge.
For controllind dc motors with transistor click here http://www.makeitmech.com/2017/02/drive-dc-motor-using-transistor-arduino.html
Use of transistor is also useful when if you are using some external switch such as push button and you want to use electrical switch instead of using push button you can use Transistor so it can switch electrically with heavy loads.
Theory of Transistor:
Transistor have three legs emitter, base, collector. Transistor is using to turn a small input current into large output current and acts like amplifier. But at the same time it also used for switching.When there is no current is flow through base a little or no current flow between emitter and collector. Turn ON the base current make a big current flows through emitter and collector.
Transistors:
1. Purely an electronic device, also called Electronic switches
2. Comes in configuration of PNP and NPN. We will be using npn transistor configuration.
3. Can handle DC loads only.
4. They can operate at MHz speed.
5. Activation generally requires low voltages that in most of the cases, can be provided by
Arduino board.
6. Long life.
Now because of your basic Knowledge i am going to show you that that if a led is powered by external 12 volt battery with resistor then whats going on and whats the circuit and if we connect it with an electric switch then whats the circuit and also whats happen when we connect it with Transistor then whats happen.
Now the circuit with Transistor is connect with Arduino and arduino pin then we saw that how to connect transistor with arduino as a switch.The transistor allows you to control a circuit that’s carrying higher current and voltage from the microcontroller. It acts as an electronic switch. It’s designed for switching high-current loads. It has three connections, the base, the collector, and the emitter. The base is connected to the microcontroller’s output. The high-current load (i.e. the motor or light) is attached to its power source, and then to the collector of the transistor. The emitter of the transistor is connected to ground.
You’ll notice that each of those circuits uses a series resistor between the control input and the base of the transistor. Don’t forget to add this resistor! A transistor without a resistor on the base is like an LED with no current limiting resistance.
Some transistors may only be rated for a maximum of 10-100mA of current to flow through them. If you supply a current over the maximum rating, the transistor might blow up. The series resistor between our control source and the base limits current into the base. The base-emitter node can get its happy voltage drop of 0.6V, and the resistor can drop the remaining voltage. The value of the resistor, and voltage across it, will set the current.
Schematic of Transistor switch and arduino:
FINAL CODE:
int transistor_switch = 2;void setup() {
pinMode(transistor_switch,OUTPUT);
}
void loop() {
digitalWrite(transistor_switch,HIGH);
delay(1000);
digitalWrite(transistor_switch,LOW);
delay(1000);
}
Understanding with code:
Step #1: Global space
In global space we define that what is the name of our variable and the pin we connect our output or input connect with so here i use variable (transistor_switch) and pin number (3). Declare an integer variable with suitable name and define it with the digital I/O pin # (0 to 13).
Step #2: Configure in setup()
At setup we define our pin Mode that the variables declare in the global space is our INPUT or OUTPUT. In our case we see the led glowing so we write it as OUTPUT. For our program, we should write:
void setup() {
pinMode(transistor_switch,OUTPUT);
}
Step #3: loop()
In loop() you can actually do something that run again and again so in our loop by using of switch we ON and OFF the led by using delay of 1 second so that we see our output switching ON and OFF.
void loop() {
digitalWrite(transistor_switch,HIGH);
delay(1000);
digitalWrite(transistor_switch,LOW);
delay(1000);
}
Once the code is uploaded, if you have done everything right, the LED should flash. It will do that for as long as the device is plugged in.
Note- if the Arduino is unplugged, then plugged in again, it will still work.
Hope you enjoyed the lesson, keep looking at my profile for more arduino lessons soon.
Related Posts
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment