Sketch works with tweak pulse but not with sensor

Made simple sketch for light to switch when sensor detects object. Ultrasonic sensor HC-SR04 is installed on door frame, when person enters it detects and gives pulse output which is used to set the flip flop and intern switch on the light.

Flip flop trigger input is used and change from 0 to 1 used to set the another Flip flop and change from 1 to 0 used for resetting flip flop.

Delays ( 2sec) and AND gate used to block multiple pulses generated. Also more Delay (0.5 sec)node used to reset the change in status due to additional pulse.

In the debug mode if Tweak pulse is connected to Flip flop trigger then the sketch works as expected but when connected to HC SR 04 the Flip flop goes in error mode. Tried to use NAND gate flip flop but that also goes in Error mode.

I am new to Arduino and XOD. Please suggest way out. Thanks you.

There is really no way for a flip-flop to generate an error, so it is really an indication that the Ultrasonic node feeding it is generating an error. Ultrasonic sensors need time to reset & settle down between pings; you might need limit how often the sensor checks. One way to do this is to add a clock node and link clock-TICK to PING or UPD pin for your sensor so the ping is only attempted every second (or maybe a couple times a second using a fraction value for clock-IVAL).

Yes tried the change. Thanks it works