This tutorial is to teach you about transistors, flyback diodes, and basic Arduino functions. This Instructable is based off of a circuit from the Arduino Experimentation Kit.
This is a good tutorial for anyone starting out with Arduino. These parts are very easy to come by in any starter kit or very cheap if you don't have them. The programming is also very simple and uses functions that are already part of the Arduino library.
This tutorial covers transistors and flyback diodes for educational purposes. This is not necessarily the most efficient way to accomplish this project.
The materials for this project can be seen below but are as follows:
--- Arduino Uno or similar. If you know how your Arduino works then any should be fine for this project.
--- Breadboard. If this is not a project you want to keep then a breadboard is fine. Otherwise you will need to find perfboard or another way to make the circuit permanent.
--- Jumpers or wires. Many Arduino kits come with jumpers. If you do not have one, regular solid core wire is fine.
--- A Small Speaker. These can be found in many electronic devices. You will need one that can be powered on 5v from the Arduino. A piezoelectric buzzer can also be used in this circumstance.
--- 2.2k Ohm Resistor (Red Red Red). This is a good value for the transistor I am using and will most likely work for yours. If not you will need to find the datasheet and determine the appropriate resistor.
--- A Diode. These all work generally the same but watch for the polarity. It matters which way around it goes.
--- A NPN Transistor. These are quite common as well. Watch for the polarity on this as well.
If these parts are familiar to you then you can skip this step. If not, then read further.
A Transistor is a semiconductor used to amplify a signal. It has three pins: a Emitter, a Base, and A Collector.
The Emitter is where the amplified current comes out when signaled
The Base is the signal which controls the larger current. This is where the output signal from the Arduino will go.
The Collector is the pin which receives the higher current.
In our case the "higher current" will be the 5v output from the Arduino and the "lower current" will also be the 5v coming from a digital output pin but coming through the resistor to lower the current to below the transistors maximum voltage to properly switch the higher current.
The flyback diode is used to protect the Arduino pins from unwanted current created by devices with magnets such as motors and the speaker. A diode only lets current flow in one direction. When the device with the magnet becomes unpowered a small amount of current is quickly created which can damage pins when it flows backwards. The flyback diode removes this possibility. As I stated before, this is for educational purposes. The energy possibly created by the speaker is negligible but would not be for a toy motor for example.
Following the picture assemble the circuit on the breadboard. You can follow the circuit diagram or you can follow the picture I created in Fritzing.
Make sure you connect the transistor pins in the correct order and make sure the diode is in the right way.
Connect the resistor to any digital output pin on the Arduino. I used #9 (pwm).