Sensing A Magnet With Local Sourcing

I had a small project going on–never mind exactly what–and I needed to detect a magnet. Normally, that wouldn’t be a big problem. I have a huge hoard of components and gear to the point that it is a running joke among my friends that we can be talking about building something and I will have all the parts we need. However, lately a lot of my stuff is in… let’s say storage (again, never mind exactly why) and I didn’t have anything handy that would do the job.

Options

If I had time, there are plenty of options for detecting a magnet. Even if you ignore exotic things like SQUID (superconducting quantum interference device) there’s plenty of ways to detect a magnet. One of the oldest and the simplest is to use a reed switch. This is just a switch made with a thin piece of ferrous material. When a magnet is nearby, the thin piece of metal moves and makes or breaks the contact.

These used to be common in alarm systems to detect an open or closed door. However, a trip to Radio Shack revealed that they no longer carry things like that as–apparently–it cuts into floorspace for the cell phones.

I started to think about robbing a sensor from an old computer fan or some other consumer item with a magnetic sensor onboard. I also thought about making some graphene and rolling my own Hall effect sensor, but decided that was too much work.

Browsing

I was about to give up on Radio Shack, but decided to skim through the two cabinets of parts they still carry just to get an idea of what I could and could not expect to find in the future. Then something caught my eye. They still carry a wide selection of relays. (Well, perhaps wide is too kind of a word, but they had a fair number.) It hit me that a relay is a magnetic device, it just generates its own electromagnetic field to open and close the contacts.

I picked up a small 5 V reed relay. They don’t show it online, but they do have several similar ones, so you can probably pick up something comparable at your local location. I didn’t want to get a very large relay because I figured it would take more external magnetic field to operate the contacts. You have to wonder why they have so many relays, unless they just bought a lot and are still selling out of some warehouse. Not that relays don’t have their use, but there’s plenty of better alternatives for almost any application you can think of.

The Fridge Test

I got home and pulled a rare earth magnet off the refrigerator and grabbed an ohm meter. Sure enough, I could reliably operate the relay contacts with the strong magnet. My project was in business!

Of course, your mileage may vary. The construction of any particular relay may or may not be conducive to external activation. You may have to experiment with the exact magnet, but those are easy to find in lots of local outlets, including home improvement and hobby stores.

The Mother of Invention

When you are cooking, sometimes it helps to know that you can substitute one thing for another. The same is true of electronic components. Need a bridge rectifier? Make one out of diodes. You can probably substitute an op amp for most comparator applications. LEDs can detect light and speakers can act as microphones although in both cases the results are not as good as  parts that are supposed to do those functions.

I do think it is interesting, though, that Radio Shack has such a blend of odd things. You can get a lot of Arduino shields, for example. You can also get a lot of relays. However, I noticed there was only one MOSFET in the cabinet and it wasn’t a “logic level” FET. Seems like it would be like going into an office supply store and finding PCs and carbon paper, but no LCD screen wipes.

Regardless of Radio Shack’s ability to keep up with the times or not, I was glad they had relays. When you are looking to scrounge something in a hurry, don’t forget to think about auto supply places, home improvement stores, craft stores, and even dollar stores — I’ve seen a one-dollar, open-door detector before, but I knew from a previous attempt they have the sensor integrated with the electronics and are hard to scrounge.

Postscript: After I completed my little project, while looking for something totally unrelated, I ran across this homebrew reed switch. Certainly another option.

