user16336: I am building a motion following robot. It has two PIR sensors on the left and right. It has an ultrasonic sensor in the front. When either of the PIR sensors detect motion then it turns to that side. 
When both the PIR sensors sense motion then I calculate the distance first( with the ultrasonic sensor, if distance <= 50 cm and > 5 cm then the robot moves forward. But it could mean that the motion is either in the front or in the back. Thus, my robot moves forward even the motion is behind it. 
 I need some help devising a method so that when motion is detected behind then the robot will turn back. I tried making the robot turn right when both the sensors detect motion, then it will turn towards the left(i.e. front) or right(i.e. back). But in reality this method is not so practical as it would to a lot of confusion when the intruder we are trying to detect is still in motion. Plz help. A sample sketch would help.

user4143: This is a basic problem of only having two sensors.  There is no way that two sensors of this simple type (some motion yes/no) can be used to work out where the motion comes from except when there is a difference between the two sensors.  Anything else is, and always will be, ambiguous.
If you think of it as a circle divided in two, you have only three possible conditions:

That is, left, right or somewhere.  Not ideal.
So you need more data to be able to make a decision.  That means more sensors.  The ideal scenario is four sensors - left, right, front and rear.  That gives you many possible scenarios, including:

As you can see from that you have a full 360° idea of where the motion is. You can even know how far to the left it is by if the front or rear is also on.  For instance, using sailing terminology, those 8 circles would mean (in order):

Motion on the left beam
Motion on the port bow
Motion dead ahead
Motion on the starboard bow
Motion on the starboard beam
Motion on the starboard quarter
Motion dead astern
Motion on the port quarter

Also the dead-ahead and dead-astern could be indicated by just the forward or rear sensor on and the left/right sensors both off.  You could even use that fact to give some indication of the distance of the motion depending on the angular coverage of the different sensors.

16336: <p>I am building a motion following robot. It has two PIR sensors on the left and right. It has an ultrasonic sensor in the front. When either of the PIR sensors detect motion then it turns to that side. 
<br><br>When both the PIR sensors sense motion then I calculate the distance first( with the ultrasonic sensor, if distance &lt;= 50 cm and > 5 cm then the robot moves forward. But it could mean that the motion is either in the front or in the back. Thus, my robot moves forward even the motion is behind it. 
<br><br> I need some help devising a method so that when motion is detected behind then the robot will turn back. I tried making the robot turn right when both the sensors detect motion, then it will turn towards the left(i.e. front) or right(i.e. back). But in reality this method is not so practical as it would to a lot of confusion when the intruder we are trying to detect is still in motion. Plz help. A sample sketch would help.</p>
 4143: <p>This is a basic problem of only having two sensors.  There is no way that two sensors of this simple type (some motion yes/no) can be used to work out where the motion comes from except when there is a difference between the two sensors.  Anything else is, and always will be, ambiguous.</p>
<p>If you think of it as a circle divided in two, you have only three possible conditions:</p>
<p><a href="https://i.stack.imgur.com/d2Xeo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d2Xeo.png" alt="enter image description here" /></a></p>
<p>That is, <em>left</em>, <em>right</em> or <em>somewhere</em>.  Not ideal.</p>
<p>So you need more data to be able to make a decision.  That means more sensors.  The ideal scenario is four sensors - left, right, front and rear.  That gives you many possible scenarios, including:</p>
<p><a href="https://i.stack.imgur.com/WPggl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WPggl.png" alt="enter image description here" /></a></p>
<p>As you can see from that you have a full 360° idea of where the motion is. You can even know how far to the left it is by if the front or rear is also on.  For instance, using sailing terminology, those 8 circles would mean (in order):</p>
<ol>
<li>Motion on the left beam</li>
<li>Motion on the port bow</li>
<li>Motion dead ahead</li>
<li>Motion on the starboard bow</li>
<li>Motion on the starboard beam</li>
<li>Motion on the starboard quarter</li>
<li>Motion dead astern</li>
<li>Motion on the port quarter</li>
</ol>
<p>Also the dead-ahead and dead-astern could be indicated by just the forward or rear sensor on and the left/right sensors both off.  You could even use that fact to give some indication of the distance of the motion depending on the angular coverage of the different sensors.</p>
