Main Site Documentation

Fez Cerberus - PIR Sensor not switching off



| have been trying to write a dead simple program to monitor the PIR, run a motor for 10 seconds, turn the motor off, then sleep to reset the PIR. That is all I want it to do but it seems to just run in a loop, regardless of sensing. Its like it over runs the PIR signal:

Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules

Namespace GadgeteerApp19
    Partial Public Class Program

        ' This is run when the mainboard is powered up or reset. 
        Public Sub ProgramStarted()

        Private Sub motion_Sensor_Motion_Sensed(sender As Gadgeteer.Modules.GHIElectronics.Motion_Sensor, state As Gadgeteer.Modules.GHIElectronics.Motion_Sensor.Motion_SensorState) Handles motion_Sensor.Motion_Sensed
            If motion_Sensor.Motion_SensorState.Busy Then
                motorControllerL298.MoveMotor(Gadgeteer.Modules.GHIElectronics.MotorControllerL298.Motor.Motor1, 100)
                motorControllerL298.MoveMotor(Gadgeteer.Modules.GHIElectronics.MotorControllerL298.Motor.Motor1, 0)
                Debug.Print("not running")
            End If
        End Sub
    End Class
End Namespace

I have tried running this with the IF statement as above but also with the code direct under the Private Sub menu.

Any help would be appreciated. Oh its Fez Cerebus, VB2012, latest firmware.



I’d try to eliminate the PIR for a time. Do you have a button module or a joystick module? If so test you can do what you want to the motor with triggering of the button/joystick pressed. Then create a test where you are just reporting the state of the PIR. Unfortunately there’s not too many using VB so syntactical things aren’t something I can comment on sorry


Your program is not entirely following the normal guidelines for how to seperate things. I am not sure why it even compiles. Isnt the program missing an “End sub”.

Normally you should have a main program that initializes stuff and then the events are called in sub-routines outside the main-loop.

Furthermore, maybe you should start with something like the below, writting in VB, just to make sure the PIR sensor is working.

void motion_Sensor_Motion_Sensed(Motion_Sensor sender, Motion_Sensor.Motion_SensorState state)
    Debug.Print("Motion Detected!");

Good luck.