How To: Electricity/Electronics for Hackers: Basics: Part 4 (Electricity & Magnetism)

Electricity/Electronics for Hackers: Basics: Part 4 (Electricity & Magnetism)

Hello again, fellow hackers and electrical engineers! As many of you understand by now, knowing electronics is not really a required skill for hackers, but it will most certainly come in handy and may save you a lot of time!

But before we can design cool circuits like an EMP or signal scrambler, we still need to cover some theory. Today we will talk about electromagnetism and electromagnetic induction. These 2 laws in electric science can be found in almost everything: from every electric generator, electric motor, and transformer out there, to every form of wireless communication, your phone charger, and even your computer's power supply, all depend on either electromagnetism or induction. In most cases, both of them!

Today, I want to cover how these 2 fundamental laws of electric science work exactly, up to the atomic level, because we will need this in a lot of our circuits.

The Basics of Magnetism

Before we can move to electromagnetism, we need to know the basics of magnetism first. I suppose you all know what a magnet is, so I will skip that. Instead, I will cover how a magnet works.

As you all knew from elementary school, a magnet is something that either attracts, or repels a metal or another magnet. This is caused by the 2 points of maximum attraction on the magnet, called poles. There are 2 poles on a magnet, the north and the south pole.

The reason these are called north and south is because the north pole of a magnet is attracted to the earth's magnetic north pole, and a magnet's south pole is attracted to the earth's magnetic south pole. This is how a compass works: a compass needle is simply a magnet that alligns itself with the earth's magnetic field.

Let's have a look at a magnetic field. N is the north pole, S is the south pole. The black lines with the arrows represent attractive (or repulsive) force. These "lines" are called the magnetic field.

Image via

As you can see, most of the attraction is at the ends of the poles, and there is 0 attraction in the middle of the magnet. Take note that the attractive force "moves" from north to south!

Now, let's put 2 magnets next to each other with the opposite poles next to each other, and let's see what happens to the magnetic field:

Image via

As you can see, the magnetic force moves from the left magnet's north pole to the right magnet's south pole, which means the two magnets attract each other. With this knowledge, we can say that the following statement is true:

Opposite poles attract each other.

Now, let's do the same, but instead we'll put the magnet's north poles next to each other. Let's see what happens to the magnetic field:

Image via

As you can see, the arrows of the magnetic field point in a different direction. This causes repulsion. With this knowledge, we can say that the following statement is true:

Same poles repel each other.

I think we've seen enough of normal magnets for now. If you have any problems understanding how magnetism works, don't be affraid to ask for help in the comments!

Anyway, let's move on to electromagnetism!


Electromagnetism is pretty simple. Basically, it means that we create a magnetic field using electricity. The basic law of electromagnetism goes like this:

Every conductor that carries an electrical current produces a magnetic field around it.

This can be easily represented using this picture. I is the (conventional) current flow from + to -, and B is the magnetic field.

Image via

Take note that the magnetic field "B" has no polarity. The magnetic field is too weak to have a solid polarity.

Note: This magnetic field technically does have a polarity (at the + and - side of the battery), but we simply chose to ignore it and place a circular magnetic field around an uncoiled conductor.

We do have a way to increase the strength of an electromagnetic field, though: by winding wires in loops together. This is called a coil. Here is an example of a coil, connected to a battery.

As you can see, the side of the coil that is connected to the positive terminal of the battery (remember, a long vertical line = positive, short vertical line = negative, as explained in this article) is the north pole, and the side connected to the negative end of the battery is the south pole. This means that:

+ = N
- = S

With this knowledge, we can construct our own electromagnet.

Constructing an Electromagnet

Here we are at last: time to construct our very first device! We just learned the basics of electromagnetism, and now we'll be making our own electromagnet! But what is an electromagnet?

