Page 1 of 1

Can't get motion sensor triggered?

Posted: Sun Sep 01, 2019 2:44 pm
by Ken76
I have problem with this code below this text.
It doesn't triggered the PirSensorPin_ValueChanged and I also tried with RisingEdge but the result is the same,
the text "Hello" remain the same and not changing to "Motion detected".

I'm using Raspberry PI 3 and motion sensor for this project.
Is there something wrong with this code?

Code: Select all

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Devices.Gpio;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace ControllerLamps
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        private GpioPin motionSensorPin;
        public MainPage()
        {
            this.InitializeComponent();
            SetupMotionSensor();
        }
        private void SetupMotionSensor()
        {
            var gpioController = GpioController.GetDefault();
            motionSensorPin = gpioController.OpenPin(26);
            motionSensorPin.SetDriveMode(GpioPinDriveMode.Input);
            motionSensorPin.ValueChanged += PirSensorPin_ValueChanged;
            textBlockInfo.Text = "Hello!";
        }
        private void PirSensorPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            if (e.Edge == GpioPinEdge.FallingEdge)
            {
                textBlockInfo.Text = "Motion detected!";
            }
        }

    }
}

Re: Can't get motion sensor triggered?

Posted: Wed Sep 04, 2019 8:28 pm
by Ken76
I have even tried to test another GPIO pin and motion sensor. What else can I try?