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.

Logic table for both motors

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.

K-map for left motor

From which I got the function


Then the K-Map for the right motor.

K-map for right motor

And the function


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?

  • 1
    \$\begingroup\$ A very warm welcome to the site. This is a very good quality and detailed question that you've written. \$\endgroup\$
    – TonyM
    Feb 8, 2022 at 11:09
  • 2
    \$\begingroup\$ What is the logic behind row 5? Is it just pick the right hand black line? \$\endgroup\$
    – HandyHowie
    Feb 8, 2022 at 11:25
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Talar
    Feb 8, 2022 at 11:39

1 Answer 1


I think state 5 is incorrect: -

enter image description here

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.

In other words, it's as if you have swapped sensor A and sensor C from the left hand scenario.

That looks like each motor would need 4 NAND gates.

  • \$\begingroup\$ I set LM to logic 1 in row 5 because I thought that it would be odd to detect a black line on both sides and trying to follow both would just cause the robot to behave oddly, so it would just follow one of them. But now that you say it, driving forward would solve that problem as well I think. I'll try again with both motors on concerning row 5. \$\endgroup\$
    – Talar
    Feb 8, 2022 at 11:51
  • 1
    \$\begingroup\$ @Talar please take the 2 minute tour of the site to get a brief understanding of things. \$\endgroup\$
    – Andy aka
    Feb 8, 2022 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.