High-Power Control: Arduino + TIP120 Transistor

Discussions area for bildr's blog posts.
From: http://bildr.org/2011/03/high-power-con ... nd-tip120/

Up until now, we have talked about working with a lot of low-power devices. Sensors, LEDs, ICs, and the like are all capable of being powered directly from your Arduino, but as many awesome 5 and 3.3v components as there are, eventually you will find yourself holding a 12v solenoid, motor, or light and wondering “How the heck am I supposed to control this from my Arduino?” Well today we are going to talk about doing just that from a magical device know as a transistor, specifically the TIP120 Darlington Transistor.
ameyer
Founder
 
Posts: 3323
Joined: Thu Jan 21, 2010 11:59 pm
Location: The Bay Area

So far the best explanation of transistors I've seen so far! Good job!


Also, soon my exam period at school will stop, and I'll start with writing another article.
DrLuke
 
Posts: 364
Joined: Sun Jun 20, 2010 6:01 pm
Location: Germany

Thanks! If there is anything I like to hear, it's that I was able to simplify something.

Excellent, Ill be glad to have you back at the helms.

DrLuke wrote:So far the best explanation of transistors I've seen so far! Good job!


Also, soon my exam period at school will stop, and I'll start with writing another article.
ameyer
Founder
 
Posts: 3323
Joined: Thu Jan 21, 2010 11:59 pm
Location: The Bay Area

Thanks for the cleaver and neat tutorial!

I'm using this technique to control 200mW laser beam from the Arduino Uno and it worked well. Since a week I'm trying to go wireless. I'm using Arduino Fio with Xbee, and all my sensors and output are working great... except this high load one. I first though the issu was with driving the mosfet with 3v3 instead of 5v, but I tried it on a separated board and it works great. So I guess it's more concerning the power source. I'm using a simgle battery to power both the ArduinoFio and the lasers. So the connections are exactly as in your drawings, but (all grounds being anyway together) the laser + is directly connected to the battery - in parallel with the Arduino board. The result is an output voltage of 1.4v instead of the 3.7v available from the battery...

**EDIT : Pluging an external power source for the laser, still get a voltage of 1.4v. Instead driving the mosfet from an external power source (and powering the laser with the Fio source) works! So I guess these Mosfet need 5v to let full voltage get through... any suggestion of another Mosfet?

Any clue?

Thanks!
Dave.
Last edited by guizmo_mtl on Thu Feb 09, 2012 10:20 am, edited 1 time in total.
guizmo_mtl
 
Posts: 5
Joined: Wed Feb 08, 2012 1:41 pm

My guess would also be the 3.3v
On the other board, was it a 3.3v only arduino as well?

But it working for this guy: http://diffusionht.blogspot.com/2011/06 ... iting.html

What if you plug in the FIO via USB? Does it work then? If so it could be a power issue.




guizmo_mtl wrote:Thanks for the cleaver and neat tutorial!

I'm using this technique to control 200mW laser beam from the Arduino Uno and it worked well. Since a week I'm trying to go wireless. I'm using Arduino Fio with Xbee, and all my sensors and output are working great... except this high load one. I first though the issu was with driving the mosfet with 3v3 instead of 5v, but I tried it on a separated board and it works great. So I guess it's more concerning the power source. I'm using a simgle battery to power both the ArduinoFio and the lasers. So the connections are exactly as in your drawings, but (all grounds being anyway together) the laser + is directly connected to the battery - in parallel with the Arduino board. The result is an output voltage of 1.4v instead of the 3.7v available from the battery...

Any clue?

Thanks!
Dave.
ameyer
Founder
 
Posts: 3323
Joined: Thu Jan 21, 2010 11:59 pm
Location: The Bay Area

Thanks.

The Arduino Uno was 5v (as in your tutorial), so this was different output voltage than the 3v3 of the ArduinoFio.

Actually I also inspired myself from this post (http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads). So I'm using IRF510 mosfet.

What do you think of the edit of my previous post?

**EDIT: I'll try this one... http://www.nteinc.com/specs/2900to2999/pdf/nte2974.pdf

D.
guizmo_mtl
 
Posts: 5
Joined: Wed Feb 08, 2012 1:41 pm

In this case, I'd say to try and use a BJT instead of a MOSFET because your driving voltage is so low. Any old NPN (because you are putting it on the low side) should suffice as long as it can carry the current (and voltage but it sounds like its a low voltage system) that the Laser requires. Your pin should be able to supply adequet current but it may be worth some protection to put a resistor between the pin and the base of the BJT. Something low like 100 Ohms. To avoid confusion, hte base of the BJT is similar to the gate of a MOSFET. Don't ask me why they couldn't make our lives simpler and use the same damn names.

