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.
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.
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
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.
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.
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
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.
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); } }}
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
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.
[*]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]
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
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.
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:
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.
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)?
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?
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.......
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.