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:

Further Reading & Links

Recent Posts

Ultimate Scrolling Background & Character Animation | Step-by-Step Scratch Tutorial

we’ll walk you through one of the most exciting concepts in 2D game development: the scrolling background and character animation effect. This type of animation makes your game environment feel alive...

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

Learn step-by-step how to build a colorful, interactive virtual piano using Scratch and the Music Extension. By the end of this post, you’ll know how to build a virtual piano Scratch project, create...

Build a Text-to-Speech Translator in Scratch (Supports 45+ Languages!) – Ultimate Guide

Have you ever wanted to build your own multilingual translator that can speak in different languages? With Scratch, you can! In this exciting project, we’ll guide you through building a Text-to-Speech...

Date and Time Virtual Assistance using Text-to-Speech: Create an Alexa-Like Smart Assistant Using Scratch

Do you want to build your own digital assistant in Scratch that can respond to voice commands and share the current date and time? In this comprehensive Scratch virtual assistant tutorial, you’ll...

Mastering Scratch Motion Blocks: A Complete Tutorial for Beginners and Game Developers

One of the most powerful and foundational aspects of Scratch programming is motion blocks—used for controlling sprite movements and building dynamic, interactive projects. Motion blocks are...

Build an Interactive Odd & Even Quiz Game in Scratch: A Step-by-Step Tutorial

In this Scratch quiz game tutorial, we'll build an engaging Odd & Even numbers quiz—a classic math quiz game in Scratch that’s perfect for beginners and educators alike. You’ll guide your players...

Create Amazing Sprite Looks with Looks Blocks: A Complete Guide to Visual Sprite Effects

The “Looks” blocks in Scratch are the secret sauce behind smooth costume changes, exciting visual effects, and immersive game environments. Whether you're just starting your Scratch coding projects or...

Build Your Own Scratch Painting App: A Fun Scratch Coding Tutorial for Kids

In this tutorial, we’ll walk you through creating a painting app in Scratch—a project that combines creativity, problem-solving, and interactive design. Using Scratch’s pen extension, you’ll build an...

Build a Fun “Bouncing Ball” Pong‑Style Game in Scratch – Step-by-Step Guide

Build a Fun "Bouncing Ball" Pong‑Style Game in Scratch - Step-by-Step Guide. This bouncing‑ball game combines fundamental elements: Motion & coordinate control, Sensing sprite overlaps, Variables for...

How to Make a Snowman Chase Snowflakes – Step by step Scratch Game Tutorial

Welcome to this interactive Scratch coding tutorial! If you’ve ever wanted to learn Scratch coding, build fun Scratch projects, and develop a Scratch game idea, there’s no better place to start than a...

Mastering Scratch Pen Blocks Tutorial: Draw Shapes in Scratch with Code

In this post, we'll explore how to use pen blocks in Scratch, demonstrate hands-on Scratch geometry project workshops, and empower you to draw shapes in Scratch using clean, loop-based code. Along...

How to Make a Star Trail Animation in Scratch – Easy Scratch Project Tutorial

In this detailed Scratch tutorial, you'll discover how to combine block programming logic, Scratch coding techniques, and creative flair to create animations in Scratch. By the end, you'll have a...

Build a Simple Calculator in Scratch – Step‑by‑Step Guide!

In this Scratch calculator tutorial, we take you from watching a quick demo to building a functional calculator in Scratch—complete with user prompts, number input, and basic arithmetic operations...

Even or Odd Number Finder – Scratch Game by Kodex Academy

The concept is simple but powerful. The game randomly shows numbers on the screen, and the player must decide whether the number is even or odd. They click the correct button (Even or Odd), and the...

Learn to Code with Eat Yummy Taco – A Fun Scratch Game for Kids

Get ready to dive into a deliciously engaging game that will tickle your taste buds and test your reflexes — all while learning how to code! “Eat Yummy Taco” is a beginner-friendly and fun Scratch...

How to Build an Interactive Hide and Seek Game in Scratch 3.0: A Beginner’s Guide by Kodex Academy

Every good game begins with a scene. In Scratch, this means choosing a backdrop and designing the space where the game happens. This section guides you through selecting or creating a background that...

My Blocks in Scratch Explained | A Complete Guide to Custom Blocks for Beginners (Scratch 3.0)

The My Blocks palette in Scratch is essentially your personal toolset. While the other palettes give you predefined blocks (like motion, looks, or sound), My Blocks allows you to create your own...

Understanding Block Programming: A Fun and Interactive Approach to Coding

One of the best ways to introduce kids to programming is through block programming, a method that simplifies coding concepts using visual blocks instead of writing complicated lines of code...
Scroll to Top