Arduino varying power to electromagnet

I am working on a project, for which the ultimate goal is to be able to control an electromagnet. Basically, I combined the IR tachometer projects with the regulated positive voltage booster project:
http://www.arduino.cc/playground/Main/RegulatedPositiveVoltageBooster

I can, depending on the IR phototransistor state, get the outgoing current to alternate between 9v and 20v. I could go higher, but I need to work on my homemade inductor. I have tested the output with a DMM, so I am confident that the voltage is being boosted.

Ultimately, I'd like to use this for a kind of parlor trick, where I can use different IR sensors to varyingly attract - and if possible repel - other (natural) magnets. The coil of the electromagnet would be connected to the Vout in the diagram.

I have tried it with some quick-and-dirty homemade wire-wrapped electromagnets, and the result is nominal. There is very little difference between 9v and 20v, and it doesn't appear that there are "poles" to the electromagnet. My next step is to make a better magnet coil!

Looking longer term, keeping mind that Priority #1 is to not fry my one and only Arduino, is there a way to use a MOSFET to increase the voltage boost, reverse the polarity, and switch faster between the high and low voltages? (At some point, I may introduce a medium voltage, but that isn't as important right now.)

And, at the risk of going too far into electromagnetism, I have a couple "tube" magnets that I could put a coil around. There is room in the core for a bolt, too. Would it be more effective to wrap those, maybe with a core? Or should I get a cylinder magnet and wrap that?

Thanks!
T

Edit: oh - point of clarification. The only 220 Ohm resistors are on the LEDs. The others are 1M, 100k, and 1k, consistent (mostly) with the Regulate Positive Voltage Booster project. I posted a bit more on this here:
http://arduino.cc/forum/index.php/topic,94550.0.html

...get the outgoing current to alternate between 9v and 20v.

You are confusing current (Amps) and volts. do you have a multimeter/ If you measure the voltage across the coil, I'd be surprised if you are really getting 20V. I'm guessing that your voltage multiplier can't put-out the needed current when there's 20V across the coil.

Electromagnets and solenoids work from current. The magnetism is related to current and the number of turns. The current depends on voltage ane the resistance of the coil. The relationship between voltage, resistance, and current is defined by [u]Ohm's Law[/u]. (One volt across a 1 Ohm resistance results in current flow of 1 amp., etc.)
> Looking longer term, keeping mind that Priority #1 is to not fry my one and only Arduino, is there a way to use a MOSFET to increase the voltage boost,
Yes. A MOSFET can help to protect your Arduino from excess voltage or current. I don't have a handy link to a schematic, but I'm sure someone else can help with that.
> At some point, I may introduce a medium voltage, but that isn't as important right now.)
** That would require 4 MOSFETS in a bridge configuration, or two MOSFETS if you have + and - voltages available from you power supply.**

Excellent points!

Indeed, I did confuse volts and current (amps)! But, in looking at it, if the resistance is constant (all the pieces of the circuit are the same), and the volts go up (they did), doesn't that require that the amps increase, too?

Let's ignore the "medium" for now. :slight_smile: My limited understanding tells me that the MOSFET should either replace or work with the 2n3904 NPN.

But, getting back to priority #1 (not frying my Arduino) :slight_smile: I look forward to more information on how to accomplish it. I would be happy to either increase the boost with the MOSFET, or do quicker switching.

Thanks again!

Indeed, the voltage is the same on both sides of the electromagnet, a bit over 20v. I can't connect the ground to the Arduino, otherwise it resets. :astonished: Also, the amps, although quite small, does increase through the voltage booster circuit.

I tried a couple different handmade coils last night, but with no real success.

Still looking for help on the MOSFET, or anything else electromagnetic-related. :slight_smile:

Ok, I realize now I may have a forest-for-the-trees problem!

I started with the notion that the EM needed volts. So, I found a voltage booster!

Alas, I now know that EM needs amps. My prior design had VERY minimal amps.

But, upon further research, the Uno vcc can output 200 mA. That would be WAY more than I currently have.

So, can I run straight from the 5v out, to a transistor (? NPN? MOSFET?), with one post connected to a pin ( PWM? Analog?) to switch the amps from a low setting (maybe 20/40 mA) to a high of the 200 mA, or thereabouts?

I've done some looking around in the Playground, but can't find anything that looks immediately applicable.

TIA

