Skip to main content

Email question from a student

I received an email earlier today from a 7th grade student in Utah. Here's the (edited) question:

"How can I program my robot to make more than 1 yes-or-no decision. I have a robot that looks at 3 different sensors but I'm only using sensor logic values and not numbers. The switch block only lets me do one True or False condition."

Great question! And I certainly understand why you're confused. Rather than email the answer, I figured I'd share this with others because if one person is asking, I'm sure there are others. So, here's one option (option #2 will be provided in a separate blog post):
I don't know the details of your robot, but let's just assume that your robot's 3 sensors are Touch, Sound, and Light. You've configured the trigger values for each sensor (For example, does the Light sensor detect a light value less than 20 - true or false?) and are using the logic data plugs to take the True or False response from each sensor.
You didn't state whether all 3 sensor logic values must all be True or all be False, so this example will show you how to make decision based on a mixture of logic values, okay? Let's look at the possible options that can be returned. I'm going to write down all the possible options that could come from 3 sensors in the following format: Light - Sound - Touch with a 1 indicating True and a 0 indicating False. For example, if the Light sensor is True, the Sound sensor is False, and the Touch sensor is True, then I would write 1 - 0 - 1. Got it?
Okay, next we need to look at all the possible options?

Light - Sound - Touch

0 - 0 - 0

0 - 0 - 1

0 - 1 - 0

0 - 1 - 1

1 - 0 - 0

1 - 0 - 1

1 - 1 - 0

1 - 1 - 1

Verify that I've got them all, but I think you'll find that that's it... I've provided everything from all False to all True and everything in between. Now, count them up. There are a total of 8 possible combinations.
Using this, I need to figure out how to program a decision-making procedure that can account for 8 possible combinations. And to do that, I'm going to use the Switch block that you talked about in your question. You are correct that the Switch block only provides 2 possible options when using a Logic value - True or False. What I think will surprise you is that you can place a Switch block inside a Switch block inside a Switch block. Yes, that's 3 levels deep. By doing this, you can check the status of each sensor, one-at-a-time - based on True or False response, another Switch block will be used to check the status of the next sensor (True or False). A final level of Switch block will be added to test the last sensor.
Take a look at the image I've provided here and you'll see how this is done. Starting from the left, you'll see the first Switch block (SB-1) with True or False path. Follow it and you'll see 2 new SBs (SB-2 and SB-3), one in the True path of SB-1 and one in the False path of SB-1. Follow these and you'll see 4 new SBs, 2 in the True path of SB-2 and 2 in the False path for SB-3. And because each of these SBs have a True/False path, you will find that you have a total of 8 possible paths that can be traced.
If this is confusing you, just trace each possible path with your finger and keep count. Use the circles in the right image to represent each switch - blue lines are True and red lines are False. If you're still confused, the best solution would be to duplicate my image in NXT-G and experiment - it'll make sense if you think about it for a while. Thanks for the question - and option 2 will be posted shortly. In that option, I'm going to show you a way to use logic values to determine if all sensors are True or all sensors are False.

Light sensor

Sound sensor

Touch sensor

Popular posts from this blog


2023 is the 25th Anniversary of the MINDSTORMS brand. For 25 years, MINDSTORMS has educated and inspired a generation of robot builders, both children and adults. Unfortunately, the LEGO Group decided to end the line on December 2022. Many ROBOTMAK3RS have been passionately involved with the development of MINDSTORMS through the MUP and MCP programs. Even with the newest Robot Inventor line, several ROBOTMAK3RS were invited to submit additional bonus models that were included in the official app. Regardless of the retirement of a major LEGO robotics product line, ROBOTMAK3RS continue to MAKE-SHARE-INSPIRE using all LEGO robotics platforms available to us. Here is the official statement from LEGO. Since its launch in September 1998, LEGO MINDSTORMS has been one of the core ‘Build & Code’ experiences in the company’s portfolio, carrying with it significant brand equity and becoming a stand-out experience for the early days of consumer robotics and leading to current Build & Code

Celebrating 25 Years of MINDSTORMS

In celebration of the 25th Anniversary of MINDSTORMS, we take a trip through history. Please also visit ROBOTMAK3RS Community every week as we highlight different projects all through 2023 in celebration of the anniversary. Some of the early history is based on the content shared by  Coder Shah  in our  MINDSTORMS EV3 Community Group . Some of the text and links may have been edited from his original posts for consistency and clarity.  1984 - Kjeld Kirk Kristiansen watched a TV program called "Talking Turtle," where MIT professor Seymour Papert demonstrated how children could control robot "turtles" using LOGO, a programming language he developed. 1988 - The collaboration between MIT and LEGO resulted in LEGO TC Logo in 1988, which allowed students to control LEGO models using computer commands. The video shows Papert demonstrating TC Logo. 1990 - LEGO TC Logo was hampered since the robots you built had to be tethered to a personal computer. LEGO and MIT

Celebrating MINDSTORMS with a Remix Part 1

In honor of the 25th Anniversary of MINDSTORMS, we asked ROBOTMAK3RS to combine a LEGO set of their choice with a MINDSTORMS set. Here is what these five ROBOTMAK3RS came up with.  MINDSTORMS Chess Assistant by Arvind Seshan Overview: When you are new to chess, it can be a challenge to remember which pieces go where. Now, you can use machine learning and LEGO MINDSTORMS Robot Inventor to build a tool to help you learn where all the chess pieces go on the chess board. Sets used: LEGO® Iconic Chess Set (40174) and MINDSTORMS Robot Inventor (51515) Review: I really like how the chess set base can store all the pieces underneath and that the board neatly splits in half for handy storage. The chess pieces themselves are very sturdy and well built. My only criticism is the building of the box itself. It was quite difficult to see what pieces to use and since the entire box is made mostly of thin plates, it took a lot of time and patience. I would have liked the storage area to be sliding dra