Line follower robot using only NAND gates

I'm stuck on this and would appreciate some pointers.

So for class I have to figure out the logic for a line follower robot using at maximum 8 NAND gates (two 74HC00 Quad NAND ICs).

The robot has three sensors, each of which gives logic 1 when on a black surface and logic 0 on a white surface. The robot has two motors, one on the left and one on the right.

Below is the truth table I have made: A, B and C for the individual sensors; LM for Left Motor; RM for Right Motor.

My aim is that the robot tries to get the black line either under sensor B or, when the line is wide enough, under all sensors.

Next I made the K-Maps for both motors. Left motor first.

From which I got the function

F=C+A'B

Then the K-Map for the right motor.

And the function

F=BC'+AC'+AB

I tried creating each AND, NOT and OR gate using NAND using this but I quickly run out of NAND gates.

So, I have two main problems.

1. How do I convert these functions to use NAND gates only, without exceeding the NAND limit?
2. How do I combine these two Boolean functions in order to make the motors work according to the logic table, without running out of NAND gates?

Do I simply have to sacrifice some of the functions in order to require fewer gates?

• A very warm welcome to the site. This is a very good quality and detailed question that you've written. Feb 8 at 11:09
• What is the logic behind row 5? Is it just pick the right hand black line? Feb 8 at 11:25
• Yes. I thought that in a case where the robot detects 2 black lines on opposite sides, it would pick the right side and continue following that. Mostly since I thought that trying to follow 2 lines on opposite sides would cause it to lose the black line completely at some point. Feb 8 at 11:39

Personally I think you either have to stop both motors or continue driving both motors. Then, the problem looks a lot more easily solved because the right hand motor enable signal would be $$\A + \bar{C}B\$$ for both motors driven in state 5.