(Also, apologies if self-replying is frowned upon here. I've been on boards where that was a serious no-no!)

But, upon further research, the Uno vcc can output 200 mA.

Where does it say that then?
If you are powering it from USB you can draw 500mA from the 5V supply. If you are powering it through the power jack it might be a bit higher.
You will not get a very strong magnetic field from such a current, what are you hoping to drive with it?

Not really trying to "drive" anything, just trying to make the strongest electromagnet I can, and then switch it from the strongest to a weaker state, possibly rapidly. :slight_smile:

Ideally, it would rely solely on the power/current from the Arduino itself. But, I'm also willing to look into using a DC wall wart or battery pack, for testing purposes - dedicated to the electromagnet. Long range, the idea would be to take the circuit and programming prototyped on the Arduino and create a custom board.

The parameters, really are:

  • strongest electromagnet possible with the Arduino; and
  • have the Arduino switch the electromagnet between a high and low setting.

Oh, over-riding consideration though is to not fry the Arduino. :slight_smile:

Edit:
Perhaps a bit more elaboration is necessary. :slight_smile: The idea I have is something like this....

Imagine a perfectly flat/level board, and put a pinball in the middle. Flat and level means it doesn't roll. Now, place a frame around the edge of the board, which of course has nails or screws. Nearby, there is a discrete IR phototransistor. One of the nails/screws is actually an electromagnet, tied into the IR phototransistor. Now, imagine if you had a flashlight that emitted in the IR frequency that could be picked up by the IR phototransistor. By flashing the transistor, you could "turn on and off" the electromagnet. The ball might appear to move.

Now, if you had 4 (or more) such devices around the board, you could get the ball to move all around the board.

This is just an idea, of course. But, it seems like it should work!

Not really trying to "drive" anything,

Yes you are you are trying to drive a coil.
Drive is the term in electronics for controlling something.

Ideally, it would rely solely on the power/current from the Arduino itself.

Well the power always comes from elsewhere. Directly from the arduino output pins you get very little.

The ball might appear to move.

That requires quite big magnet. The problem is that the metal ball has to get a certain force to over come its inertia. This is more than the force needed to make it move. A magnetic field drops of with the inverse cube of the distance. That means at very short distances you have a strong force but not much force at all as the distance increases. I know it was just an idea but don't let all those road runner cartoons fool you about how a real magnet works. :slight_smile:

For a start try and influence the pointing direction of a compass needle. get a feel for what current will do what in terms of a field. Only then when you know what you want to do worry about how the arduino is going to drive that amount of current and the voltage needed to push that current through the coil. Remember the more turns the more magnetic field, but the more voltage you need to push the current through.

Excellent points!

I've made some headway using the Playground project of the Positive Voltage Booster, and can get a minimal electromagnet out of that. This is about 50+ turns around a long nail, just to get an idea. With this system, I can get 20 volts to it, but an insignificant amount of amps (the DMM read < 30 mA IIRC).

I have other ideas on how to make the ball move :wink: but for now, I'm trying to just make the strongest electromagnet I can. Much of the design will follow from that!

What's the best way to connect the v out from the Arduino, more or less directly to the coil, then back to ground, without releasing the magic smoke? :slight_smile: Put the resistors "between" the EM and ground, to test without the switch, just to see what strength of magnet I can get?

I would use a transistor to switch the current. Then you can get as much as the supply will give you and the arduino will be safe.
At this stage there is not much point in trying to generate a higher voltage because I don't think you will have enough turns on the coil to limit the current with just a 5V supply. You might want to look at a relay or solenoid as a source of a ready built coil with lots of turns.

Just put a current meter in series with the coil and connect it directly to the supply to start with and see what current it takes. Alternatively measure the resistance of the coil and calculate the current with various supply voltages. A series resistor will limit the current but also limits the magnetic field you get.

Excellent - and a quick (probably stupid) question, just to make sure I understand the starting point.

I have a wire from the 5v out to the breadboard, and a wire from the Arduino gnd to the breadboard gnd. I go from the "hot" wire to one end of the coil around the EM. I put the other end of the coil to a wire leading into the breadboard gnd. (I know the breadboard is optional, but eventually, I will want use it to test various switches, etc.)

Thanks for helping!

Yes that sounds fine. Good luck.

Thanks (I may need it)!

Also, the reference I used for the power outputs was:
http://arduino-info.wikispaces.com/ArduinoPinCurrent

Thanks again!

Also, the reference I used for the power outputs was:

Bit controversial that 400mA of sinking claim. I think you misunderstand what that means. It is the total from all pins with any one pin not exceeding 40mA. But there are other restrictions as well that will limit this further.

Well, I'm going to take some measurements just off the DC current out/ground. Unless... that is something other than the 5v out? :fearful:

Yes it is different.
The current through the ground lead is the current the device is sinking. The current into the +5V processor line is the current the processor is sourcing.
I don't see how you can measure either of these currents without hacking the board to pieces.

haha

I think I'm using terms incorrectly. Thank you for your patience.

On the Uno, there is a 5v "out" pin (next to a 3.3 pin). Next to the 5v out pin are 2 ground pins. If I put a jumper in the 5v out, and a different jumper in the ground, then use a multimeter between the two, can I safely determine what mA it is putting out?

Now I'm scared to even try that!

You should be using the Arduino to -control- a much stronger power supply, not using the Arduino -for- a power supply.

To move a ball bearing around from anywhere but real close using wire wrapped around nails is going to generate a lot of heat in that wire. Think about how and where you're going to sink that heat.

If I put a jumper in the 5v out, and a different jumper in the ground, then use a multimeter between the two, can I safely determine what mA it is putting out?

Basically no.
To measure current you must have a meter in seriese with the current path. It is the pins of the chip that actually source and sink the current. So you must put the meter in line with the signals from the chip.
I think you are getting confused with the total current in any chip lead and what you are driving.

A wee update. :slight_smile:

I've worked up the electromagnet to a point where it can get a metal ball moving from a couple centimeters away, with power supplied directly from a battery pack of 4 AA batteries. Ordinarily, that would be ~ 6v, but, since I've basically short-circuited it several times in testing the magnet, it was testing down at 4.4v. XD The resistance of the EM coils drops the voltage down to < .5v measured.

I am now at a decision-point.

Option 1: hook it straight up to my previously working 9v/20v solution powered solely from the Arduino's 5v output. Somewhat reluctant to do that, because I think the Arduino had a problem grounding the 20v power output.

Option 2: hook the circuit up to an external 9v (or larger) battery, and only use the Arduino to do the voltage management, not the voltage output. I realize this is starting to look much like the solenoid project, so I will also refer to that, but I wanted to see if anyone had any guidance for potential issues with this option.

Again, longer-term, I'd like to have the Arduino powered from the same source that goes to the EM. But, I'm taking "baby steps" here. :slight_smile:

TIA!
TL