electromagnet

Hi, I'm new to Arduino. I'm looking to get some advice and help on how to create a computer controlled electro magnet. I have the Arduino receiving serial input to turn on and off a digital out pin and I've tried to link this up to an NPN transistor that will switch on an off the current to the magnet. I've drawn the basic schematic here:

I have a few concerns. First, this circuit isn't working. Even when I use something more detectable like a LED or a small DC motor it doesn't appear to function. What am I doing wrong? Second, I'm not entirely sure this us safe to hook up. Is it sufficiently decoupled from the arduino board? Last, the magnet is basically shorting the battery and will pull max current. I've tried putting a 110 ohm resistor inline but that was enough to drop the current so low that the magnet didn't function. Should I use a bigger battery, and if so... how can I preserve it's life. Also, will PWM work for an electromagnet.

Thanks in advance.

Also should have stated that the GPIO on 13 is HIGH. The LED on the board verifies this.

What kind of transistor? A 1.5V battery is pretty low in voltage to be switching this way; a typical transistor will lose .3V or so, and a "darlington" (which is common for power switching) will lose about 1.2V, which won't leave very much left for your electromagnet (or for an LED, which will usually need at least 2V.)

I was using a PNP transistor. I started to measure voltage now -- still not having much luck. I did read about the Mosfet transistor and I tried one of those that seemed to work somewhat with a DC motor. After I turned the output pin to LOW the motor would still run. I would slow down some until I touched either the top of the Mosfet or the diode. I was using the schematic presented on page 41 of the handbook in the guide section. Has anyone gotten this to work?

Also, I've hooked the electromagnet up to a DC powersupply at 12v 1000mA. At least that is what the box from radioshack said. Still no dice. Infact, the magnet appears to be turning on then off when plugged in directly to this powersupply. The battery maintains a constant connection. Not sure why.

A quick and practical fix, is to use a 5v relay, it'll solve any messing around with tranny's. You might want a second electromagnet to determine if the one you've got is faulty. Also meter the supply and make sure it's not AC.

Excellent! Relay's rule! Picked up a SPST 5vdc reed relay today and it worked like a champ. For simple on-off circuits with very low resistance I think this is the way to go. I would still like to know two things. First, why did my DC power supply (which I verified was outputting DC) cause the magnet to turn on then off? It works like a champ with a 1.5v AA. Perhaps the DC adapter has some switch to turn off when current jumps about a certain amount? Anyone have experience with this? Second, why did it fail with a transistor? Is there some key piece of knowledge about the base pin that I don't know about? Finally, I've made my own electromagnet with some copper wire and an iron nail... how long can I expect a standard AA to last when shorted out by the magnet, and is there anyway to increase the battery life?

Thanks for the help.

I am going to experiment with PWM and DC motors next -- driving the speed. I think I may want to use an external power supply for these as well. Using a relay for that is out of the question.

Lots of people attempt to use transistors for switching larger power supplies, I can't recall one that's reported any considerable amount of success - otherwise I'm sure it would be filed under memorable achievements in the playground, that's why I got 50 x 5v relays off eBay, relays do everything, keeping Arduino nice and safe.

Don't know what the issue is with your DC, I was hoping you'd answer that one, I need to rig an electromagnet via relays as well, and I don't want to be using batteries either :)

Post back when you have our solution ;D

I was using a PNP transistor.

