Scratch Virtual Piano Tutorial: Build Your Own Piano in Scratch (Music Extension)

Scratch Virtual Piano Tutorial Build Your Own Piano in Scratch

Learn step-by-step how to build a colorful, interactive virtual piano using Scratch and the Music Extension. Perfect for beginners, educators, and kids ages 7+ who want to explore coding and music!

Video by Kodex Academy: 🎵Build Your Own Piano in Scratch! | Step-by-Step Music Extension Tutorial
You can watch the full tutorial on YouTube here.

Introduction: Scratch Virtual Piano Tutorial

Welcome! Today we’ll learn how to make a piano in Scratch, guiding you through a fun Scratch virtual piano tutorial, designed especially for Scratch piano project step by step learning.

Scratch is an amazing platform for block-based coding that teaches programming logic through creative projects like this one. By the end of this post, you’ll know how to build a virtual piano Scratch project, create piano keys Scratch, and even code a piano in Scratch complete with instrument selection, beats, and tempo. Ready to start?

What You’ll Learn & Why It Matters

In this tutorial, you’ll build a fully functional virtual piano Scratch coding project using:

  • Scratch music extension
  • Sprite design with the Paint Editor
  • Event handling with “When this sprite clicked”
  • Motion blocks to anchor keys
  • Music blocks: setting instrument & playing notes
  • Cloning & customizing code for multiple keys

By the end, you’ll have built a Scratch piano game coding project you can play, expand, or even embed in your own website. This is ideal for Scratch coding for beginners, fans of Scratch music coding tutorial, or anyone wanting to learn coding with Scratch piano.

Scratch Code – Build Your Own Piano in Scratch (Music Extension)

  1. Navigate to scratch.mit.edu. Log in or create an account—you’ll need to save your project.
  2. Click Create to start a new project.
  3. Remove the default Scratch Cat sprite for a blank canvas.
  4. Save the project naming it “Virtual Piano Scratch” or similar.

Now you’re set to jump into this Scratch piano project step by step tutorial.

1. Adding the Music Extension

To add sound:

  1. Click the blue Extensions button (bottom-left).
  2. Select Music.
  3. You’ll now see the Music Extension, containing multiple music blocks

The Music Extension includes:

  • play drum () for () beats
  • beat tempo
  • play note () for () beats
  • set instrument to ()
  • set tempo to ()
  • And more Scratch Wiki.

This powerful block set transforms your project into a full Scratch music coding tutorial.

2. Designing Your Piano: Costumes & Sprites

A well-designed visual improves interaction. Here’s a deeper dive into crafting your piano layout:

Step-by-Step

  1. Delete Scratch Cat for a clean start.
  2. Click Paint New Sprite.
  3. Set backdrop to something lively—e.g., “Spotlight” for a stage vibe.
  4. Create your first white key:
    • Use Rectangle tool, size ~140×40 px.
    • Fill with white, outline black.
  5. Duplicate it until you have 8 white key sprites.
  6. Space them evenly (use “go to x/y” in paint view to align).
  7. Add black keys:
    • Paint another sprite as a smaller (~60×25 px), black rectangle.
    • Duplicate 5 times, position them between certain white keys (e.g., between C-D, D-E, etc.).
  8. Name your sprites logically: “WhiteKey1 (C)”, “BlackKeyCSharp”, etc., for easy coding.

💡 Pro Tip: Group by using suffix .key to quickly filter similar sprites.

3. Coding the Keys: Blocks, Events & Notes

Transforming your static sprites into interactive piano keys involves thoughtfully combining Event, Motion, and Music blocks—let’s dive deeper!

Understand the Required Blocks

  • Event: For clicking or keypress
  • Motion: To anchor key position
  • Music: To play sounds
  • Graphic Effects: Provides visual feedback

a. Event Block: “When this sprite clicked”

This block enables each key sprite to react to mouse clicks:

Why it’s important: It’s the main trigger—without this, clicking a sprite wouldn’t do anything.

Tip: For keyboard responders (e.g., playing notes via the “A”, “S”, “D” keys), use blocks like when key [A] pressed. This opens the door to building Scratch piano game coding features like a playable keyboard.

b. Motion Block: “go to x: [ ] y: [ ]”

Purpose: Keep your keys anchored.

Each key sprite stays fixed on its screen position. Why is this important?

  • Prevents keys from drifting when clicked or animated.
  • Allows consistent code cloning—so when you duplicate, each key’s code remains properly aligned.

💡 Pro Tip: For keyboard shortcuts, storing consistent go to positions is crucial—your code remains organized, and visuals stay neat.

c. Music Blocks: Instrument & Play Note

Setting the Instrument
Choose your instrument using:

