Hello. First time poster here. I am just getting started with the Arduino, and I'm coming into this world with only a very basic understanding of electronics. I do have a very solid understanding of computers and a reasonable amount of knowledge in programming.
I got the Arduino Starter Kit from Amazon. The one that says "Official Kit from Arduino with 170-page Project Book". It's an Arduino Uno R3. I completed the first 6 projects with no problem. I played around with the programming a little for each one to help develop a better understanding of the specific syntax requirements for the IDE.
At the moment, I'm trying to work out how to use the Arduino to simply turn on/off 1 side of my breadboard. (See photo)
On the left side of the breadboard, I have 4 LED's that are always on. On the right side of the breadboard, I have 4 LED's that I want to turn on and off in software.
I understand how to insert a physical switch to make this work, and I understand what the physical switch is doing. When it's not pressed, it breaks the flow electricity. When it is pressed, it allows electricity to flow through which turns the right side of the breadboard on. But I don't know how to do that with software.
One thought I had was to use a relay switch. As I understand it, relays can be turned on and off by applying a HIGH or LOW signal to them. However, my kit did not come with a relay and I'm not sure what exact relay I would need that would be compatible. Also, I believe this can be done without a relay.
My specific question is: How do I wire the connection between the breadboard and the Arduino so that I can turn the 4 LED's on the right off?
Each Arduino pin is powerful enough to control a single LED (20mA of current), but
as currents get larger a switching device is needed.
You have a choice of BJT (bipolar junction transistor), MOSFET, or mechanical relay
(but the latter would need a BJT or MOSFET to power it and a free-wheel diode,
so its best reserved for switching say mains or very high power circuits).
For 4 LEDs a small switching transistor like the 2N2222 (NPN) would do, and
would switch on the low side (ground side). Or a PNP device could switch the
5V rail (high-side switching).
Logic-level MOSFETs can be used, n-channel for low-side switching,
p-channel for high-side switching.
Search around here for examples perhaps? The playground has some stuff.
MarkT:
Each Arduino pin is powerful enough to control a single LED (20mA of current), but
as currents get larger a switching device is needed.
Makes sense.
MarkT:
You have a choice of BJT (bipolar junction transistor), MOSFET, or mechanical relay
(but the latter would need a BJT or MOSFET to power it and a free-wheel diode,
so its best reserved for switching say mains or very high power circuits).
Ah. So a basic 5v relay isn't any good by itself?
MarkT:
For 4 LEDs a small switching transistor like the 2N2222 (NPN) would do, and
would switch on the low side (ground side). Or a PNP device could switch the
5V rail (high-side switching).
OK. The Starter Kit I have came with 5 Transistor [BC547]. (Which don't seem to ever get used by the included Projects.) That PDF says they are "Amplifier" transistors though, so I assume they cannot be used for ON/OFF switching?
MarkT:
Logic-level MOSFETs can be used, n-channel for low-side switching,
p-channel for high-side switching.
It also came with 2 Mosfet transistors [IRF520]. Project 9 has an example for using the Mosfet transistor. After a few wiring mistakes, I was able to make it work for my sample project with these 4 LED's.
Thanks a lot for your help. It's very cool to control physical things with a bit of simple code. I think I'm already hooked.
Only because the coil likely takes more current than an Arduino pin is capable of supplying. A transistor switch is necessary for higher DC currents.
OK. The Starter Kit I have came with 5 Transistor [BC547]. (Which don't seem to ever get used by the included Projects.) That PDF says they are "Amplifier" transistors though, so I assume they cannot be used for ON/OFF switching?
Yes, they can. Any small-signal transistor is good for switching moderate levels of current in the range of a couple hundred milliamps.
It's very cool to control physical things with a bit of simple code. I think I'm already hooked.
blixel:
OK. The Starter Kit I have came with 5 Transistor [BC547]. (Which don't seem to ever get used by the included Projects.) That PDF says they are "Amplifier" transistors though, so I assume they cannot be used for ON/OFF switching?
Yes, they can. Any small-signal transistor is good for switching moderate levels of current in the range of a couple hundred milliamps.
Ah ok. Excellent. One thing though. When I use the Mosfet transistor [IRF520] to control the ON/OFF switching of the LED, the onboard LED flashes in sync with the LED on the breadboard. (Using pin 13.) But when I use the Transistor [BC547] to control the ON/OFF switching, the onboard LED is always off.
Any idea why that is?
It spooked me when I switched from the Mosfet to the Transistor because I thought I managed to blow out the onboard LED. But when I removed the Transistor, the onboard LED started flashing again. And when I switched back to the Mosfet, the onboard LED once again blinked in sync with the LED on the breadboard.
You've got the load of the bc547 on the emitter and the collector grounded, although I'm not sure that would cause your exact symptoms. Load of an npn should be between the collector and +ve.
JimboZA:
You've got the load of the bc547 on the emitter and the collector grounded, although I'm not sure that would cause your exact symptoms. Load of an npn should be between the collector and +ve.
Hmm... so flip it around?
[quote author=Coding Badly]
No current limiting resistor between the Arduino and the transistor base?[/quote]
That was it. I added another resistor between the white wire and the center pin on the transistor and now the onboard LED is blinking. I'm using the same resistance as I was for the LED, 220ohms. Is that sufficient?
Should the Mosfet have a resistor between the Arduino and white wire also?
blixel:
I'm using the same resistance as I was for the LED, 220ohms. Is that sufficient?
5 volts / 220 ohms * 1000 milliamps per amp = 22.7 milliamps. Which is less than 40 mA (damage occurs) so that is a reasonable choice.
Should the Mosfet have a resistor between the Arduino and white wire also?
I rarely include one but, yes, it should. The goal is the same for a MOSFET (limit the current). Someone else will have to help you determine a reasonable resistance for the MOSFET you are using.
JimboZA:
Well if the problem was fixed by the lack of base resistor, maybe you just had the pic wrong not the circuit?
Adding the resistor fixed the problem but I thought I might still have the transistor backwards otherwise. Like you said, it may not make a functional difference in this case, but it could still be wrong, technically. I don't quite understand the pinout other than knowing the data wire goes to the center. The other two seem interchangeable.
Jiggy-Ninja:
Yes, they can. Any small-signal transistor is good for switching moderate levels of current in the range of a couple hundred milliamps.
Caveat - there are high voltage and high frequency transistors that have very low
maximum currents, order of 50mA, but they are rare and exotic and unlikely to
be sitting in a general purpose kit!
A switching transistor is optimized for low Vsat and low stored-charge, but all
bipolar transistors behave basically the same. Most general purpose ones
have ratings like 30V to 80V, 0.15 to 0.5A.
Newer "super-beta" devices (which are usually surface mount) perform loads
better than the average small signal transistor, for instance 5A max and 20A
peak I've seen in a small transistor, 50mV Vsat at 1A. Some are available
in through-hole packages, for instance I've a few STX724's and ZTX851's
which are super-beta in TO92 and e-Line packages respectively.
Or to put it in brief you don't necessarily need to go to a TO220 MOSFET or
Darlington for switching loads of an amp or two - for instance a stack of 8
e-Line superbeta transistors fits on the footprint of an ULN2803 and provides
substantially higher load currents and lower Vsat. At a price, admittedly.
The ULN2803 is a chip with eight 0.5A darlington transistors sharing emitters,
a handy device for switching multiple loads. If there was a super-beta array
with the same pinout it would be a winner in the hobbyist market at least, but
new devices no longer come out as through-hole packages...
Hi,
If your using pin 13 as the control pin, that pin also connects to the on-board LED, so that will also switch that LED on too.
If using a FET tie the Gate to ground with a 100K resistor, this makes sure the FET only switches ON when the gate is pulled high.
FET's take very little current (Their voltage controlled, unlike Tranies that are current driven) and the resistor between control/signal can often be omitted.
Cactusface:
Hi,
If your using pin 13 as the control pin, that pin also connects to the on-board LED, so that will also switch that LED on too.
If using a FET tie the Gate to ground with a 100K resistor, this makes sure the FET only switches ON when the gate is pulled high.
FET's take very little current (Their voltage controlled, unlike Tranies that are current driven) and the resistor between control/signal can often be omitted.
Hope it helps, regards.
Mel.
What does the T in FET stand for?
The proper term for a current controlled transistor is Bipolar Junction Transistor (BJT).