Arduino Touch Key Piano Example (BC548B)

September 20th, 2015


You will need the following:

IMG_9744
As many 10k Resistors as you want inputs/keys
IMG_9745
As many BC548B transistors as you want inputs
1x Arduino mega
A breadboard
And some jumper cables.

IMG_9748
Place your transistor so that the emitter(3) is connected to ground, and the collector(1)/base(2) are 1 or more pins apart.

IMG_9749
Place the 10k resistor so that is hits +5v and the collector(1)

IMG_9755
Connect positive to +5v on the breadboard and Arduino, and negative to GND(ground).


Connect a jumper from A0(Analog Input 0) to the Collector pin.
IMG_9757
Connect a jumper to the unused(Base(2)) pin, this will connect to whatever you want to play such as an apple or banana.

Untitled Sketch 2_bb
Connect a speaker/buzzer to pin 3 and GND and it should look like this.

Upload the following code:
DOWNLOAD:
tonekeyboarduno.zip(Uno), tonekeyboardmega.zip(Mega)
(Mega)
/*
Capacitive Tone keyboard

Plays a square-wave at a given frequency when triggered.

 circuit:
 * 10k resistor from +5V to the collector of each BC548B
 * Speaker on Digital Pin 3

 created 20 September 2015
 by Joey Babcock ( http://joeybabcock.me )
 
 **Note this is for arduino mega only./

#include “pitches.h”

// notes to play, corresponding to the 3 sensors:
int notes[] = {
NOTE_C3, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4
};

void setup() {
Serial.begin(9600);
}

void loop() {
for (int curSensor = 54; curSensor < 61; curSensor++) {
// get a sensor reading, pin 54 is equivelent to A0
int sensorReading = analogRead(curSensor);
Serial.print(sensorReading);
Serial.print(” “);
// if the transistor has made contact
if (sensorReading < 500) {
// play the note corresponding to this transistor:
tone(3, notes[curSensor-54], 50);
}
}
Serial.println+(” “);
}

(Uno)

/*
Capacitive Tone keyboard

Plays a square-wave at a given frequency when triggered.

 circuit:
 * 10k resistor from +5V to collector of each BC548B
 * Speaker on Digital Pin 3

 created 20 September 2015
 by Joey Babcock ( http://joeybabcock.me )
 
 **Note this is for arduino mega only./
 */

#include "pitches.h"

// notes to play, corresponding to the 3 sensors:
int notes[] = {
  NOTE_C3, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4
};

void setup() {
Serial.begin(9600);
}

void loop() {
  for (int thisSensor = 14; thisSensor < 18; thisSensor++) {
    // get a sensor reading:
    int sensorReading = analogRead(thisSensor);
    Serial.print(sensorReading);
    Serial.print(" ");
    // if the sensor is pressed hard enough:
    if (sensorReading < 500) {
      // play the note corresponding to this sensor:
      tone(3, notes[thisSensor-14], 50);
    }
  }
  Serial.println+(" ");
}


Comments

Comments Are Not Yet Implemented.