Reed switch - pull up resistor in cayenne?

Simple project - I have a magnetic reed switch (alarm sensor type) which I am monitoring via digital input. Connected to the RPi3 ground and GPIO 26. When the sensor is disengaged, it reads zero, all is good. But when the sensor is engaged (i.e. magnet is close to switch), it flip flops from 0 to 1 constantly.

I’ve read other posts where this is happening and it seems like putting a resistor somewhere helps, but…

if I use python on the pi and set the input pin to have the built-in resistor in the “pull up” state (GPIO.setup(rpin, pull_up_down=GPIO.PUD_UP), all works as expected in python. I don’t see the flip-flop at all. If I leave out the pullup, then I do see the flipflop.

So my question is do I need an external resistor somewhere or can I ask cayenne to set up this pin with the pull-up resistor?

Also, if I need a resistor, can someone tell me what size and where to place it?

Thanks,

Tom S.

Hey @tschwartzman and welcome to the Cayenne Community. I’ll give you the software half of this, and hopefully one of our more hardware oriented guys can chime in on the that half of things (I believe your suspicion is correct – that you do need an external resistor somewhere – but I’m not entirely sure which one and where).

Speaking software, Cayenne doesn’t have a setting for the internal pullup resistor on the Pi in our UI, but if you connect your Raspberry Pi through our MQTT API using the Python MQTT Pi agent (as opposed to the agent software that is installed when you choose the ‘Raspberry Pi’ option in our UI), then you can use Cayenne without the webiopi layer that we use to interact with the GPIO in the ‘original’ agent. Basically you could integrate the Python code you already have and is working, with a client that can exchange values with Cayenne.

If you wanted to experiment with that route, just follow these steps to uninstall the original agent before installing the MQTT one.

The easier answer indeed might just be getting this external resistor in place :slight_smile:.

Might start with a 4.7k resistor

1 Like

4.7 K or 10 K are generic resistor that you have to test with them. If you provide a wiring scheme, I can tell you exactly between which two wires you have to hook up the resistor :wink:

1 Like

Thanks all for the info. I am a little daunted by the MQTT idea, so will try the resistor.

I don’t have a wiring scheme but this switch has two wires going from pi to it - one is ground and the other is a digital input. So I guess the question is would the resistor go between the ground and the sensor or the digital input and the sensor?

Tom

Pull up is to 3.3v, resistor to 3.3v and one side of the switch other side of switch to gnd. (start with 10k then lower like 4.7k). Then connect from resistor side of switch to gpio of your choice. Never use 5v, kablooey!

William

1 Like