An electromagnet is a magnet that runs of electricity (you don't say). It's basic construction is a coil wound around a soft iron core (in our case, it will be a regular nail). The coil is then connected to a DC (or AC in some cases) power source, which then magnetizes the core as long as there is a current flowing through the coil. The advantage of this method is that you can decide when the magnet is active. The electromagnet is used extensively in industry, to move metal scrap or other things. Here is an example:

Image via

We are going to construct a less powerful version of this, but it will still work using the same principles. Our electromagnet will be a lot similar to a classic bar magnet. Here you can see how likely they are (left is our electromagnet, right is a classic bar magnet).

Images via,

The reason our electromagnet has no polarity indicated, is because the polarity will differ on how you plug the battery on the coil. (remember, + is north pole, - is south pole). Anyway, let's get down to construction! Here's what you'll need:

A spare 1.5V AAA battery.
A nail (or any other circular soft iron object) of about 10cm long.
A piece of wire (30-45cm long).
Paperclips (to attract with our electromagnet).

Before we start, some safety tips:

1.) Do NOT use the electromagnet for longer than 30 seconds! We are causing a short circuit here (the length of the wire is too short to have any decent resistance), which causes the battery to heat up pretty quickly. To prevent exciting fires and explosions in your hand, you should let the battery cool down after powering the electromagnet for 30 seconds!

2.) Make sure you use an alkaline battery! Like I mentioned above, we are creating a short circuit. And Ni-MH batteries aren't as robust as short circuits as classic alkaline batteries. So make sure to only use alkaline batteries for your own safety!

Now, here is what you need to do:

Step 1: Wind the Wire Around the Iron Core

The first step would be to wind our piece of wire around the iron core, in my case a nail, so that we will get a coil around it like shown in the image above. The winding doesn't have to be neat, but keep the following in mind:

1.) Keep winding in the same direction (don't overlap)!
2.) Make sure that you leave the ends of the nail empty!
3.) Make sure you leave 2 ends sticking out from the coil!

Here is how my electromagnet looks like:

If yours looks like this, it should work fine.

Step 2: Strip the Ends of the Coil and Connect the Battery

Now we'll power up the electromagnet. First of all, strip the ends of the wire (like shown in the picture above) so that the battery can connect. Next up, hold both poles of the battery against the stripped ends of the coil. When you hold one of the empty ends of the coil next to a paperclip, you'll noticed it attracts!

Congratulations: you've just successfully constructed the "hello world" of the electrical engineers! The side of the nail to which the + of the battery is pointed, is the north pole of the electromagnet, and vice versa. You can check this with a compass.

"So I Powered the Electromagnet a Few Times and My Nail Has Become a Magnet... Phoenix, What Have You Done?!"

Have no worries, this is completely normal. It's a process called "magnetization".

What this basically means is that the nail "remembers" the electromagnetic field created by our electric current, and thus becomes magnetic itself. This is how classic bar magnets are made: they are exposed to a strong magnetic field, and thus become magnets themselves.

Since the magnetic force our nail has been exposed to is still considerably small, the effects of magnetization should decay in about half an hour. If you're not willing to wait, you can try something called "demagnetization".

To achieve demagnetization, simply plug the battery back in, but reverse the polarities. This way, the nail will be exposed to a new magnetic field with opposite polarities, and thus it will reduce the effect of the previous magnetic field. If timed correctly, you can even completely mitigate the magnetization!

Alright, we've spoken enough about magnetism, let's get to electromagnetic induction!

The Discovery of Electromagnetic Induction

We already know that we can create a magnetic force out of electricity. But what the famous scientist Michael Faraday wondered in 1831 was: "If it is possible to get a magnetic force out of an electric current, is it also possible to get an electric current out of a magnetic force?". To test this theory, Faraday built a device named "Faraday's iron ring of induction".

Image via

Faraday's iron ring of induction consisted of a battery (left), a "primary" coil winded around the iron ring on the left side, a "secondary" coil winded around the iron ring on the right side, and a galvanometer (a galvanometer is a special measurement instrument that can read both positive and negative values).

