0

I am a complete layman when it comes to electronics. I want to make a timer that can be triggered using an external signal from a proximity sensor. Lets say when there is no product on my conveyor, my timer triggers till the product is on the conveyor (This signal can be taken from a proximity sensor). I want all the times displayed in real time and logged as well. Can anyone please guide me on how to achieve this? I have C# in my mind but I need a starter guide for this project. Thanks.

Ali Javed
  • 3
  • 1

1 Answers1

0

Since you have arduino listed as a tag and you want use c# I am going to take make an assumption you want to use this for a netduino type device. You are going to have an interrupt (or in c# terms an "event") for your prox sensor. When this interrupt triggers you can start your timer by making the enable property of the timer true. After the timer interval expires it will call the method wired to the elapsed event. When this occurs you can turn off the timer so that it will not run again until your sensor is activated.

class Program
{
    static Timer timer;

    static void Main(string[] args)
    {
        //set timer interval of 3 seconds
        timer = new Timer(interval: 3000);
        timer.Elapsed += Timer_Elapsed;

        InterruptPort sensor = new InterruptPort(/* sensor port information */);
        sensor.OnInterrupt += new NativeEventHandler(sensor_OnInterrupt);
    }

    private static void sensor_OnInterrupt(uint data1,uint data2,DateTime time)
    {
        Console.WriteLine(DateTime.Now);
        timer.Enabled = true;
    }

    private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
    {
        Console.WriteLine(DateTime.Now); 
        timer.Enabled = false;
        //do work
    }
}

For more information on logging and timers I would check out the following links

logging

timers

Community
  • 1
  • 1
mrsargent
  • 2,267
  • 3
  • 19
  • 36
  • Thank you for the help but I don't really know coding in C#. It was just an idea that the user application can be made in C# while the proximity sensor can be attached to an adruino (interfaced with with the PC user application). I need a begginer's guide on the study material and approach I should be using to achieve this. Thanks. – Ali Javed Dec 21 '15 at 04:16