Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

small door sensor


  • Please log in to reply
21 replies to this topic

#1 optimus primer

optimus primer

    Member

  • Members
  • PipPip
  • 21 posts
  • Locationnashville, tn

Posted 06 January 2013 - 08:59 PM

i am new to netduino, and even programming. i have an idea for a door sensor but lacking the programming part. if anyone would like help me i would greatly appreciate it.

 

my kids are currently running in and out of the back door while i am in my office. i would love to be able to know when they are coming in and out of the back door. i have bought some led lights and door sensors. have plenty of wire laying around. so i have all the stuff to do it just stuck with the programming.

 

my idea is to maybe have power running through the sensor and when the door opens the break in the voltage will somehow turn the led on. and when the door shuts the light will still stay on until i press a reset switch or button.

 

any tips will be greatly appreciated.

 

 

thanks,



#2 jkrarup

jkrarup

    New Member

  • Members
  • Pip
  • 8 posts

Posted 07 January 2013 - 05:03 PM

Seems fairly basic. Do you have the expertise to wire and connect the door sensor, reset switch and LED's to the netduino board?

 

 

Logic is as follows:

Define the sensor, LED and reset switch.

Define a status for the LED as a boolean type (true=on, false=off)

Set the LED status to false to begin

create a endless loop

inside the loop check for the condition of the door sensor and it it is open set the LED status to true

also inside the loop check for the reset switch and if pressed set the LED status to false

finally inside the loop set the LED to the LED status (turn on or off the LED)

 

In the "how to's" of the project page, the "pushing the button" gives you a head start on the programming. http://netduino.com/projects/

 

Hope that helps.



#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 07 January 2013 - 06:40 PM

Perhaps a better idea instead of the endless loop will be to instantiate two InterruptPort-s, one for the door sensor and second for the reset switch, then you can set the LED state in the respective interrupt handlers. Wire both sensor and switch between Netduino pin and ground, otherwise you'd need to change the interrupt mode (e.g. InterruptEdgeHigh).  

