I need to control an electromagnet via USB with an android phone, to make a small educational project.

I know how to write the software, but how can I control an electromagnet via USB?

Via an USB Relay? Any suggestion?


This may be overkill for what you want, but Microchip do an Accessory development starter kit for Android.

enter image description here

With that you can create anything you like to interface with your Android phone. You can even use Arduino shields with it!

To this you would need to add something to actually drive the electromagnet. You might like to check out the many tutorials online about interfacing motors and solenoids to the Arduino, as the same applies to this board.

Most commonly either a transistor, or transistor pair (known as a Darlington Pair) is used, depending on power requirements. These are also available in an IC form, such as the popular ULN2003 chip with 7 Darlington Pairs in it.

I have created an Arduino shield that contains an 8-channel Darlington IC, the ULN2803, which you can etch yourself using Toner Transfer. The details on it are here.

Shameless self promotion there :)

  • \$\begingroup\$ this seems to show a board for interfacing to android, not really answer the question of how to control the magnet. \$\endgroup\$ – Kortuk Oct 29 '11 at 10:06
  • 1
    \$\begingroup\$ A device will be required to interface the magnet to the android device. That is what this board can do. If you go to the site linked you can see that there is a video where they demonstrate it interfacing the LEDs on the board to the Android device. Just replace "LED" with "Electromagnet" and some driver circuitry (say an off-the-shelf arduino shield) and bob's your uncle \$\endgroup\$ – Majenko Oct 29 '11 at 10:27
  • \$\begingroup\$ sounds like a good thing to add to your answer, maybe explaining that step also? \$\endgroup\$ – Kortuk Oct 29 '11 at 10:44
  • \$\begingroup\$ This is most probably true. Done. :) \$\endgroup\$ – Majenko Oct 29 '11 at 11:16
  • \$\begingroup\$ And there are more Android Accesory development boards. For example Arduino Mega ADK — labs.arduino.cc/ADK/Index and SparkFun.com has board named IOIO — sparkfun.com/products/10748 \$\endgroup\$ – vasco Oct 29 '11 at 17:19

You would need to use a USB capable microcontroller or something like an FT245 USB to parallel in order to connect and receive commands from the host properly.

Then simply trigger a pin to turn on the base of a suitable transistor/relay and activate the electromagnet.

Here are a couple of useful FT245 related links:
FT245 bit bang document
FT245 based relay driver
cheap FT245 "breadboardable" module

EDIT - note the FT245 solution will only work if the Android can be used as a host. From a quick google I found this page which says version 3.1 and higher support host mode. YOu would have to check for you particular device on the specifics. There are quite a few threads out there about doing things like connecting a keyboard to androids.
Otherwise a uC (e.g. PIC24/32) could be used as a host.

  • 1
    \$\begingroup\$ This would only work on android devices that have USB 2.0 OTG capability - which older ones don't have. \$\endgroup\$ – Majenko Oct 29 '11 at 9:45
  • 1
    \$\begingroup\$ @Majenko - you're right, if the OPs android doesn't have host capabilities then they will have to use a uC as a host I guess. I have not actually got my hands on an Android yet :-( \$\endgroup\$ – Oli Glaser Oct 30 '11 at 17:04

IOIO is smaller, cheaper and easier to work with than adk's. It will also work with any Android version (as opposed to 2.3.4+) and supports both USB or Bluetooth connection to Android.

  • \$\begingroup\$ Can you give us links, pictures and explanation of things like, "easier to work with then adk's"? With that you will receive my upvote. \$\endgroup\$ – Kortuk Nov 3 '11 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.