Check out a free preview of the full Nodebots / Hardware course:
The "Wiring Up a Magnetic Door Switch" Lesson is part of the full, Nodebots / Hardware course featured in this preview video. Here's what you'd learn in this lesson:

Steve wires up a magnetic door switch to detect when a door or drawer has been opened.

Get Unlimited Access Now

Transcript from the "Wiring Up a Magnetic Door Switch" Lesson

>> Steve Kinney: So I'm gonna transition to our next little project. For this next project, the wiring is suspiciously simple, but it is definitely a fun one. So let's actually take a look at the wiring. And it might not be immediately clear what this component is, and that's totally fine.

[00:00:18] But this is in your kit, a magnetic door switch. So it's got kind of an on or an off, whether they're connected or not connected, in this case. And basically you could put one on the door and one on the door frame. And when they're connected, that's one status of the switch, and when someone opens the door, that's another status of the switch, right?

[00:00:41] You could put it in a drawer, right? It's just basically two magnetic pieces of plastic. It's interesting, cuz on one hand, it is a very simple component, which is again, two magnetic pieces of plastic. On the other hand, the idea that you can get a notification. So what we're gonna do is we're gonna get it working, and then we're gonna play with a third-party API for the first time, right?

[00:01:01] So we just played with sending post requests to our own server. But we will be able to play with a third-party API for sending us notifications when these two things get separated, which will be a lot of fun. The wiring is very simple, we have one that's gonna go into pin a2, and one that goes to ground.

[00:01:20] And kinda show you how it's arranged, because the first time I got one of these, I assumed they kind of go like this for separating. But that's not how it works, especially, it took me suspiciously long to figure that out. Especially if you look at where the adhesive is, there's no way that would really work for a door.

[00:01:37] They actually go,
>> Steve Kinney: Like this, right? And when they are together, that's one status, and then when they get far enough apart, that will trigger the other status of the switch. All right, so technically this is very similar to an on-off switch, right? But we have closed, we have open, closed, and open.

[00:02:02] There's really only two wires coming out of it, and it is not polarized, so I will put one.
>> Steve Kinney: Gotta stretch them out a little bit, I'll put one into the ground, and I'll put the other one into a2.
>> Steve Kinney: I've also got ground, zero, one, two, that's should work.

[00:02:38] And I'm gonna place these both.
>> Steve Kinney: There's adhesive on the bottom as well as little screw holes. So how very fragile it is to keep them together now will not be the case when you use it for real. But as we play around with it, it's a little tough.

[00:02:55] But I'm just gonna place them together like that. And with that, we should be ready to head over to our playground and write a little bit of code.