... private static InterruptPort doorSensor;private static InterruptPort resetSwitch;private static OutputPort led; static void Main(){  // TODO: Replace the pins according to the actual wiring  doorSensor = new InterruptPort(Pins.D0, false, ResistorModes.PullUp, InterruptModes.InterruptEdgeLow);  doorSensor.OnInterrupt += doorSensor_OnInterrupt;   resetSwitch = new InterruptPort(Pins.ONBOARD_SWITCH, false, ResistorModes.PullUp, InterruptModes.InterruptEdgeLow);  resetSwitch.OnInterrupt += resetSwitch_OnInterrupt;   // TODO: Replace the pin if you use external LED  led = new OutputPort(Pins.ONBOARD_LED, false); // Initially Off   // Sleep, wait for the interrupts...  Thread.Sleep(Timeout.Infinite);} static void doorSensor_OnInterrupt(uint data1, uint data2, DateTime time){  // Door open - turn the LED on  led.Write(true);} static void resetSwitch_OnInterrupt(uint data1, uint data2, DateTime time){  led.Write(false);}

Depending on switch or door sensor construction, you'd probably need to improve the code to handle bouncing - this has been already discussed numerous times on the forum  :P Edit: The code was written from head, it contains a few typos and there are missing using and namespace directives. The fixed version was posted below. Sorry.


Edited by CW2, 09 January 2013 - 07:36 AM.


#4 AxelG

AxelG

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 07 January 2013 - 06:59 PM

Another idea might be to wire a small piezo buzzer to the ND to also get an audio cue.

 

I have a home-built alarm system that will alert me to the opening or closing of a door or window while in standby.  Simple two beeps for open, one for closed.



#5 optimus primer

optimus primer

    Member

  • Members
  • PipPip
  • 21 posts
  • Locationnashville, tn

Posted 09 January 2013 - 04:32 AM

Perhaps a better idea instead of the endless loop will be to instantiate two InterruptPort-s, one for the door sensor and second for the reset switch, then you can set the LED state in the respective interrupt handlers. Wire both sensor and switch between Netduino pin and ground, otherwise you'd need to change the interrupt mode (e.g. InterruptEdgeHigh).  
... private static InterruptPort doorSensor;private static InterruptPort resetSwitch;private static OutputPort led; static void Main(){  // TODO: Replace the pins according to the actual wiring  doorSensor = new InterruptPort(Pins.D0, false, ResistorModes.PullUp, InterruptModes.InterruptEdgeLow);  doorSensor.OnInterrupt += doorSensor_OnInterrupt;   resetSwitch = new InterruptPort(Pins.ONBOARD_SWITCH, false, ResistorModes.PullUp, InterruptModes.InterruptEdgeLow);  resetSwitch.OnInterrupt += resetSwitch_OnInterrupt;   // TODO: Replace the pin if you use external LED  led = new OutputPort(Pins.ONBOARD_LED, false); // Initially Off   // Sleep, wait for the interrupts...  Thread.Sleep(Timeout.Infinite);} static void doorSensor_OnInterrupt(uint data1, uint data2, DateTime time){  // Door open - turn the LED on  led.Write(true);} static void resetSwitch_OnInterrupt(uint data1, uint data2, DateTime time){  led.Write(false);}

Depending on switch or door sensor construction, you'd probably need to improve the code to handle bouncing - this has been already discussed numerous times on the forum  :P

thanks for the reply. really helpful. i tried a copy and paste and it thru a bunch of errors. but when i type the hole thing i still get a couple errors. will there be a difference in the coding if there is a difference in firmware. i have 4.2 . this is probably a real stupid question but like i said im new to the whole thing.

 

thanks again



#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 09 January 2013 - 07:31 AM

Well, the code was not meant as a complete working solution, just a snippet to illustrate the idea, sorry about the confusion. The fixed version that can be copy'n'paste-d directly (replace everything in your Program.cs) is  
using System;using System.Threading;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware.Netduino; namespace NetduinoApplication1{  public static class Program  {    private static InterruptPort doorSensor;    private static InterruptPort resetSwitch;    private static OutputPort led;     public static void Main()    {      // TODO: Replace the pins according to the actual wiring      doorSensor = new InterruptPort(Pins.GPIO_PIN_D0, false, ResistorModes.PullUp, InterruptModes.InterruptEdgeLow);      doorSensor.OnInterrupt += doorSensor_OnInterrupt;       resetSwitch = new InterruptPort(Pins.ONBOARD_BTN, false, ResistorModes.PullUp, InterruptModes.InterruptEdgeLow);      resetSwitch.OnInterrupt += resetSwitch_OnInterrupt;       // TODO: Replace the pin if you use external LED      led = new OutputPort(Pins.ONBOARD_LED, false); // Initially Off       // Sleep, wait for the interrupts...      Thread.Sleep(Timeout.Infinite);    }     private static void doorSensor_OnInterrupt(uint data1, uint data2, DateTime time)    {      // Door open - turn the LED on      led.Write(true);    }     private static void resetSwitch_OnInterrupt(uint data1, uint data2, DateTime time)    {      led.Write(false);    }  }}


#7 optimus primer

optimus primer

    Member

  • Members
  • PipPip
  • 21 posts
  • Locationnashville, tn

Posted 19 January 2013 - 07:23 PM

Well, the code was not meant as a complete working solution, just a snippet to illustrate the idea, sorry about the confusion. The fixed version that can be copy'n'paste-d directly (replace everything in your Program.cs) is  

using System;using System.Threading;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware.Netduino; namespace NetduinoApplication1{  public static class Program  {    private static InterruptPort doorSensor;    private static InterruptPort resetSwitch;    private static OutputPort led;     public static void Main()    {      // TODO: Replace the pins according to the actual wiring      doorSensor = new InterruptPort(Pins.GPIO_PIN_D0, false, ResistorModes.PullUp, InterruptModes.InterruptEdgeLow);      doorSensor.OnInterrupt += doorSensor_OnInterrupt;       resetSwitch = new InterruptPort(Pins.ONBOARD_BTN, false, ResistorModes.PullUp, InterruptModes.InterruptEdgeLow);      resetSwitch.OnInterrupt += resetSwitch_OnInterrupt;       // TODO: Replace the pin if you use external LED      led = new OutputPort(Pins.ONBOARD_LED, false); // Initially Off       // Sleep, wait for the interrupts...      Thread.Sleep(Timeout.Infinite);    }     private static void doorSensor_OnInterrupt(uint data1, uint data2, DateTime time)    {      // Door open - turn the LED on      led.Write(true);    }     private static void resetSwitch_OnInterrupt(uint data1, uint data2, DateTime time)    {      led.Write(false);    }  }}

i have been tinkering with the program for several days know. I can not seem to get it just right. i am trying to get it were the light will come on when the sensor breaks, not when it breaks then close. thanks for all help



#8 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 20 January 2013 - 09:59 PM

I can not seem to get it just right. i am trying to get it were the light will come on when the sensor breaks, not when it breaks then close.

 

Could you please provide more detailed information on what kind of door sensor you use and how exactly it is connected to Netduino?



#9 optimus primer

optimus primer

    Member

  • Members
  • PipPip
  • 21 posts
  • Locationnashville, tn

Posted 20 January 2013 - 11:06 PM

Could you please provide more detailed information on what kind of door sensor you use and how exactly it is connected to Netduino?

it is a magnetic two piece sensor. there is two wires that run into one piece of the sensor. the other piece connects to it magnetically. with both pieces together it can complete the circuit. once the 2 pieces are separated it will open the circuit. 

hope this helps

 

 

thanks,



#10 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 21 January 2013 - 08:25 AM

Ok, so if it is something like this then the following should work:


    [*]Connect the first sensor wire to Netduino pin (e.g. D0),
    [*]Connect the second sensor wire to ground (one of Netduino's GND pins),
    [*]In the sample code above, change InterruptModes.InterruptEdgeLow to InterruptModes.InterruptEdgeHigh on line #17. 
    [/list]

    The circuit then works like this:


      [*]When the sensor is open, there is logic level high (positive voltage) on the Netduino pin (D0), because the pin is connected to supply voltage (+3.3V) through the internal pull-up resistor,
      [*]When the sensor is closed, it connects the pin to ground = logic level low and the transition from high to low level is detected as 'low edge' (a.k.a. 'falling edge'),
      [*]When the sensor opens again, the signal on the pin is pulled-up to logic high, this change is detected as 'high edge' (a.k.a. 'rising edge') and the interrupt handler for InterruptEdgeHigh is executed. Go to step #2.
      [/list]

#11 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 21 January 2013 - 08:37 AM

Also, if you want the LED to be on when the door is open during Netduino startup, modify the code on line 24 so it reads the doorSensor status:
// The LED status is inverted doorSensor logic level (note the exclamation mark)led = new OutputPort(Pins.ONBOARD_LED, !doorSensor.Read());


#12 optimus primer

optimus primer

    Member

  • Members
  • PipPip
  • 21 posts
  • Locationnashville, tn

Posted 04 February 2013 - 11:58 PM

well i been thinking about adding a keypad to the system. just for the hell of it. would any type of security keypad work? i was thinking cheap and found a ademco 6148 for about 40 bucks. it says there is.....

-(black) ground

+(red) +12vdc(aux. power)

DO (yellow) 'data out" from control panel

 

i guess the best way to test and see if it would work is to buy it and try it out. i figure the DO yellow would basically be an on/off switch to start the light from on/off. but not sure. any help would be awesome

 

thanks.....



#13 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 05 February 2013 - 01:32 AM

The data out may be something like a serial line that sends the code to the alarm panel instead. It does not make sense to have a wire that just turns the panel on or off. That would only take 2 wires and could be opened or shorted to turn the panel off.

 

I would not buy the keypad with a data sheet. http://www.intellaho...148 install.pdf

 

Chuck



#14 Billy Propes

Billy Propes

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • LocationVincent, OH, USA

Posted 05 February 2013 - 04:36 AM

These alarm keypads usually use a proprietary communications protocol between the keypad and alarm panel (usually some variation of a serial bus).  This is so that anybody with access to the wiring in your house can't just hookup to it and disable the alarm.

 

If you just want a simple keypad, with no display (or just a few LEDs), I believe your best bet is going to be to either create your own keypad matrix or use something like this:

 

https://www.sparkfun.com/products/8653

 

If you need LEDs, you could even use something like CAT5 for the wiring and just sink some LEDs through the Netduino.

 

Hope this helps some!  Best of luck!



#15 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 05 February 2013 - 06:40 AM

I have a couple of these and they work really well,

http://www.harborfre...stem-93068.html

Very simple, Just point the sensor toward your door. However,  not as much fun as wiring your own
sensor with a Netduino.



#16 optimus primer

optimus primer

    Member

  • Members
  • PipPip
  • 21 posts
  • Locationnashville, tn

Posted 05 February 2013 - 07:42 PM

The data out may be something like a serial line that sends the code to the alarm panel instead. It does not make sense to have a wire that just turns the panel on or off. That would only take 2 wires and could be opened or shorted to turn the panel off.

 

I would not buy the keypad with a data sheet. http://www.intellaho...148 install.pdf

 

Chuck

so what you are saying is that the keypad in the hyperlink would work? if so would i have to make my own keypad matrix from the statement from Billy Propes statement? or would it be almost plug and play (knowing that the netduino program would have to modified)?



#17 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 05 February 2013 - 10:45 PM

optimus primer,

 

The link was to the Keypad that you listed.

 

I do not know if it would work without seeing what it transmits using a logic analysis or more information from a data sheet.

 

Chuck



#18 optimus primer

optimus primer

    Member

  • Members
  • PipPip
  • 21 posts
  • Locationnashville, tn

Posted 06 February 2013 - 12:15 AM

optimus primer,

 

The link was to the Keypad that you listed.

 

I do not know if it would work without seeing what it transmits using a logic analysis or more information from a data sheet.

 

Chuck

oh ok. im a dumdass i just realized that its the same controller. i will try and find a keypad that has a data sheet. is there anything specific to look for?



#19 optimus primer

optimus primer

    Member

  • Members
  • PipPip
  • 21 posts
  • Locationnashville, tn

Posted 07 February 2013 - 12:13 AM

well i found a manual online that said that the current for stand by is 30ma, and 55ma for the alarm. if i hook the data out pin to the analog input on the netduino and have it to light a led when the current is at 55ma, and not when its set at 30ma. would this process work?

 

here is the link i found this information from.......                                                                                        

 

 

http://www.alarmhow....tion Manual.pdf



#20 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 07 February 2013 - 02:21 AM

I do not know without some time to research it, but my gut feeling is no.

 

  • You need to be carefull hooking into the analog pin, it has a maximum design voltage of 3.3 vdc. May be be able to setup a voltage divider if it has a higher voltage.
  • An Analog pin can not sink 30ma.
  • Most LEDs are closer to 20ma.
  • I didn't find the protocol listed in the manual (didn't spend that much time looking), it could be serial or any number of dedicated protocols.
  • The protocol and voltage etc. will dictate the pins that you can use.
  • Start by figuring out what you want the circuit to do and maybe we can help you find a solution.

I will try to help, but may not have much time for awhile. The plant that I work at is being closed down.

 

Good luck,

Chuck






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.