When Faraday connected the battery to the primary coil, he noticed that his galvanometer would suddenly shoot up in the positive range, and then go back to the value of 0. When he disconnected the battery, he would notice that his galvanometer jumped again, but into the negative value! Faraday had discovered that it was possible to get electricity out of a magnetic force!

Faraday continued with his experiments, and he noticed that if he slipped a bar magnet in and out of a coil quickly, his galvanometer would oscillate between positive and negative. Faraday had just discovered a new type of electricity: alternating current.

Even today, the only way to generate AC (the electricity that drives our homes and industry) is through electromagnetic induction.

Faraday continued, and produced the very first electric generator in history using his discoveries called "Faraday's disk". Until then, it was only possible to get electricity out of cells (batteries). Faraday's disk was the first device capable of converting kinetic energy directly into electric energy, and is the grandfather of all AC and DC generators in existence today!

Image via

What Is Electromagnetic Induction?

Now that I've talked a little about how Michael Faraday discovered electromagnetic induction, I think it is time to talk about the phenomenon specifically. I won't get into the mathematical side because even I don't completely understand it, so I'll just cover what it is, when it occurs, and some practical examples. Here is the definition of electromagnetic induction:

When there is a change in the magnetic flux, a current is induced in the object affected by the magnetic field.

But what is magnetic flux? In a simple way, it is the name we use to indicate the impact of a magnetic field on an object, in this case, it would be the secondary coil on Faraday's ring of induction.

Magnetic flux is the product of the strength/direction of the magnetic field, and the place of the object within the magnetic field. To get induction, we need to make a change in one of them. We need to either increase/decrease the strength of the magnetic field, or we must make the object within the magnetic field move.

Induction Through a Changing Magnetic Field

In Faraday's iron ring of induction, there is electromagnetic induction because the magnetic field on the primary coil changes. Remember that magnetic flux is the product of the strength of the magnetic field and the place of the object within the magnetic field, so if we get a change in one of those, we get a change in magnetic flux, and thus we get electromagnetic induction!

When Faraday closed the switch to the primary coil, the magnetic flux on the secondary coil changed, because there suddenly was a magnetic field created by the current in the primary coil. This induced an electric current on the secondary coil.

After a while, there would be no change in magnetic flux anymore, so the induction would cease.

When Faraday opened the switch again, the magnetic field would suddenly disappear. So there was a change in magnetic flux, and thus we got induction! However, since this was the opposite of what happened during the first induction (which caused a positive "spike"), we get a negative spike this time.