Your schematic shows an NPN, and if you were to put a PNP in the same place, your circuit would be wrong. Normally NPNs (as you show) are inserted in between the load and ground, and turned on with +V, while PNPs are inserted in between the +V rail and the load, and are turned on by GND (but will expose the pin to V+ - Vbe, which is not good if you're swithing high voltages with a 5V micro.

Most voltage regulators have "over current" and "over temp" protection, and will turn off (or "something") if you draw too much power from them...

Try a pin other than 13 for the transistor. Depending on the version of the Arduino board that you have the resistors for the LED may mess up other electronics. Same thing goes for pins 0 & 1. Kirk PS Fixes for the NG board have been posted, but I can not find them. :-(

Oops, I meant NPN. Drew it correct but wrote it wrong. Thanks for the catch.

I'll give pin 12 a shot tonight. I was aware that 13 had a 1K resistor added already but didn't think it would make a difference. I also had a friend (computer engineer) suggest that the problem was that I was not using a common ground. I am going to try connecting the negative side of the AA battery to the Arduino ground.

Yep have it working with the transistor now!!!!

Circuit is exactly the same as above except there is a line between the negative side of the AA to the Arduino ground. Worked on both pin 12 and 13 - W00T.

Ok, I think I saw smoke. I use the above circuit but I wanted to test if I could put a small resistor inline with the magnet. So I hooked it back up to my 12vdc 1000ma power source and I really hope it was all in my mind but I think it was coming from the arduino. Everything appears to be working. I can upload new code, serial connections are fine, and the circuit seems to work with the same transistor and diode. If I burned out something on the Arduino what could it have been?

I used a 15 ohm resistor and even that seemed to be enough to prevent the magnet from holding a small screw.

A 1ohm resistor allowed the magnet to function but it got very hot a 10 ohm got just as hot and the magnet didn't function with 1.5v AA or 3v 2xD cell's.

Does anyone know if I can use a 555 timer to run an electromagnet? I'm just trying to increase battery life.

Ok seriously: get on the Google machine. it's all there waiting for you, in two flavours: opticallly isolated MOSFET, or NPN Darlington transistor. Just follow the directions and it will work perfectly.

http://www.arduino.cc/playground/Learning/SolenoidTutorial http://www.arduino.cc/playground/uploads/Learning/solenoid_driver.pdf

Ok seriously: get on the Google machine. it's all there waiting for you, in two flavours: opticallly isolated MOSFET, or NPN Darlington transistor. Just follow the directions and it will work perfectly.

http://www.arduino.cc/playground/Learning/SolenoidTutorial http://www.arduino.cc/playground/uploads/Learning/solenoid_driver.pdf

Thanks for the links.

I've seen those before. What I was missing was a common ground. Two questions still. Can you tell the difference between an NPN switching transistor and a NPN Darlington transistor? Wasn't immediately obvious from a quick Google search. Also, is the optically isolated MOSFET better (ie safer) than a 5vdc relay?

Thanks

Answered some of my own questions: http://www.kpsec.freeuk.com/trancirc.htm has a great information on transistors. Though, I am not certain why one should use a Darlington over a single NPN. And I still don't know the best way to preserve battery life when using an electromagnet.

why one should use a Darlington over a single NPN.

I believe its because its they can handle a large current and they dont need much to turn on.
Like a low power relay or something. I dont know too much in that area myself.

And I still don’t know the best way to preserve battery life when using an electromagnet.

A electromagnet is a power hog. Best solution is to turn it off when its not needed. :slight_smile:

In a related vein, would I need to use a circuit like this to provide current to a small lightbulb, or is there a simpler way?

(I've searched around, and found information on powering motors and the like, but nothing about the power requirements of a simple lamp. I blew up a couple of transistors a few months ago, while taking my first tentative baby steps with electronics, and decided that LEDs were the light source for me. Now, though, I have need of a light bulb...)

a Darlington is two transistors combined in one package, to provide additional gain. http://www.google.ca/search?q=darlington+transistor

One transistor = a gain of say 100 Two transistors = gain of 100 X 100= 10,000.

So with a Darlington you only need, say, 1ma base current to switch 10 Amps through its collector. Try a TIP102. Download the datasheet and look at the suggested applications section to get an idea of how they're used.

You will not be able to "conserve" much with an electromagnet running on batteries: the current requirements of electromagnets are large. The optoisolator in the link above is used to provide optical isolation between the driver circuit and the power output circuit. That way, the significant noise and voltage spikes that occur when you switch an inductive load wion't feed back into the sensitive microprocessor circuitry.

PS your original circuit has no base resistor, it needs one; the original circuit also uses a PNP, which as someone says above, means you will only be able to get the base to 7V (12V - 5V), and it will never turn off. You;re also putting a ice noisy shot of 7V on the Arduino pin, which could well fry the output as it is beyond the Atmega's specs.

Try those diagrams, they work perfectly.

D