Saturday, 6 July 2013

Chiptune Chime


My attempt at a didgital windchime using Arduino and piezos


Fritzing for the electronics set-up with Arduino.




I used cat5 cable and piezos available at a bit more of a premium price from Maplin. The cat 5 cable is good because its already paired and you get 4 pairs so lots of cable for cheap price, its also quite stiff so can be modeled into position and stay. 

Resistors on the piezos are 1M Ohm and the one on the speaker is 1K Ohm.

The Arduino code is as below thyat I have adapted from the tutorial mentioned in it:


/*

 created 21 Jan 2010
 modified 9 Apr 2012
 by Tom Igoe

This example code is in the public domain.

 http://arduino.cc/en/Tutorial/Tone3

 */

#include "pitches.h"

const int threshold = 10;    // minimum reading of the sensors that generates a note

// notes to play, corresponding to the 3 sensors:
int notes[] = {
  NOTE_FS4, NOTE_GS4,NOTE_DS4, NOTE_CS4, NOTE_AS4 };

void setup() {

}

void loop() {
  for (int thisSensor = 0; thisSensor < 5; thisSensor++) {
    // get a sensor reading:
    int sensorReading = analogRead(thisSensor);

    // if the sensor is pressed hard enough:
    if (sensorReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[thisSensor], 20);
    }
  }
}


No comments:

Post a Comment