Netduino home hardware projects downloads community

Jump to content

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

Simpel timer for security system

timer loop piezo LED button netduino 2

  • Please log in to reply
No replies to this topic

#1 sebswed


    Advanced Member

  • Members
  • PipPipPip
  • 45 posts
  • LocationSweden

Posted 13 April 2013 - 06:26 PM

Netduino (plus) 2 project


I'm a beginner, just started coding and was playing with loops, button, LED and piezo element. I created this to understand the code and provide this for beginners like me who have some kind of security system in mind.


It uses the on board LED and button with a piezo element connected on pin 5 (red = +) and GRND (-).

It requires for you to add the PWM.dll to your project reference (right-click on your folder called 'References' and choose 'Add Reference...'). It can be used in combination with a 10K resistor to reduce the volume (I did not use a resistor).


When pressing the button a low frequency sound followed by a higher frequency sound will be heard. The later is looped (counted) and creates the (activation) delay. After the delay (10 loops) the on board LED will go on, indicating the system is activated. You could write additional code there where the LED goes on (for example an output port that enables a relay allowing power to an external siren when a sensor detects an intruder.


You could use an RFID card reader, code- or key lock instead of the on board button.


Its a simple code, just copy and paste and make sure to add the pwm.dll reference to your project.

Posted Image


using System;using System.Net;using System.Net.Sockets;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;namespace NetduinoApplication1{    public class Program{        static SecretLabs.NETMF.Hardware.PWM speaker = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5); // Define the speaker    static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); // Define the LED    static InputPort button1 = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled); // Define the button    public static void Main()    {        while (true)        {            if (button1.Read())   //Check if the button is pressed and do the following when pressed            {                                //Period is 1/frequency                //1/1,000,000 second : 1000000 --> 1 sec                // Duration for Sound over PWM (Period / 2)                uint C = 1000000 / 600; //600 Hz tone                uint D = 1000000 / 660; //660 Hz tone                speaker.SetPulse(C, C / 2);  //Play                Thread.Sleep(800); // Duration                speaker.SetPulse(0, 0); // Turn Off                Thread.Sleep(75); //Pause                    int MyVar; // Create variable "MyVar"                    MyVar = 0; // MyVar is 0                    while (MyVar < 10) // While MyVar is less than 10, do the following loop                    { // start the counting loop for MyVar                        MyVar++; // Increase the value from MyVar by + 1                        speaker.SetPulse(D, D / 2);  //Play                        led.Write(true); //LED on                        Thread.Sleep(1500); // Duration                        speaker.SetPulse(0, 0); // Turn Off                        led.Write(false); // LED off                        Thread.Sleep(2000); //Pause                    } // Close the counting loop from MyVar                              // Write your code here                // This code will run directly after the MyVar loop (for example to enable your security system)                led.Write(true); //LED on                        } // Close the button loop            // Write your code here            // Here you can write other code that has to run even if the button not has been pressed            // For example a listener for a button to deactivate your security system        } // Close the while loop    } // Close the Main loop}}


Netduino Plus 2 (v4.2.2.2)

Also tagged with one or more of these keywords: timer, loop, piezo, LED, button, netduino 2

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.