Introduction: Simple Solenoid Using Arduino

Picture of Simple Solenoid Using Arduino

This by far the simplest way to weakly magnetise any object using your Arduino uno. All it takes is a lot of wiring and coiling, and a program to do the trick. In fact, it takes just two steps to program an Arduino to turn it into a solenoid.

Step 1: Program the Arduino

Picture of Program the Arduino

Here is one program that you may use to make a solenoid out of an Arduino:

void setup() {




void loop() {








by changing value of delays, one can change frequency of alternating current hence you can test whether lower or higher frequencies magnetise the best or not. Upload it onto your Arduino board using the IDE.

Step 2: Making the Coil

Picture of Making the Coil

based on the program, you may have to take a very long piece of Insulated, Single core, Copper wire ( commonly called enamelled wire) and wrap it around the metallic object that you wish to magnetise.

Caution: the current in the coil must not exceed max current output limit for the pins (40mA). Since the Digital pins also provide 5V of electricity, the ideal resistance of the coil must be less than 125 ohms so that the current in it will be 40mA. You can use a multi-meter to find resistance of coil and if it is too high, you can shorten length of wire used.

it is best to make as many coils as you can fit around the object. one of the wire may the be connected to digital pin 10 on the Arduino while the other of the coiled wire may be connected to digital pin 11 on the Arduino. And... Violà! your solenoid is good to go. :-)

Note: remove object from coil only after you have disconnected coil from the aduino.


DIY Hacks and How Tos (author)2016-06-08

Keep in mind that you don't want to exceed the max current output limit for the pins (40mA). So you need make sure that the total resistance of the solenoid is at least 125 ohms.

Thank you for the helpful input. I will make a note of that in the instructable as soon as possible.

mstone25 (author)2016-06-08

Also the wire you show at the bottom is useless for winding coils as it is not enameled. Each winding would short to the wining next to it.

trackx (author)2016-06-08

And dont forget the BEMF, the Voltage Spike will (eventually) kill your Arduino too...Insert a Diode in parallel to the coil. Dont tell People, how to mess up things...

About This Instructable




More by KaushikMehul:Simple Solenoid using Arduino
Add instructable to: