Using a FEZ Cerberus with a Breakout board, and trying to get a magnetic reed switch to work with it. I’m going about 30 feet with the wiring so I’m wondering if that could be the issue. (I’m a computer guy, not electronics…) Trying to send a digital input down one wire 1 (pin 5, aka “_trigger” in the code) and if the reed switch/circuit is closed works (door is closed), I expect to hear that same input coming up wire 2 (ping 8, aka “_receiver” in the code).
Basic stuff, and I’ve read all the docs on Digital Inputs/Outputs from here, so I’m hoping I’m just something small. In the timer event, I’m just trying to read/listen to the input, hoping it was whatever I set it to when the program runs.
Any ideas? Should I use a different reed switch for this? (trying to make a security system for a house with multiple doors/windows) If not these, what else could I use?
Here’s my code:
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
public partial class Program
private GT.Timer _pollingTimer;
// socket 1 pin 5
// socket 1 pin 8
public static GT.SocketInterfaces.DigitalOutput _trigger;
public static GT.SocketInterfaces.DigitalInput _receiver;
// This method is run when the mainboard is powered up or reset.
_trigger = breakout.CreateDigitalOutput(GT.Socket.Pin.Five, false);
_receiver = breakout.CreateDigitalInput(GT.Socket.Pin.Eight, GT.SocketInterfaces.GlitchFilterMode.Off, GT.SocketInterfaces.ResistorMode.Disabled);
_pollingTimer = new GT.Timer(1000);
_pollingTimer.Tick += new GT.Timer.TickEventHandler(_pollingTimer_Tick);
void _pollingTimer_Tick(GT.Timer timer)
Debug.Print("Receiving: " + _receiver.Read().ToString());
Not really sure what your “trigger” and “receiver” are meant to be ?
A reed switch is just a switch that closes when the magnet is near the reed. This means that if you apply a positive voltage to one side of the switch, you’ll see no power on the other wire when the door is opened, and you’ll see power when the door is closed. The SparkFun site has a typical wiring example for this - the digital input pin is using a pull-down resistor to make sure it sees a “0” when the door is open, and when closed you’ll read the +ve voltage as a “1”.
For this, I’d consider using pin 3, the interrupt capable pin, since you can rely on the interrupt to trigger an action and there’s no need to poll the switch to see if it’s changed state. But a reed switch is perfectly capable of achieving what you want. Just mock it up on a breadboard and show us the wiring (use fritzing for a diagram or take a pic)
@ Brett - Thanks, the _trigger and _receiver were just common names I was using to determine which wire was which. I was setting the pin on the _trigger pin, and expecting to hear back the same on the _receiver if the door was closed, but it sounds like it doesn’t work that way.
There are two wires that are coming out of the reed/switch, does it matter which one connects to Pin 3? The other wire (coming from the other side of the switch) should go to a different pin I assume?
I can Fritz it up later today, although we’re only talking about two wires that connect the switch. If I get this working then yes, I’ll need to diagram it out since it’ll get more complicated.
Nope, it’s a switch, either wire to either end will do
One problem with your assumption is there’s no difference between the switch closing and not closing when you “set” the value to 0. The reason there is a pull-down resistor and it’s wired to a positive supply on one side is because you need to know the value when there is and isn’t a closed circuit.
Did you look at Sparkfun’s diagram? Replicate that on a breadboard. The white wire is the “signal” and can go to pin3, red is +ve (3v3) and black is GND. As you can see the resistor is pulling the signal down to GND, and then when the door closes the signal will go +ve.
@ verbosewater - Once upon a time I wanted to use Nordic Radios to make a wireless security system to ease installation and to secure farmers fields. Oh to be young and stupid.
Fair warning, you’re going to need to need galvanic isolation on those inputs (i.e. photocouplers) so that the thief doesn’t burn your board with a stove lighter.
Can you show us the circuit diagram. I suspect that one wire went to VCC and the other went to your Input? That option “GT.SocketInterfaces.ResistorMode.Disabled” if you’re using a switch without an eternal pull down resistor (assuming you’re connecting to VCC) then you should have it as pull-down, not disabled.