Open door alarm- detecting circuit continuity with USB and transistor enable ground

Discussion in 'The Projects Forum' started by ttshaw1, Feb 22, 2016.

  1. ttshaw1

    Thread Starter New Member

    Jan 24, 2016
    5
    0
    I'm planning on making an alarm for my back door that will sound if I leave it ajar, as often happens. I want to use a Raspberry Pi so I can keep it modular and customizable, so I need to use the pins of a USB to detect if it's open. I'm planning on simply breaking a circuit when I open the door and completing it when it's closed. Attached is my rough plan.
    upload_2016-2-22_14-1-36.png
    The brown are metal contacts that will touch when the door is closed. 1 will go to data. There should be positive voltage at that point because there's a resistor before 2, Ground. 3 is the USB's power supply, +5V. I'll put a large resistor after it to avoid unnecessary power usage.

    Will this work? Hopefully, it'll be a clear difference between 0V (open door) and some positive amount, depending on my resistors. I am concerned that USB is entirely digital. Can I choose some voltage that the Raspberry Pi will read as ON?

    Also, on the other side, I'm going to use a data channel from the second USB to enable a transistor, activating a speaker. What do I do with that USB's GND pin?
     
  2. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,540
    1,251
    Magnetic door and window switches for alarm systems have been around for many decades. Lowes, Home Depot, Ace, ebay. With a magnetic switch the door alignment and contact do not have to be perfect to prevent a false alarm.

    USB +5 V source > 1 K resistor > long wire to switch terminal #1
    Switch terminal #2 > long wire back to Pi input, with 10 K resistor to system ground.

    Door closed = switch closed = 4.5 V at Pi input, 0.5 mA loop current.
    Door open = switch open = GND at Pi input, no loop current.
    Dead short anywhere on the line = 1 mA short circuit current worst case.

    ak
     
  3. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    5,800
    1,104
    Welcome to AAC!
    Sounds like a solution looking for a problem ;). Unless this is just a proof of concept/educational project, a RasPi seems a tad OTT for that job. Won't the Pi's annual power consumption cost exceed the purchase price of an off-the-shelf alarm such as this ?
     
  4. ttshaw1

    Thread Starter New Member

    Jan 24, 2016
    5
    0
    You're right about that- this is really for fun. In addition to making sure we keep the door locked, it would be great to have a home-made system that will sound a klaxon when someone tries to let in uninvited guests during a party. I've got a car horn lined up and ready to go. Using store-bought components feels like cheating.

    As to the magnetic switch not needing to be perfect- that might actually be a hindrance. The door sometimes becomes unlatched even when it was closed and checked, so I would need it the mechanism to be pretty precise. It's really a mechanical problem, but I'm not studying Mech E. You know what they say about only having a hammer.

    Still, it sounds like the switch would functionally be the same as the door-mounted segment in my diagram, with the resistors and leads in the same places. That's confirmation that that current and voltage to USB data would register? I unfortunately know very little about interfacing with computers like that.
     
  5. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,540
    1,251
    The range of the magnetic door switches I use is less than 1/4 inch. Plus, you can mount them slightly misaligned to reduce the range even more. The best part is that they are immune to weather and dirt because the switch element is hermetically sealed.

    Overstating just a bit, there are some persons on these fora who think there are only two electronic components needed for any problem on earth, a 555 and a PIC (or Arduino or Pi or or). Hence my tagline. Here is the original quote:

    I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.
    - Abraham Maslow, The Psychology of Science: A Reconnaissance (1966), Ch. 2, p. 15.

    ak
     
  6. marcf

    Member

    Dec 29, 2014
    137
    19
    If you are considering using a pi, why not go crazy and design a class A system with open circuit and ground fault supervision?

    I can give you some ideas if wanted.
     
  7. ttshaw1

    Thread Starter New Member

    Jan 24, 2016
    5
    0
    My constraints are number of USB slots and money. I'm not running enough wire that I'm worried about a ground fault (not sure what open circuit supervision is), but sure, I'd like to hear how to implement it.
     
  8. marcf

    Member

    Dec 29, 2014
    137
    19
    Hope this helps. You can use a similar circuit for the activation of horns. Just put them between the NO contacts and the return side. Of course you need to provide enough power for the horn. You could use a from C relay at the control for this purpose.
     
Loading...