Switch it to “Electric Piano”, “Clarinet”, or even “Synth Drum” to experiment with Scratch music extension variety.

Playing the Note

  • MIDI note 60 = Middle C (C4).
  • Adjust note numbers 61–67 for the octave.
  • Length of 0.5 beats offers nice responsiveness.

Enhancements:

  • Allow faster note repetition: Use play note __ until done.
  • Veil with sleep effect:

d. Effect Blocks (Visual Feedback)

Add color or size changes to visually indicate which key is pressed:

Children love seeing keys “light up” when played! This visual component enhances engagement.

Putting it All Together: Full Script Example

Now you have the complete routine for each key—just duplicate and tweak go to positions and note values to cover the full keyboard!

4. Coding All the Keys: Simplifying Through Cloning

Duplicate the Script for White Keys

  • Use the duplicate icon to copy the sprite + script.
  • Update go to X coordinate (e.g., -105, -70…).
  • Change play note [60] to 62 (D), 64 (E), etc., for the next keys.

Add the Black Keys

  • Duplicate the black key sprite and script.
  • Adjust the Y coordinate for the smaller black keys (typically ~20 px higher).
  • Use MIDI notes 61 (C#), 63 (D#), 66 (F#), etc.

Use Broadcasts for Shared Code (Alternative Method)

For more advanced users:

  • Send broadcasts like broadcast [PlayC] when clicked.
  • Add listeners in a single “Sound Manager” sprite:

Encourages cleaner code organization, ideal when scaling or adding features like recording.

5. Enhancing with Keyboard Input: From Click to Typing

Replace click events with keyboard triggers:

Piano NoteKey Press
C4A
D4S
E4D
F4F
G4G
A4H
B4J
C5K
  • Map A–K to white keys; W, E, T, Y, U to black keys.
  • Benefits: Enables Scratch piano game coding, typing-play interactions, and paves the way for game-like Play-Along modes.

Enhancing the Virtual Piano Features

Let’s level up the piano into a full musical experience.

A. Instrument Selector

Add a drop-down or toggler sprite to let users swap instruments:

Gender options: flyers like “Electric Piano,” “Synth,” “Marimba”.

B. Tempo & Beat Controls

Create control sprites:

  • Tempo Up:
  • Tempo Down:

Use beat tempo block to make the tempo visible.

C. Visual Effects & Animations

Enhance visuals:

  • Add size by 10 and size by -10 for zoom effects.
  • Use bubble effect for sparkle responses.
  • Animate backdrop change per instrument.

D. Recording & Playback

Implement a recording feature:

  • Create lists: NoteList & TimeList.
  • Start timer on green flag and clear lists.
  • On key press:
  • Playback with PlayBack broadcast looping through list.

E. Chord Mode

Let keypad simulate chords:

  • Define multiple notes per key.

Simultaneously or quick-sequenced to simulate chords.

F. Note Training & Games

Add a “Guess the Note” or “Follow the Melody” game:

  • Randomly choose a note and highlight the key.
  • Wait for the user’s click, give feedback.
  • Store high scores using cloud variables (if enabled).

This makes it an educational Scratch piano game coding tool.

Complete Code Samples for Virtual Piano in Scratch

Below is a fully annotated script for the C key, integrating many of the advanced features.

For black keys and other features like keyboard support, duplicate & customize accordingly.

Conclusion

You’ve built a full-featured virtual piano Scratch coding project:

  • Designed colorful piano keys
  • Coded interactive clicking and keyboard support
  • Added effects, instrument and tempo controls
  • Included recording and game-like capabilities

All in an easy-to-use, shareable Scratch file—perfect for schools, home coding projects, or your personal digital instrument.

📣 What next?

  • Expand your piano with more octaves or piano switches.
  • Add chord modes or multi-track recording.
  • Integrate your piano into a bigger Scratch game.

Call to Action

  1. Don’t forget to check out the full video tutorial by Kodex Academy here: Build Your Own Piano in Scratch! | Step-by-Step Music Extension Tutorial by Kodex Academy
  2. Like, comment & share the video
  3. Visit kodexacademy.com
  4. subscribe to the Kodex Academy YouTube channel for deeper Scratch content.

Happy coding with Kodex Academy! 🚀

Learn More with Kodex Academy

At Kodex Academy, we’re passionate about helping students learn coding in creative ways. This project teaches more than Scratch—it empowers young minds to build tools that work in the real world.

Explore more:

Stay updated with new content, free tutorials, and coding challenges!

Further Reading & Links

Recent Posts

How to Make a Math Racing Game in Scratch | Game Concepts and Complete Tutorial

In this tutorial, you’ll learn to build a Math Racing Game in Scratch. Players solve math problems to move their character forward; wrong answers benefit the opponent. It’s a race of speed, accuracy...

How to make Memory Skill Game in Scratch | Card Matching Game in Scratch – Part 2 | Step-by-Step Coding

In this tutorial you'll learn how to make memory skill game in Scratch / card matching game in Scratch. This is a great beginner‑to‑intermediate project for scratch tutorial game, scratch programming...

How to make a Card Matching Game in Scratch | Memory Skill Game in Scratch – Part 1 | Step-by-Step Coding

In this Scratch tutorial, we'll walk you through how to make a card matching game in Scratch, also known as a memory game or skill game. This is a popular beginner project that introduces essential...

Create a Quiz Game in Scratch | Spelling Test in Scratch | Picture Identification in Scratch

Want to make learning spelling fun, visual, and interactive? In this Scratch tutorial, you'll learn how to make a spelling quiz game in Scratch using picture identification, text-to-speech, and...

How to make a Double Jump Game in Scratch | Platformer game in Scratch | Step by Step Coding

How to make a Double Jump Game in Scratch. Scratch is a fantastic platform for beginners to learn programming by making games, animations, and interactive stories. Among the many kinds of games...

How to Use Variables in Scratch | Variable Blocks in Scratch | Complete Tutorial

Introduction: Variable Blocks in Scratch Whether you’re just getting started with Scratch programming or looking to take your projects to the next level, understanding variables and lists is...

How to Make Earth Revolve Around the Sun in Scratch: A Complete Tutorial & Enhancements

Animating Earth revolving around the Sun is a classic beginner/intermediate Scratch animation project. It combines trigonometry (sine & cosine), variables, loops, and visual scripting. Kids can learn...

How to Make a Game in Scratch | Snake Game in Scratch | Step-by-Step Game Coding

In this tutorial, we’ll build a Snake Grid style game in Scratch step by step (very similar to the Kodex Academy example). By doing this, you’ll cover many of the core Scratch building blocks. We will...

How to Use Operator Blocks in Scratch | Full Guide with Live Coding & Examples

One of the most powerful features in Scratch is its Operator Blocks — essential for handling math operations, logic comparisons, and string manipulations...

How to Create a Thirsty Crow Story in Scratch | Animation Story in Scratch for Kids

In this tutorial, you’ll learn how to create the classic “Thirsty Crow” story in Scratch, using simple animation, voice, and sprite actions. This is a perfect project for kids who are new to coding...

How to Create a Dodge Ball Game in Scratch: A Complete Step-by-Step Tutorial for Beginners

This step-by-step tutorial will guide you through how to create a Dodge Ball game in Scratch from scratch! In this game, you’ll control a character trying to dodge falling balls, earn points, and...

How to use Sensing Blocks in Scratch | Scratch programming for beginners | Live Coding with Examples

In today’s session, we’re diving deep into one of the most powerful features of Scratch — Sensing Blocks. These blocks allow your projects to interact with the world, detect touches, respond to...

Build an Egg Shooting Game in Scratch: Step-by-Step Coding | Complete Guide for Beginners

Learn how to create a fun, interactive shooting game in Scratch with this detailed tutorial inspired by classic arcade games. Perfect for kids and beginners looking to dive into Scratch programming!...

How to Make a Maze Game in Scratch | Step by Step Coding | Full Tutorial & Enhancements

Introduction: Why Build a Maze Game in Scratch? If you’re looking for a Scratch beginner project idea that’s fun, interactive, and educational, then building a maze game in Scratch is the...

Scratch Control Block Tutorial: Full Guide with Loops, Conditions, Cloning & Code Examples

“Control blocks” in Scratch are those blocks (from the Control category) that manage the flow of your script: when things happen, how many times they happen, making decisions, repeating actions...

How to Create a Car Racing Game in Scratch – Part 2 – Step-by-Step Coding

Welcome to your ultimate guide on how to make a car racing game in Scratch—a step‑by‑step tutorial. You'll learn Scratch game development techniques, see actual code blocks, and discover enhancements...

How to Make a Hurdle Jumping Game in Scratch – Build a Fun Hurdle Runner with Score & Win Screen

Are you ready to create your very own hurdle jumping game in Scratch—just like the iconic Chrome Dino or Super Mario? 🎮 Whether you're new to Scratch or just looking for your next fun project, this...

How to Create a Car Racing Game in Scratch – Part 1 – Step-by-Step Coding

In this Scratch car racing game tutorial, we’ll walk you through how to create a fully functional, visually exciting, and incredibly fun car racing game using Scratch. In this blog, we’ll cover: How...
Scroll to Top