Tutorial.Tone2 History

Hide minor edits - Show changes to markup

June 12, 2012, at 04:22 PM by Tom Igoe -
Changed lines 32-37 from:

The code for this example is very simple. Just take an analog input and map its values to a range of audible pitches. Humans can hear from 20 - 20,000Hz, but 100 - 1000 usually works pretty well for this sketch.

You'll need to get the actual range of your analog input for the mapping. In the circuit shown, the analog input value ranged from about 400 to about 1000. Change the values in the map() comand to match the range for your sensor.

to:

The code for this example is very simple. Just take an analog input and map its values to a range of audible pitches. Humans can hear from 20 - 20,000Hz, but 120 - 1500 usually works pretty well for this sketch.

You'll need to get the actual range of your analog input for the mapping. In the circuit shown, the analog input value ranged from about 400 to about 1000. Change the values in the map() command to match the range for your sensor.

May 02, 2012, at 03:36 AM by Scott Fitzgerald -
Changed line 41 from:
to:
November 16, 2011, at 04:08 AM by Scott Fitzgerald -
Changed line 41 from:
to:
September 30, 2011, at 03:04 AM by Scott Fitzgerald -
Changed line 41 from:
to:
January 12, 2011, at 12:48 PM by Davide Gomba -
January 12, 2011, at 12:48 PM by Davide Gomba -
Changed lines 22-23 from:

Connect one terminal of your speaker to digital pin 8 through a 100 ohm resistor, and its other terminal to ground. Power your photoresistor with 5V, and connect it to analog 0 with the addition of a 4.7K resistor to ground.

to:

Connect one terminal of your speaker to digital pin 9 through a 100 ohm resistor, and its other terminal to ground. Power your photoresistor with 5V, and connect it to analog 0 with the addition of a 4.7K resistor to ground.

September 24, 2010, at 06:05 AM by Tom Igoe -
Changed lines 50-51 from:
to:
September 23, 2010, at 10:31 PM by Christian Cerrito -
Changed lines 3-4 from:

Pitch follower using the tone() function

to:

Pitch follower using the tone() function

September 17, 2010, at 05:44 PM by Tom Igoe -
Changed line 52 from:
  • Tone? - play a melody with a piezo speaker
to:
  • Tone - play a melody with a piezo speaker
September 16, 2010, at 10:07 PM by Tom Igoe -
Changed line 41 from:
to:
August 25, 2010, at 05:14 AM by Christian Cerrito -
Changed lines 7-8 from:

Hardware

to:

Hardware Required

August 25, 2010, at 05:13 AM by Christian Cerrito -
Added lines 7-15:

Hardware

  • 8-ohm speaker
  • 1 photocell
  • 4.7K ohm resistor
  • 100 ohm resistor
  • breadboard
  • hook up wire
Changed lines 22-23 from:
to:

Connect one terminal of your speaker to digital pin 8 through a 100 ohm resistor, and its other terminal to ground. Power your photoresistor with 5V, and connect it to analog 0 with the addition of a 4.7K resistor to ground.

Changed lines 43-54 from:
to:
August 24, 2010, at 08:10 AM by Christian Cerrito -
Changed line 31 from:
to:
January 22, 2010, at 12:05 AM by Tom Igoe -
Changed lines 31-46 from:
 /*
   Pitch follower
  
  Plays a pitch that changes based on a changing analog input
  
  circuit:
  * 8-ohm speaker on digital pin 8
  * photoresistor on analog 0 to 5V
  * 4.7K resistor on analog 0 to ground
  
  created 21 Jan 2010
  by Tom Igoe 
  
  http://arduino.cc/en/Tutorial/Tone2
  
  */
to:
Deleted lines 32-53:
 void setup() {
   // initialize serial communications (for debugging only):
   Serial.begin(9600);
 }

 void loop() {
   // read the sensor:
   int sensorReading = analogRead(0);
   // print the sensor reading so you know its range
   Serial.println(sensorReading);
   // map the pitch to the range of the analog input.
   // change the minimum and maximum input numbers below
   // depending on the range your sensor's giving:
   int thisPitch = map(sensorReading, 400, 1000, 100, 1000);

   // play the pitch:
   tone(8, thisPitch, 10);

 }

January 21, 2010, at 08:06 PM by Tom Igoe -
Added lines 1-70:

Share