Is the 200mW laser designed to be just fed the voltage? IE, you don't need a resistor like an LED?. Because this would explain the 1.4V voltage when its powered on...

Just some thoughts...

Jon
Xnient
 
Posts: 30
Joined: Sat Jan 28, 2012 4:42 pm

Thanks for your reply Jon.

The Laser comes with onboard controller, so it really just need voltage (between 3.3v and 3.7v) - as I said I was using them with the IRF510 setup on my Arduino Uno (5v digital output).

I'll give a try with the BJT, don't have any here, but one of these should work : http://www.datasheetcatalog.org/datashe ... Xrzqzr.pdf
http://www.bourns.com/pdfs/tip29.pdf
http://www.pci-card.com/2n2219a.pdf

The current is specified to 500mA-800mA or 1A, but it seems to me that it may also expect a voltage near of 5v to 'turn on'...

D.
guizmo_mtl
 
Posts: 5
Joined: Wed Feb 08, 2012 1:41 pm

You should be fine with just a plain ol' 2N3904 NPN BJT.

They are VERY common and will give you what you want as long as you sink about 10mA into the base. R = 3.3/10mA = ~300 Ohms.

They only cost about 3cents too!

As a note on BJT's, they are current controlled devices. You give it a current into the base and it gives you a current through the transistor. The 3904 has a gain of 100 at 10mA, so if you put 10mA in, you'll get 1 A out (of course, if your device allows it, which yours will not).

Good Luck,

Jon
Xnient
 
Posts: 30
Joined: Sat Jan 28, 2012 4:42 pm

Oh great for the part number... but too late. Igot some sample of the previously listed one... I'll try something with that...

D.
guizmo_mtl
 
Posts: 5
Joined: Wed Feb 08, 2012 1:41 pm

No matter, they all look like they should work...You aren't asking for anything complicated from these parts.

Good Luck and let me know how it turns out.

JOn
Xnient
 
Posts: 30
Joined: Sat Jan 28, 2012 4:42 pm

Following this : http://www.kpsec.freeuk.com/trancirc.htm#npn

And using the 2N3414 NPN, I compute a resistor value of 220Ohm, and it worked!
guizmo_mtl
 
Posts: 5
Joined: Wed Feb 08, 2012 1:41 pm

That's great! I am glad that you got it working.

That's also a very useful link, thanks for sharing.

Jon
Xnient
 
Posts: 30
Joined: Sat Jan 28, 2012 4:42 pm

It works very well for me too :D I am turning on/off a 6V dc motor.

Then I tried to power the circuit with 7.5V instead of 6V (so I can power the arduino from the same source), and it seems the transistor is bypassed :shock: . The motor runs without any interruption and always at the same speed. Is a transitor not supposed to keep the device off and turn it on on command?

I might be missing something, any idea?

thanks
nemalk
 
Posts: 1
Joined: Tue Nov 13, 2012 12:25 pm

Id have to see how it is wired up to know.


nemalk wrote:It works very well for me too :D I am turning on/off a 6V dc motor.

Then I tried to power the circuit with 7.5V instead of 6V (so I can power the arduino from the same source), and it seems the transistor is bypassed :shock: . The motor runs without any interruption and always at the same speed. Is a transitor not supposed to keep the device off and turn it on on command?

I might be missing something, any idea?

thanks
ameyer
Founder
 
Posts: 3323
Joined: Thu Jan 21, 2010 11:59 pm
Location: The Bay Area

Great read, thanks!
Other posts on this site also look good, I'll definitely give them a read soon
Also, I would love to translate this article to Hebrew for my interactive art students - with your permission, with all credit, of course. We are just getting to this subject in a lesson or two.
Cheers,
Zvika
zvika
 
Posts: 5
Joined: Fri Nov 23, 2012 4:21 am

Absolutely. The only thing you have to do is give credit and keep the license the same. Everything on the wiki, and blog is creative commons http://creativecommons.org/licenses/by-sa/3.0/

So it can be used for commercial projects as well.


zvika wrote:Great read, thanks!
Other posts on this site also look good, I'll definitely give them a read soon
Also, I would love to translate this article to Hebrew for my interactive art students - with your permission, with all credit, of course. We are just getting to this subject in a lesson or two.
Cheers,
Zvika
ameyer
Founder
 
Posts: 3323
Joined: Thu Jan 21, 2010 11:59 pm
Location: The Bay Area

Super,
Thanks!
zvika
 
Posts: 5
Joined: Fri Nov 23, 2012 4:21 am


Hi. A great tutorial. I got one 12v halogen pulsating on and off in no time at all, and I think I learned something along the way.... Just a quick question, to check I'm on the right track for researching the next stage:

