There’s no denying it. For better or worse, technology is taking over the world. Being able to program a computer is a skill that will serve our children well in the future. I didn’t write my first simple program until I was 18, but ultimately I got my PhD and worked full-time writing and operating codes for scientific research. It was a skill that I’m so grateful to have developed as it now allows me to earn money from home and be with my kids all day. I don’t expect my children to wait until they are in college to learn the principles of coding. I believe that even my kindergartner is fully capable of getting down some of the basics.
I’m so honored to be a part of the 28 Days of Hands-On STEM Activities series hosted by Left Brain Craft Brain this year. The free, printable “Coding a LEGO Maze” activity that I’ve created as part of this series can grow with kids. Children as young as 5 or 6 can attempt the easiest challenges, while the concepts introduced in the harder challenges are covered in any introduction to programming class.
There are so many baby steps involved in learning how to think like a programmer. Throughout the past several years, I’ve programmed in at least 6 different computer languages (C, C++, Java, Fortran, Matlab, and Python). For a beginner, what’s important is not the specifics of a language (called the syntax). Rather it’s better to understand the commonalities between languages which are the building blocks of any programming language. These LEGO mazes, which can be solved with “code” using paper rather than a computer, illustrate 4 levels of difficulty and include a variety of programming concepts. While these Levels will be described in more detail below, here is a quick overview:
- Level 1: The child can see the specific problem at hand and step by step walk their LEGO figure out of the maze. Like the game Robot Turtles, this easiest level teaches the child to think from a point of reference different than their own. The child’s left may not be the same as the figure-in-the-maze’s left, but even the youngest kids can learn this valuable skill of switching reference frame.
- Level 2: Hopefully, by the time they’ve mastered Level 1, your child will realize that it’s a bit tedious to tell the character to move forward 7 times in a row. Rather, it would be handy to just have a way to say “Do this next command 7 times.” This level introduces the concept of “for loops.”
- Level 3: Older children might be ambitious enough at this point to realize that an awful lot of work goes into solving a specific maze using the method of Levels 1 and 2. With the introduction of “while loops” and “if statements”, kids can challenge themselves to write as short a program as possible to solve a specific maze. The programmer just needs to consider all possibilities at any random location for their LEGO figure and decide the best generic sequence of actions. For example, what should the character do if there’s an opening to their left? What if they’ve hit a dead end?
- Level 4: While kids will hopefully experience success in Level 3, they will likely find that if they try to use their code on a different maze, it may not work. It’s possible that their figure will get stuck in what programmers call an “infinite loop”, repeating the same behavior over and over again without being able to escape. By introducing a random number generator, older kids can write a program that can get their figure out of any maze.
At the end of this process, the most mature kids will realize that it would be great if their LEGO figure could remember where he had already been so that he could systematically cover ground instead of seeming to wander aimlessly. This could motivate a discussion of more advanced programming concepts such as memory and stored variables.
Recommended Age Range: Kindergarten, Elementary, Middle School, High School
Time Required: ~1 hour if laminating
Difficulty: Easy to prepare, Level 3 and 4 challenges may only be appropriate for kids in late elementary or older
Cost: Free printable, less than $2 to laminate (does not include cost of LEGO or DUPLO bricks which are optional)
- Paper for printing Coding a LEGO Maze free printable
- Thermal laminating pouches
Supplies & Tools:
- Thermal laminator
- Paper cutter (optional)
- LEGO figure (or other figure of similar size)
- LEGO or DUPLO bricks (optional)
1. The first time only, you will need to print, laminate (optional, but recommended), and cut out all the pieces in the Coding a LEGO Maze free printable.
2. Next, you will need to set up your maze. You can use any of the 5 provided mazes or if you choose, you can make your own maze with the blank grid provided. Once you’ve selected your maze, there are 3 options for setup:
Option 1: If you do not have LEGO or DUPLO pieces or if you would just rather save time, you can use the provided mazes as-is. You just need a figure to place on your maze that has a front, so that you know which way it is facing.
Option 2: If you are a fan of LEGO, you can cover the gray parts of the provided mazes with LEGO bricks.
Option 3: If you are a fan of DUPLO, I recommend cutting out the white part of the maze, placing it on a DUPLO board and then covering the board with DUPLO bricks to form the walls. You could also just place the DUPLO pieces directly on the laminated maze, but I found that didn’t work very well as the walls needed to be pretty high in order to have all the pieces connected together, which makes it hard to move the figure.
Once you’re finished, your maze might look something like this:
Level 1: The first step for youngest kids is to teach them how to think from the point of view (reference frame) of the character in the maze. To do this, place the figure at the start of the maze and give your child all the green cards in 3 piles (Go Forward, Turn Right, and Turn Left). Your child needs to place the instructions that he or she thinks the character needs to follow into a long list. For example, in the LEGO (not DUPLO) maze above, construction worker Emmet needs to: Go Forward, Go Forward, Go Forward, Turn Right, Go Forward, etc. I had my 6 year old place all the cards he thought he would need to get Emmet out of the maze into a list. I was planning to move the figure myself using the “code” he had written, but he really wanted to move his character himself. I had him follow each command one at a time and flip over the cards as he executed them. This worked out great. My only caution is that you should pay attention to left and right turns. When Emmet was walking toward him, my son placed a Turn Right card when really he needed a Turn Left. When he got to that card as he was flipping them over, I had him place the card in Emmet’s hands to show him his mistake. He caught on and fixed it right away.
Level 2: Once your child is good at Level 1, you can show them how they can use a loop that says “For ___ Steps” to do a command rather than just repeating the same card over and over. For the example above, the solution would look as shown. Notice that the command (or commands) inside a “for” loop are indented slightly. Not all coding languages are picky about this indent, but some are, and it makes the code more human readable anyway, so it’s a good habit to get in. At the end of the “for” loop, you place an “End” card to note where the loop ends. Again, not all programming languages require this “end” command, but many do.
Level 3: I know my kindergartner is far from this step, but eventually, once kids are able to think more abstractly, you can teach them about conditional “if” statements. Once I learned about if statements in college, I couldn’t stop applying them to my daily life. It basically felt like every decision could be summarized using one of these decision trees. For example, if I was trying to decide where to have dinner, I might think something like:”IF my friend Kelly is free,
—> then I will go get Thai food with her.
ELSE IF they are serving something edible at my dorm’s cafeteria,
—> then I’ll pick something up there.
—> I will stay in my dorm room and have some cereal and ice cream.
Thankfully, I grew out of that after I stopped spending tens of hours in the computer lab each week.
Basically, when you are writing a program, you think about all the possibilities and evaluate what you should do in each case and in what order (or with what priority). For example, our character in a maze only faces a limited number of options. He may or may not have walls in front of him or to his left or to his right. However, there are so many possible codes that can be written based on these limited options. The child could decide to tell their person to follow this command: “If there is no wall in front of me, go forward. End.” That code alone will actually solve one of the provided mazes. For mazes that require turns, they may come up with something more like the code below.
This code basically translates to the following instructions: “If I can turn left, turn left. Otherwise if I can turn right, turn right. Otherwise if I hit a dead end, turn around. After I’m done checking those conditions, go forward. Repeat.” The “repeat” comes from the red “while” loop around the whole code. By saying “While still in the maze (a bunch of code) End” what that means is keep repeating that (bunch of code) until you’re not in the maze anymore. I should also point out that one piece of code I didn’t use was ELSE. “IF” means definitely do this if the specified condition is true. “ELSE IF” means do this if the specified condition is true AND the “IF” and “ELSE IF”s that came before were not true. “ELSE” means do this if everything above has failed (like my cereal and ice cream dinner fall back). “END” means this is the end of the “if” statement (or “while” or “for” loop).
Level 4: If your child tries the above code (or their corresponding similarly structured code) on all the mazes provided, they will likely find that the code does not work on all mazes. In some cases, because of the priority given to that left turn (or whatever priority their code uses), their character will get stuck going back and forth over the same path repeatedly (an infinite loop). To solve this problem without introducing more complicated concepts like storing variables, a random number generator can be used to remove the priority of one choice over another. For example, instead of saying “If I can turn left, turn left,” I could instead say, “If I can turn left, turn left half of the time.” Since we are not ACTUALLY using computers, instead of using a random number generator function, your kids can just use a dice roll instead. By introducing this randomness, the character may not follow the most logical path to get out of the maze, but he will not get stuck doing the same thing over and over and over again. Here is an example of one possible code that I *think* will work for any maze. It is not the only “right” answer and probably not the best answer. I discourage you from showing your child my answer before they give it a shot on their own. Coding is a process of trial and error. Lots of testing is almost always required before programmers come up with something new that works.
Don’t forget to check out all the amazing posts in the 28 Days of Hands-On STEM Activities for lots more ideas to get your kids interested in these wonderful fields! If you thought this post was useful, please consider subscribing to my newsletter (and receive access to exclusive, free, educational printables)!
Click here for more Technology and Engineering activities for kids.
Learning Activities for Kids
Best Books for Kids
What an interesting twist on a LEGO maze! I had no idea coding could be incorporated into something like this (then again, I know nothing about coding, lol!)
It’s kind of crazy, but sometimes it seems like coding can be incorporated into pretty much anything. Thanks for stopping by!
This is amazing!! I love it! It incorporates what my son loves: Lego and learning coding!
Thank you so much for the printables that go with it; I am really looking forward to doing this myself and then letting my son have a go!
Aww, thanks! I hope your son has fun. :)
Kurt E Henriksen
Great material. Is it possigle to get the printable pages as a word document, so I can translate it into danish?
I’m very sorry, Kurt. I didn’t make this document in Word. I made images in Photoshop.
Thank you so much for this. I have been looking for just such a resource for a long time and will fit in nicely with the coding program I teach. Amazing!!
I’m so glad it’s helpful to you, Alison! :)
Hey! Thank you so much for such a simple coding practice activity! I volunteer at a library and run engineering events there for the kids (many of whom are underprivileged) and have been toying with the idea of trying to get them interested in coding but couldn’t think of a way to do it without having them directly on computers. I stumbled upon your activity and instantly fell in love with it! I have modified it slightly so I can do it with a larger group of kids but I think it is going to work great! I appreciate the hard work you put into making this and for providing the printable sheets! I am super excited to try out this program with the kids tomorrow! Thanks again!
You are very welcome. I’m so glad you’ll be able to use my material. Good luck tomorrow! I hope it goes well! :)
I am so excited about doing this with my son! He’s pretty excited too :). Thank you for taking the time to explain this – I love how you broke it up into 4 different levels. I’m following your blog now and looking forward to doing more activities you post!
I’m so glad you like it! Thank you for subscribing. :)
This is an awesome post – thanks for sharing. I love the idea of coding without sitting in front of a computer screen. We’ve been doing similar things on our blog : http://www.beyondawesomebricks.com
You are very welcome. I’m glad you enjoyed it. It sounds like you offer a wonderful service. I’m sure the kids have a lot of fun!
What a great idea you have! Thanks for sharing.
After reading this, I feel I’m at level 2. Coding is so hard, but it’s fun.
You are so welcome! I’m glad you’re having fun. :)
Hi michelle! Great blog, love the activities!
I was wondering if an “&” could be added to lvl 3 codes for mazes, somenthing like:
If to my right|
if to my left| & in front of me|
Else if to my left|
Hi Melisa! You can totally do that. In real coding, “ands” and “ors” are absolutely allowed. I don’t actually have the same software that I used to create this document, so I tried to make these labels as close as I could! In actual coding, you would need to use parenthesis, but I think for the purpose of this offline coding activity, it’s still instructive even without them. I hope this helps! https://researchparent.com/wp-content/uploads/Bonus_Ands_and_Ors.pdf
Stem for you
Awesome blog. I love the activities
Thank you so much!
I can’t believe you have done ALL this, and provided it all for FREE.
THANK YOU SO MUCH.
This is genius. THis is amazing.
Thank you again. <3
You are so welcome! I hope my resources are helpful to you. Have a great day!
This is literally so amazing! Glad that I read your blog & got to know such an interesting lego maze to teach coding for kids. Never imagined we can make kids understand coding concepts with the help of such fascinating games. In this digital age, making kids aware of different programming languages at early stage is definitely the need of the hour. I am pretty sure the activity which you have shared will be so much beneficial in creating a perfect foundation for kids in acquiring different coding concepts in a fun way. Thank you so much for sharing such a great article with us.
I’m so glad it was helpful to you! :)
This is such a wonderful website, with easy to do activities and with such detailing and clear instruction. Thank you so much!
Thank you! I’m so glad you find my posts helpful! :)
This looks like a fun coding activity for kids and would help them to learn and understand coding fundamentals. Thanks for sharing!
You are so welcome! I hope it is useful!
Games and activities like these can help kids develop many life essential skills. It can even make learning fun for kids and allows them to explore their creative side, Thanks for sharing these ideas!
I am so glad they are helpful! :)
This is amazing!! I love it! It incorporates what my son loves: Lego and learning to code!
I hope he enjoyed this activity!
I had my 4th and 5th grade students create their own Lego Maze right before our winter break and they had so much fun. They really got into it. We kept the coding concept simple and that really was pretty challenging. It was a good beginning for learning how to code. If you are doing multiple classes, at one time, over estimate the number of Legos needed. I had 4 classes and 3000+ Legos was not enough.
Wow, that is impressive, Barbara! Thank you for sharing your experience and wisdom with us. I’m so glad your students enjoyed the activity!