48 thoughts on “Sensing A Magnet With Local Sourcing

    1. Hey, this could even generate an analog signal, depending on the iron particle size and the oil viscosity… I really want to experiment with this now, maybe “reset” the tube by pulling the iron back with a solenoid coil

  1. Hall sensors are everywhere! Anything that has a motor on a computer has one at least. From hard drives to floppy drives to CD/DVD drives. Most printers also have some. Ask your neighbours for some dead / antique hardware !

    1. I have seen them in 3.3″ FDDs and an index sensor. Older 5.25″ drives where optical. But in any case I not expecting to find a bunch of FDDs anytime soon.

      I think I have seen them on old CD/DVD drives but newer CD/DVD us a printed inductor (PCB trace) instead.

      But fan? Are they in computer fans? Is it only the 3? or 4? wire ones? I haven’t seen them in fans but most or all of the fans I have pulled apart are 2 wire.

      Have I been throwing out Hall sensors?

      1. Regular 2-wire fans have hall sensors; they are basically 2-phase motors with a single hall sensor with 2 complementary outputs, pulling one side or the other of the coils low, with the center tab connected to VCC, if I remember correctly.

        1. Thanks [SparkyGSX]

          If you are still on this tread an you tell what is in a HDD. Are there 3?

          I want to try hall sensors as endstop sensors for am arc delta that I am making and although I normally keep HDD spindle motors (intact), I would still prefer to donate 1 HDD motor rather than 3 fans.

          Thanks in advance – if you have time.

          1. Seems like most modern HDDs have no sensor, the get the required timing from resonance of the circuit and the data from the read heads. I have taken apart dozens of modern ones and very very few have a hall.

            Older floppy drives, most CPU heatsink fans, and especially CD/DVD spindle motors definitely tend to have hall sensors.

          2. While we are on the subject of finding useful bits in old *junk*. The plastic head parking vanes look like they would make perfect interrupters for opto-interrupters used as endstops in 3D printers etc.

  2. These used to be common in alarm systems to detect an open or closed door. However, a trip to Radio Shack revealed that they no longer carry things like that as–apparently–it cuts into floorspace for the cell phones.

    Go to a dollar store, they sell those tiny door sirens powered with expired button cells. I purchased a bunch last week just for the reed switch and piezos! :)

  3. Maplins is the UK of RadioShack.
    Exactly the same problem.
    They……………….. hang on a minute……………. keep reading…………….. don’t look down just yet. Ya guessed it?

    Load of relays, then some headphone jacks, auduino shields (dedicated shelf space) and mostly gadget shop stuff like drones a karaoke system and some faux aluminum (painted cardboard box) suitcases and the occasional battery or PSU if you are lucky.

  4. I used to joke that if I could choose one place to be when the zombie apocalypse hits, it would be either the DigiKey warehouse or the McMaster-Carr warehouse… Something of a mad fantasy of having both a perfect excuse to hack together insane devices and one of the world’s best parts bins at my disposal…

  5. AMR sensors are pretty common and work great for detecting magnetic fields. Many phones contain one, either standalone or as part of 9DoF sensor. The Honeywell HMC5883/5983/etc. used to be pretty common at electronics shops, I know Paralax still sells a breakout board. Long term availability on these is not good… Honeywell has EOL’ed their AMR product line. NXP has the MAG3110, which is very reliable, cheap, and easy to solder. These are available from Sparkfun on breakout boards.

  6. Probably just a brain fart but, if you charge a coil and capacitor then discharge it can you tell if it is interacting be a magnetic field by changes in it’s behaviour? What if you have three in a right angle corner configuration and probe them in sequence, does this not give you a 3D magnetometer, or are the AD circuits of MCUs not sensitive enough to sense the changes in behaviour? Or do you need 3 sets of 2 coils and the magnetic field can be detected by it’s influence on transmission between the coils. It would not be as complex as it perhaps sounds as you only need one pin for all of the receiver coils and three to pulse the senders. The loops may not need to be many turns and be wound around a block like 3D printed template with circular groves in it. You could dead bug the coil block onto the back of an ATTiny84 and have it emit the data over I2C.

    1. This is pretty close to delightfully hack-ish way to make a variable inductor. I think I see where you’re headed, but forgive me if I misunderstood. The coils couldn’t be air-wound, as far as I know. They need to be wound around some ferrous material – ferrite is traditional here. Then I assume you’re measuring the reasonant frequency of the LC circuit. Given a known value of C, you can solve for L easily enough. If all parts were perfectly ideal, L would be constant, and you wouldn’t really measure a thing. Fortunately, real-world ferrite cores behave differently as they carry more and more magnetism. By placing the coil (on the ferrite form) into a magnetic field, the actual value of its inductance changes. So, yeah, this should work. Might have to be careful that you didn’t accidentally make a thermometer. :-)

      The way you make a variable inductor out of this is by winding the coil for the inductor and then a second coil to use as an electromagnet, and winding them on the same form. Then as you vary the DC current in the electromagnet you’ll see a change in L for the other inductor.

      1. Isn’t that a “variable saturable reactor”, or something like that? In the early days of radio, they used something along (as I understand your post) those lines. A magnetic amplifier. By partly saturating a core with DC, you can control how much AC it will pass between two coils.

        As far as sensing external magnetic fields, I wouldn’t fancy your chances, I imagine the difference you’re trying to sense would be swamped by other noise, and be tiny in comparison to the current you’re driving through it. In theory it should work, but I bet not in practice.

    2. What you describe is pretty close to a Fluxgate sensor, which is a type of magnetic sensor that can be much more sensitive than Hall effect sensors (if paired with highly sensitive and somewhat complicated and expensive measurement circuits).

      While it is true a inductor with an magnetic core behaves differently in a static magnetic field due to core saturation (which is why you need to saturable core), it depends on the direction of the current; if the current generated a magnetic field in the same direction as the external field, the core goes further into saturation, reducing the apparent inductance, while a current in the opposite direction will take the core out of saturation, thus increasing the inductance.

      1. That is the term I was missing, “Fluxgate sensor”. Having searched that term on google image search I found devices that looked almost identical to the image I had in my mind’s eye, spooky!

        http://www.open.ac.uk/science/research/rosetta/mission/rosetta-orbiter/rpc/mag

        http://www.open.ac.uk/science/research/rosetta/sites/www.open.ac.uk.science.research.rosetta/files/images/rpc_mag.jpg

        So the question is, can you DIY one of these to at least give you a binary or stepped output for each axis that acts like a 3D rotary encoder? The reason I thought that an ATTiny may be able to do the job is because with the right tricks they can actually behave as a very sensitive touch sensor with a significant range, and that indicates that they may also have characteristics that can be exploited for magnetic sensing too. It is all just volts once it hits the chips pins after all.

  7. I like the relay as an alternative…I probably would’ve scavenged a coil from a PSU or something, added a bolt for a core, and wired up circuitry to detect voltage spikes, vastly over-complicating things.

  8. I’d be willing to be that even if the magnet couldn’t operate the relay, it would be possible to sense the difference in coil current required to close it when biased with a magnet.

    Incandescent bulbs can also be used to detect light, and you can detect magnetic fields with a gas laser. Never tried it with a semiconductor laser.

      1. While I haven’t tried it, the filament of an incandescent bulb can be considered a crude black body, and the resistance will change with temperature, which changes with absorbed light. If the resistance is on one arm of a Wheatstone bridge, it becomes a “bolometer” for measuring the energy of incident light.

        C.L. Strong’s “Procedures in Experimental Physics” has a section describing this, chapter 8.

  9. I have not stepped foot in a Radio Shack since they went over to the dark side. I won’t even step into the hipster pizza restaurant that one of the Radio Shacks turned into. Yes I am that bitter about what happened!

      1. That’s funny. I will say, though, I think you guys might have missed the point. There are basically three kinds of posts we create: the ones that say “Look, that guy split an atom with a 555 chip! Here’s a link.” Then there are the long ones like my FPGA series or mBed series, or the Spice tutorials where we do something original for HaD. Then there are the ones in between that we loosely think of as rants. Can Radio Shack be saved? Spy radios. Why make PCBs? How do you educate kids? The history of the Enigma/Norden/Fax machine/etc.

        This is pretty much in that last category. I’m not saying “Hey kids! Run out and get a relay and use it as a magnetic sensor.” I’m saying, “Wow, I needed a magnetic sensor, couldn’t find one in the dumpy Radio Shack bins. Came up with an expedient, and then started musing about the state of Radio Shack and the use of unconventional substitutions.” You might notice the category tag is even “rant.”

        To me, it is like TV. The local channels run sports, news, soap operas, dramas, comedy, award shows, reality shows. I manage to find it within myself not to write them every week to complain about the sports, award shows, soap operas, and reality shows that I don’t like to watch. I just watch what I like and figure they must do the rest of it for somebody.

  10. I once tried to use a reed switch from a dollar store alarm thingy and found that the reed switch wasn’t even encapsuled in glass, it was just sitting there on the PCB as a bare set of wires.
    In the past you would find the glass ones even in cheap stuff, but it seems you can go even cheaper.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.