I'm trying to control lighting for a kid's activity, where they look through two way mirror at another child, and two pulsing lights, 180 degrees out of phase, are on either side of mirror. The effect is that one child begins to see the other child's face in his own, at the point where the light fades off their side and rises on the other side. It can be really effective (as long as the kids are roughly the same height!)

I'm now seeking to move on: to control the second light, have it run inversely to the first, and just wanted a point in the right direction.

Am I better off researching how to code this up using a second PWM pin? I could, say, time the cycle of the lamp, and try to write this in as a delay between setting of the first and second PWM pins.

Even better, I could explore how to invert the PWM values in the first PWM, which I guess would involve some "-255" function in a second "Sinout"

Or am I better of exploring how to physically invert a PWM signal? (A discussion elsewhere mentions 7400 (NAND) inverter.

I'm thinking of splitting the signal from one common PWM pin. One goes to TIP20 direct, and the other to an inverter and then to its TIP120.

Any thoughts on what road to start going down and researching? And what road to go down safely, given the voltages?

Again, thanks for the tutorial. (And if all else fails, at least I still have a single lamp here, dimming up and down on a most relaxing wave!)
ed101
 
Posts: 6
Joined: Sat Feb 02, 2013 5:23 am

Sounds awesome. I want pics!
You can do this in code, so easily it is crazy. You just use another PWM pin.

To invert the signal, because it is 0-255, you just need to do (255 - signal) for the other one.
So when one is 255, the other is 0. When it is 0, the other is 255.
Code: Select all
   
    analogWrite(fadePin1, value);
    analogWrite(fadePin2, (255 - value));


Here is the full code example.


Code: Select all

//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code to output a PWM sine wave signal on pin 9
//////////////////////////////////////////////////////////////////

#define fadePin1 9
#define fadePin2 10

void setup(){
  pinMode(fadePin1, OUTPUT); 
pinMode(fadePin2, OUTPUT); 
}

void loop(){

  for(int i = 0; i<360; i++){
    //convert 0-360 angle to radian (needed for sin function)
    float rad = DEG_TO_RAD * i;

    //calculate sin of angle as number between 0 and 255
    int sinOut = constrain((sin(rad) * 128) + 128, 0, 255);

    analogWrite(fadePin1, sinOut);
    analogWrite(fadePin2, (255 - sinOut));

    delay(15);
  }


}



Here is an even simpler version. It doesn't have the sine wave stuff in it.
Code: Select all

#define fadePin1 9
#define fadePin2 10

void setup(){
  pinMode(fadePin1, OUTPUT); 
  pinMode(fadePin2, OUTPUT); 
}

void loop(){

  for(int i = 0; i<255; i++){

    analogWrite(fadePin1, i);
    analogWrite(fadePin2, (255 - i));

    delay(15);
  }


}








ed101 wrote:Hi. A great tutorial. I got one 12v halogen pulsating on and off in no time at all, and I think I learned something along the way.... Just a quick question, to check I'm on the right track for researching the next stage:

I'm trying to control lighting for a kid's activity, where they look through two way mirror at another child, and two pulsing lights, 180 degrees out of phase, are on either side of mirror. The effect is that one child begins to see the other child's face in his own, at the point where the light fades off their side and rises on the other side. It can be really effective (as long as the kids are roughly the same height!)

I'm now seeking to move on: to control the second light, have it run inversely to the first, and just wanted a point in the right direction.

Am I better off researching how to code this up using a second PWM pin? I could, say, time the cycle of the lamp, and try to write this in as a delay between setting of the first and second PWM pins.

Even better, I could explore how to invert the PWM values in the first PWM, which I guess would involve some "-255" function in a second "Sinout"

Or am I better of exploring how to physically invert a PWM signal? (A discussion elsewhere mentions 7400 (NAND) inverter.

I'm thinking of splitting the signal from one common PWM pin. One goes to TIP20 direct, and the other to an inverter and then to its TIP120.

Any thoughts on what road to start going down and researching? And what road to go down safely, given the voltages?

Again, thanks for the tutorial. (And if all else fails, at least I still have a single lamp here, dimming up and down on a most relaxing wave!)
ameyer
Founder
 
Posts: 3323
Joined: Thu Jan 21, 2010 11:59 pm
Location: The Bay Area

Thanks a million!

And yeah, it might be better for me to stick to that 'Sin-less' option.... given my maths (my "-255" vs. your "255-" :D )

I'll get the second light and transistor today. I imagine though, once I get the two way mirror (that's next month), that the 'changing faces' effect will really kick in at say 20%/80% lighting either side.

If that's the case, I'll try and play with your code, and do some reading, to be able to introduce a pause of a few seconds on the way up/way down, say at 51 (20%) and 204 (80%). Guess there's loads on motor control that will get me in the right direction. I'll find out if something like below works later.)

