Skip to Content

How to Code a Dirt Volcano

Learn about variables, sequences, algorithms, and loops and code a dirt volcano!

Coders take big problems and turn them into smaller, more manageable problems. Let’s take the classic volcano experiment, an acid-base reaction, and turn it into directions for a robot to complete.

We will start with a big problem and turn it into small steps and commands that a robot can follow.

Big Problem: Make a Volcano

A picture of a volcano on a yellow and white background with "how to code a volcano" in black text.

This post contains affiliate links. As an Amazon Associate, Our Family Code earns from qualifying purchases. Please see our Disclosure Policy for more details.

Vacation Under the Volcano

How to Code a Volcano is part of our Magic Tree House book activity series based on the Magic Tree House books by Mary Pope Osborne

This activity is a great way to pair a STEAM concept with book number thirteen, Vacation Under the Volcano.

Magic Tree House series ad-2

Find more MAGIC TREE HOUSE ACTIVITIES

MAKE SURE TO GRAB THE MAGIC TREE HOUSE BOOKS 13-16 TO FOLLOW ALONG WITH MORE MAGIC TREE HOUSE ACTIVITIES!

WHY ARE UNPLUGGED CODING ACTIVITIES IMPORTANT?

Unplugged coding activities are designed to build the foundation of coding.

These activities allow kids to participate in kinesthetic opportunities that help them relate the concepts they are learning to their own lives and teach children how to think logically about objects.

Kids also learn how to break down large tasks into smaller tasks that are easier to complete and how to identify errors.

Working hands-on makes coding concepts tangible and unplugged coding activities are ideal for young coders.

Unplugged activities are great for classrooms or homes that don’t have access to the internet or a computer and ideal for young students who don’t have experience working with computers.

It’s never too early to start teaching the foundation of coding.

RECOMMENDEDGET STARTED WITH ALGORITHMS AND CODE YOUR ART!

How to Code a Volcano

If you tell a robot to build a volcano for you, would that robot know what to do? 

The answer is no. A robot needs smaller, more clear directions to build a volcano for you. In this activity, we are going to learn how to communicate with a robot with clear steps and commands. 

How to Do a Classic Volcano Demonstration

To conduct the classic volcano demonstration, we must find a place outside or inside that can get a little messy, make a volcano (we used some dirt!), use a small container to hold our slurry, gather our baking soda, dish soap, food coloring, and vinegar. 

Let’s break these steps down into an algorithm, or set of instructions, for our robot to follow. We are going to think about each step as a smaller problem. 

We also tried to use a recycled material for our demonstration too! To hold our chemical reaction, we used an old K-Cup from my morning coffee to put inside our volcano!

how to code a volcano recycled kcup center

Step #1: Find a place to conduct your volcano demonstration.

Do you think you can tell a robot to find a place to conduct your volcano demonstration and have them find the perfect place? Why not? 

For this step, we can use an If-Then-Else statement. An If-Then-Else is a conditional statement that is kind of like answering a true or false question.

If the answer is True, then you do the action listed. However, if the answer is False, you do the something else. 

When giving instructions to a robot, you have to be very specific with your instructions. Our robot instructions could look something like this: 

IF the spot is flat and can get messy
THEN, build a volcano
ELSE, find a new spot.

Step #2: Gather Dirt

To build our volcano out of dirt, we must first gather up some dirt! In order to gather some dirt, we might need some tools like a bucket and a shovel.

For this problem, we can write a sequence to help our robot collect the dirt and bring it to our spot. A sequence is a specific order to follow. If our code was written in the wrong order, the directions would not make sense.

how to code a volcano step 2 gather dirt

Your robot should follow the sequence below. We are going to group the commands into a single function. We will call our function gatherDirt()

A function is a group of commands that can be run with one line of code rather than using multiple lines. To define a function, enter a set of commands between the { and } curly brackets to define the repeated behavior.

For the purpose of this exercise, we are going to keep the commands as they are instead of shortening them. 

func gatherDirt (){
Scoop the dirt with the shovel ()
Fill the bucket with dirt ()  
Dump the dirt in the spot () 
}

Depending on the size of your volcano, you might need to make several trips to get dirt.

