hi, i am working on a project to levitate ball bearing using an electromagnet. I need to vary the current going to the electromagnet for this and am using an arduino. Is there a way to control the current in the circuit using the arduino?
Yes, but by the time that you add everything that you need, then you may as well dispense with the Arduino.
You will need a way to control the current, and you will need a way to sense the current.
Most (all?) Arduinos do not have a DAC, in which case you will have to use PWM from your Arduino to control the current. This may be sufficient for the described purpose.
You could measure the current by inserting a low value (say, 0.1 ohm) resistor between the coil and ground. The voltage at the junction of the coil and the resistor would be a measure of the current. Of course, you would have to limit the voltage supplied to the coil so that you do not exceed the voltage limitation of the Arduino.
You could vary the current to the coil by using a transistor to control the current to the coil, and using the Arduino (and a resistor) to drive the transistor. The resistor value will depend upon the transistor, and whether one side of the transistor is connected to ground or to the power supply. A relay shield or a motor shield may work for this purpose instead of the transistor and the resistor.
Of course, you do not really need to measure the current. It is more important to measure the position of the ball bearing.
Thanks for the reply I will look further into those methods
He'll still need something to provide logic and control... but generating a variable current will require considerable external hardware. Luckily, this has been done before; I've seen a few people talk about similar things. See what they did, no need to reinvent the wheel.
What do you mean by "provide logic and control". I have currently a controls strategy using PI and P controllers but I still need to figure out how to increase decrease current after recieving the error demand from the feedback.
You only need to measure the current if you care about the current value. Since the current is a means to an end for levitation, the only thing that needs to be measured is the position of the ball bearing. Then the control loop can increase or decrease the stength of the magnet as needed to hold the ball's position.
PWM will be the easiest way to modulate the electromagnet's field, though you should probably increase the default 490 Hz frequency so that there's less current ripple.