Code: Select all
#define fadePin1 9
#define fadePin2 10

void setup(){
  pinMode(fadePin1, OUTPUT);
  pinMode(fadePin2, OUTPUT);
}

void loop(){

  for(int i = 0; i<51; i++){

    analogWrite(fadePin1, i);
    analogWrite(fadePin2, (255 - i));
  }
    delay(3000);

  for(int i = 51; i<204; i++){

    analogWrite(fadePin1, i);
    analogWrite(fadePin2, (255 - i));
  }
    delay(3000);

  for(int i = 204; i<255; i++){

    analogWrite(fadePin1, i);
    analogWrite(fadePin2, (255 - i));

    delay(15);

  }


}



Pics - of course, once it's up and running. It'll be a pleasure, if you're interested. And, again, thanks for your help.
ed101
 
Posts: 6
Joined: Sat Feb 02, 2013 5:23 am

AAaah .. I see. The delay command applies to the interval between steps 1-255. Got it! Better go learn some coding.. :o
ed101
 
Posts: 6
Joined: Sat Feb 02, 2013 5:23 am

You know,

If you changed
delay(15);
to
delay(15 + (sinOut / 4));

You would end up with the delay varying between 15ms, and (15 + 64) ms. So it would be slower in the fade at the highest points. But then shorter on the lower points of the sine wave.

Just a thought


Actually... Try this. I just graphed it out and this may work better. Replace the for loop with this. (I HAVE NO CLUE IF IT WORKS)

Code: Select all

for(int i = 0; i<360; i++){
    //convert 0-360 angle to radian (needed for sin function)
    float rad = DEG_TO_RAD * i;

    //calculate sin of angle as number between 0 and 255
    float rawSin = (sin(rad);
   
    int sinOut = constrain(rawSin * 128) + 128, 0, 255);
   
    analogWrite(fadePin1, sinOut);
    analogWrite(fadePin2, (255 - sinOut));

   //additional delay where needed
   int sinDelay = abs(rawSin * 20);
   
    delay(15, sinDelay);
}






ed101 wrote:AAaah .. I see. The delay command applies to the interval between steps 1-255. Got it! Better go learn some coding.. :o
ameyer
Founder
 
Posts: 3323
Joined: Thu Jan 21, 2010 11:59 pm
Location: The Bay Area

After a few burnt out transistors ... I was trying to push around 4A per piece (running a 50W lamp off 12V ... that was just me being greedy.....). As you say in the tutorial - when I got back to it - anything over a few amps is pushing it.

Anyway, now I have a 12V 8.5A regulated transformer, split to two BD681 transistors (the closest off-the-shelf thing I could get at Maplins in the UK to TIP120s), and I'm now back to two 12V 20W halogen dimmable MR16 downlights.


1) The code for the sine wave and its inverse, which you gave above, works perfectly. (And of course adjustable in a simple way with the delay value.)

2) The second code, without the sine wave in it, simply counting up, works too, but with the anticipated drop at 255 back to 1. Not as nice, aesthetically. But one to try out when I get the two way mirror, definitely.

3) For some reason the

"delay(15 + (sinOut / 4));"

adjustment upsets the symmetry, with pin 9 lamp on for longer than the pin 10 one. I'll get a calculator out later, to see if I can see why. But, for instance, the pin 9 down/nearly off/off time is about 2 to 3 times shorter than pin10.

4) The last sketch: I couldn't get to work, with "constrain not declared in this scope" coming up during verification.

But: thanks a million. There's a couple of good workable sketches here, adjustable with the delay function, which I can get going with to see how they work. I'll set these halogens into the canopy of a mock-up booth, with two stools, a two-way mirror, and not forgetting two victims.

In some science houses, they just have two dimmer switches in the booth, and it's up to the two kids to adjust the brightness. I'm trying to make this arcade-style push button control, so that we don't have kids playing around with dimmers, and so that the optimum lighting contrast levels are more easily achievable, so the kids don't walk away without 'getting it'.

I'll get back to you with some pics, and how I'm getting on, if you're still interested. I've got a weekend next month to build a mock up of the booth, with plexi glass and mirror film, and - now thanks to you - I've a couple of sketches to start the next stage.

You're a star!

PS If 20W lighting won't do it, or to guard against someone else putting in 50W bulbs somewhere down the line, I'll explore your high-power Mosfet tutorial as well. Frying those Darlington's yesterday was probably a good thing in the long run, though it didn't feel that way yesterday ... :D
ed101
 
Posts: 6
Joined: Sat Feb 02, 2013 5:23 am

Next

Return to Blog Posts

Who is online

Users browsing this forum: No registered users and 0 guests