Project 1 | Cardboard Piano

Reference: Project 1 Page

Make a project that demonstrate the following technical skills. Digital or analog input PWM or tone output Control of servomotors (optional) if you want to do something mechanical

Summary: I managed to build a decent circuit but experienced difficulty with the fabrication of the case. I tried using cardboard boxes which turned out a good prototype on the first try but I will need to continue improving the casing to have a better outcome. The speaker doesn't output as much noise as I would have hoped.

In the process of making this I also burnt my thumb using the glue gun and cannot craft things anymore. So this mediocre cardboard casing will have to do for now although Im explloring how to make an origami inspired piano construction.

I decided to make a cardboard piano.

The circuit design was straightforward

  • Using a 9v battery power source
  • Used a 7805 voltage regulator to output 5 volts
  • Connected 7 digital input pins for the 7 keys on the piano
  • Ouputting the content using a speaker


  • Works


  • Low Speaker Volume
  • Doesn't output sound the way I'd expect a real piano to
  • Subpar casing. I had no other constructions method available to me. I have learnt enough about making this in the first iteration that I can build a better case. I connected the switches using aluminium foil but I could find a better mechanism. The piano keys should also be folded properly.




#include "pitches.h"

const int threshold = 30;      // minimum reading of the sensors that generates a note
const int noteDuration = 20;   // play notes for 20 ms

const unsigned long eventInterval = 1000;
unsigned long previousTime = 0;

// Borrowed from
#define T_C 262
#define T_D 294
#define T_E 330
#define T_F 349
#define T_G 392
#define T_A 440
#define T_B 493

int speaker = 16;

void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);
  pinMode(8, INPUT);
  pinMode(9, INPUT);
  pinMode(speaker, OUTPUT);

void loop() {
  int key1 = digitalRead(2);
  int key2 = digitalRead(3); 
  int key3 = digitalRead(4); 
  int key4 = digitalRead(5); 
  int key5 = digitalRead(6);
  int key6 = digitalRead(7); 
  int key7 = digitalRead(8); 
  int key8 = digitalRead(9); 

  /* Updates frequently */
  unsigned long currentTime = millis();

  /* This is the event */
  if (currentTime - previousTime >= eventInterval) {
    /* Event code */
    Serial.print(" | ");
    Serial.print(key1 == LOW);
   /* Update the timing for the next time around */
    previousTime = currentTime;

  if(key1 == LOW)
    tone(speaker, T_C);

  if(key2 == LOW)
    tone(speaker, T_D);

  if(key3 == LOW)
    tone(speaker, T_E);

  if(key4 == LOW)
    tone(speaker, T_F);

  if(key5 == LOW)
    tone(speaker, T_G);

  if(key6 == LOW)
    tone(speaker, T_A);

  if(key7 == LOW)
    tone(speaker, T_B);