You can use a loop to tell your robot to complete the sequence a set number of times. For our volcano, we are going to loop 2 times.

for i in 1 … 2 {    
gatherDirt ( ) 
}

Step #3: Build a Dirt Volcano

For this step, the goal is to write the correct algorithm so that your robot builds a volcano made from dirt around a small plastic container (like a 35mm film container or half a plastic Easter egg). The dirt volcano should be taller than the container. 

How to Code a Volcano build a volcano setup

For this step, we can use an If-Then-Else statement just like we did in Step #1.

An If-Then-Else is a conditional statement that is kind of like answering a true or false question.

If the answer is True, then you do the action listed. However, if the answer is False, you do the something else. 

IF the dirt is taller than the plastic container
THEN stop building, shape the volcano, and move to the next step
ELSE keep adding dirt

You might also like our Fitness Coding Cards to learn more about conditional statements!

Step #4: Prepare Volcano

Code should follow a sequence. For Step #4, we will use a sequence to add materials in the correct order.

Your robot should follow the sequence below in order to prepare the volcano for eruption!

Add 2 Spoonfuls of Baking Soda
Add a Spoonful of Dish Soap
Add 5 Drops of Food Coloring

how to code a volcano acid-base reaction

Step #5: Eruption!

To complete your classic volcano demonstration, give your robot the final command!

Add 1/4 cup of vinegar

how to code a volcano eruption step

The Science Behind the Classic Volcano Activity

This is an acid-base reaction. Vinegar is an acid and baking soda is a base. When combined, they react with each other to produce sodium acetate and carbonic acid, which quickly decomposes into carbon dioxide gas and water.

The bubbles from the carbon dioxide can be seen as the reaction takes place. This type of acid-base reaction is used for baking cakes. The reaction causes cakes and breads (without yeast) to rise! How cool!!

How to Code a Volcano eruption

KEY CHEMISTRY TERMS TO SHARE WITH YOUR KIDDOS

  • Acid – a solution that has a higher amount of hydrogen ions than water (ex. vinegar)
  • Base – a solution that has a lower amount of hydrogen ions than water (ex. baking soda)
  • Neutral– a solution that has a concentration of hydrogen ions equal to water (ex. water)
  • Chemical Reaction – a change in the molecular structure of a substance
  • Reactants – a substance or substances that start a chemical reaction
  • Products – the substance created by a chemical reaction

PRACTICE WITH FRIENDS – TAKE TURNS BEING THE ROBOT

Another fun way to do this activity is to work in a large group to identify your commands.

After you have established the commands and function, you can practice by writing your own code for a friend and see how they act as the machine and run your program.

Can your robot follow your instructions and complete the volcano demonstration?

How to Code a Dirt Volcano Free Coding Worksheet – Build Your Code!

Print out these two pages of code, cut out the blocks, and put your code in the correct steps and sequence!

This is a great way to visualize your code and work hands-on with this awesome unplugged coding activity! 

how to code a volcano build your code pg1

PIN THIS IMAGE TO SAVE THIS UNPLUGGED CODING + SCIENCE ACTIVITY!

orange volcano gif

Unplugged Coding Activities

Find more Elementary unplugged coding activities to work on basic coding skills!

Meet Toni, the Maker Mom behind Our Family Code

A picture of Toni, the author, wearing a green tie dyed shirt.

Hey there, I’m Toni! I’m a software engineer and Maker Mom that finds my joy in unleashing my children’s curiosity by exploring STEAM concepts with my fantastic five!

When I’m not chasing toddlers or raising tweens, you can find me tearing things up and putting them back together over here at Our Family Code.

I am the owner and content creator of multiple educational websites designed to increase access to STEAM & STEM education with a focus on teaching computer science and coding to kids of all ages!

You can also find out more about me by visiting ToniGardner.com!

STEAM KID Activities logo
A picture of the logo for Brandicionado.com.
A picture of the logo for RocktheSteamteam.org
A picture of the logo for GetMovingMama.com
our family code horizontal logo
A picture of the logo for ThisKidCanBake.com
A picture of the logo for tonigardner.com
A picture of the logo for lodeofcode.com

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This site uses Akismet to reduce spam. Learn how your comment data is processed.