Induction through changing magnetic fields is widely used. For example: radio, Bluetooth, Wi-Fi, and pretty much any other wireless form of communication! The transmitter produces a changing magnetic field with a modulated message in it (we'll learn what modulation means later), and the receiver detects that changing magnetic field through electromagnetic induction. I'll write an article later about the fundamental technologies of wireless communication, so stay tuned!

Another widely used application of induction through changing magnetic fields is the transformer. I'll also explain how the transformer works later, but know that it relies on electromagnetic induction to work. And without the transformer, the power grid as we know it today wouldn't exist!

Image via

Induction Through Movement

As we know already, we need a change in magnetic flux to get induction, and there are 2 ways of accomplishing this: either get a change in magnetic field strength, or create movement!

Now in this case of induction, we can either move the object, or move the magnet itself. Both will cause a change in magnetic flux.

Image via

As you can see, if we move the south pole in the coil, we get a negative current (remember that S is equal to -), and if we move it out, we get a positive current.

Induction through movement is used in all generators on earth. A magnet is rotated, which induces a current in the coils of the generator, generating AC.

Here in this gif, you can see how a 3-phase alternator works, the workhorse of the power generating industry.

As you can see, when the N and S poles align with the 2 coils of phase A, phase A reaches it's amplitude. The same goes for phases B and C.

What Causes Induction?

Now you all might be asking: "What exactly causes induction"?

To keep things simple: when a magnetic field passes by a conductive material, the electrons "break loose" from their core and start flowing in an organized manner. This is electrical current. However, after a while, the electrons will "fix" themselves and get back into place: the current stops.


That is it everyone, I hope you enjoyed the long read. If you have any questions or problems, feel free to PM me or comment down below! I'll reply as soon as I can!

Now, before I finish, I'd like to point out how important induction is, because we hackers can learn from Faraday's way of thinking. Without induction, we wouldn't have:

  • The modern electricity grid
  • Wi-Fi, Bluetooth, radio, and all other forms of wireless communication
  • Generators
  • Microphones
  • ...

As you can see, induction is VERY important in our world. If Michael Faraday didn't ask himself if it was possible to get electricity out of a magnetic force, OTW wouldn't be teaching us Bluetooth and Wi-Fi hacking. In fact, you wouldn't probably be reading this!

Electromagnetic induction was born from a simple question: "is the opposite of electromagnetism true". Faraday asked himself one simple question, that in turn changed the world we live in today. Which brings me to the moral of this:

No matter how simple or illogical your idea or question may seem, don't stop wondering. You have no idea what of an impact it will have!.

So keep coming back, my fellow hardware hackers, as we continue to explore the world of electricity!





Nice post! Can you please make a post about rfid hacking ?

I'll look into that.


I have been thinking about electricity and electronics for some time and though I am not an expert. Should incase I have a magnet as big as your tiny hands in the picture and I pass electricity through the magnet and the magnetic field is generated around the magnet, can far objects be attracted when I point the electromagnet in their direction or do I need a big magnet and a large amount of electricity to accomplish this ( I want to have superpowers ) ? .... Does the magnet field depend on the amount of electricity passed thru it.

# Sergeant

The strength of the magnetic field depends on both the amount of turns of the coil, and the amount of current passed through it. In both cases, the bigger the current/the amount of turns, the stronger the electromagnetic field will be.

When you create an electromagnetic field around the bar magnet, the 2 fields will add up, but there might be problems like self-inductance in play.

But you'd still not have enough power to pull an object to you from a significant distance. You'd require a really big power source. Probably like the one in the picture of the scrap mover in this article.


I don't think it's possible but let me ask anyway. You see lets say I have the coils and the electricity part sorted out. Does the magnetic field generated around the magnet flow only in all directions or can it be beamed in a particular direction ?

# Sergeant

Yes, it is possible to concentrate a magnetic field using a cone of magnetic material (like a receiver for satellite TV does).


Great article Phoenix, I'm always impressed by the depth and comprehensiveness of your articles. Keep up the great work!


This series really is magnetic.


The things you learn about electricity can be shocking sometimes.

Yeah, magnetism really is a force to be reckoned with.

I never thought of electricity as useful till I found your series, keep up the great work mate!


I've noticed people love it when I try to point out how useful electrical engineering is. I guess I should focus more on that.


Just a little correction on Faraday's Law...
A time varying magnetic field induces an emf in the coil which in turn induces a current

This is the reason electromagnetic waves exist. Electrons oscillating around the nucleus contribute to a time varying current (due to change in emf) which induces a time varying magnetic field which in turn again induces a current.

I'll be glad to help you out if you want.
And as always a great article.

Good point! I was trying to keep things simple, so I didn't include this explanation (and we probably won't need it in our projects. I like quick and easy sometimes!).


Nice tut Phoenix, next you should also mention lorentz force law ;)

I am planning to mention it in a post about how a HDD works, because the force that moves the read/write arm so fast and precise is Lorentz force.


Phoenix is the true definition of god :)

Let's not compare me to anyone or anything, shall we? ;)


Cmoon :) everyone know it

Even if everyone has that opinion, it simply isn't true.


Very interesting article as always Phoenix. I am just wondering if this series will be continued. I 'm looking forward to it!

When's part 5

Share Your Thoughts

  • Hot
  • Latest